Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Solve this program i need to write?

Ok i am really struggling on making this program for my programming class. I major in Chemistry but i don't get why i need to learn how to program. Can someone help solve this program for me

You have been hired by the

Puerto Rico Olympic Committee to create a program that performs

measurement conversions. You need to work with the conversions for Team marathon runner.

The program should change from kilometers to miles and vice

-

versa.

Athletes should select

the type of action they want to change. If you do not choose an appropriate alternative, the program will

indicate that it has made ​​a mistake. If you choose an appropriate alternative, the program does the

calculation (measuring change) and display the results presented in

. BONUS: Add the structure

Repeat to repeat the program as many times as the user wants.

Update:

Also this program needs to be made only in Java.

3 Answers

Relevance
  • 7 years ago
    Favorite Answer

    Try this, I hope it's what you wanted. Good Luck!

    import java.util.Scanner;

    public class MarathonConverter {

    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    String input = "";

    do {

    System.out.println("To convert miles to kilometres, enter m");

    System.out.println("To convert kilometres to miles, enter k");

    System.out.println("To quit, enter q");

    input = scan.next();

    switch(input) {

    case "m": miToKm(scan); break;

    case "k": kmToMi(scan); break;

    case "q": return;

    default: doError();

    } // end switch

    } while (true);

    } // end main()

    public static void miToKm(Scanner in) {

    System.out.print("Enter miles: ");

    double miles = in.nextDouble();

    double km = miles * 1.6;

    System.out.println(miles+" miles = "+km+" kilometres.\n");

    }

    public static void kmToMi(Scanner in) {

    System.out.print("Enter kilometres: ");

    double km = in.nextDouble();

    double miles = km / 1.6;

    System.out.println(km+" kilometres = "+miles+" miles.\n");

    }

    public static void doError() {

    System.out.println("Error in input. Please try again.\n");

    }

    } // end class

    Source(s): Experience
  • 7 years ago

    Maybe this isn't a test of programming skill, maybe it's a test of ethics?

  • ?
    Lv 7
    7 years ago

    Which programming language do you use?

Still have questions? Get your answers by asking now.