Question
This Exercise is comprised of two separate classes. The MetricTest class has a main method and tests the static methods in the Metric class. A
This Exercise is comprised of two separate classes. The MetricTestclass has a main method and tests the static methods in the Metricclass. A .java file can have multiple classes that when compiled will create separate .class files. The MetricTest code is supplied. Please pay attention to the do - while loop and the break; statement. You should have used these in previous Java classes. You will use them for other exercises in ICT362. Your responsibility is to create two static methods: milesToKilometers() and kilometersToMiles() in the Metricclass. Make sure you include comments that describe what the methods do. Start the comments with /** to be JavaDoc compatible. The Equations to use for this Exercise is: Kilometers = miles * 1.609 Miles = Kilometers / 1.609 Example Output Thank you for using our Metric converter tool For Miles to Kilometers enter: K For Kilometers to Miles enter: M or enter 'Quit' to exit. Please enter the value you want to convert: 502.4 808.3616
What I have so far:
import java.util.*; /** Insert your header information here * */
public class MetricTest {
public static void main(String[] args) { Scanner input = new Scanner(System.in); // declare a sentinal to exit the loop String check = "Quit"; // Welcome the user to the the program System.out.println("Thank you for using our Metric converter tool"); do { // collect an indicator to determine the method to call System.out.println("For Miles to Kilometers enter: K " + "For Kilometers to Miles enter: M " + "or enter 'Quit' to exit."); String type = input.next(); // if Quit is entered exit the loop. if (type.toLowerCase().equals("quit")) { break; } // ask for the number to convert System.out.println("Please enter the value you want to convert:"); double tmp = input.nextDouble(); // based on the type requested, return the conversion if (type.toLowerCase().equals("k")) { System.out.println(Metric.milesToKilometers(tmp)); } else if (type.toLowerCase().equals("m")) { System.out.println(Metric.kilometersToMiles(tmp)); }
} while (true); // this is a contineous loop if the break isn't included. }
} // end MetricTest class
//**************************************************** //** Do not change code above this block. **** //****************************************************
class Metric {
// Enter the Metric conversion methods here // make sure you include the appropriate comments to explain the methods.
} // end class Metric
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started