Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name

ID: 3838838 • Letter: C

Question

Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: Convert to Kilometers Convert to Inches Convert to Feet Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user's selection. Write the following methods: getInput: This method prompts user to enter a distance in meters. Returns input to the caller. TestData: Cannot accept negative numbers. Menu: This method does not accept any arguments, but returns a selection to the caller. Convert2Kilometers: This method receives a parameter, converts to kilometers (meters * 0.001) and returns the value to the caller. Convert2Inches: This method receives a parameter, converts to inches (meters * 39.37) and returns the value to the caller. Convert2Feet: This method receives a parameter, converts to feet (meters * 3.281) and returns the value to the caller. DisplayData: This method receives the input and the converted value. See p. 314 for other methods. Test Data: see example given in the book. Use the same format. Takehome Exam Question Paper Algorithm A complete Java Program with comments/documentation output.

Explanation / Answer

code:

//*******************************************************************

// Dear CompileJava users,

//

// CompileJava has been operating since 2013 completely free. If you

// find this site useful, or would otherwise like to contribute, then

// please consider a donation (link in 'More Info' tab) to support

// development of the new CompileJava website (stay tuned!).

//

// Most sincerely, Z.

//*******************************************************************

import java.lang.Math; // headers MUST be above the first class

import java.util.Scanner;

// one class needs to have a main() method

public class HelloWorld

{

public static double getInput()

{

System.out.println("Enter the distance in meters");

Scanner sc=new Scanner(System.in);

double dist = sc.nextDouble();

return dist;

}

public static boolean test(double no)

{

if(no<0)

return false;

else

return true;

}

public static double convert2km(double no)

{

return no*0.001;

}

public static double convert2inch(double no)

{

return no*39.37;

}

public static double convert2feet(double no)

{

return no*3.281;

}

public static void displayvalue(double in,double output)

{

System.out.println("value in meters:"+in);

System.out.println("desired output:"+output);

  

}

public static double menu()

{

System.out.println("Enter your choice:");

System.out.println("1)convert to kilometer:");

System.out.println("2)convert to inch:");

System.out.println("3)convert to feet:");

System.out.println("4)quit the program");

Scanner sc=new Scanner(System.in);

double choice = sc.nextDouble();

return choice;

}

// arguments are passed using the text field below this editor

public static void main(String[] args)

{

double dist =getInput();

if(test(dist)==false)

System.out.println("invalid value");

double ch = menu();

if(ch==1)

{

displayvalue(dist,convert2km(dist));

}

else if (ch==2)

displayvalue(dist,convert2inch(dist));

else if(ch==3)

displayvalue(dist,convert2feet(dist));

else

return ;

}

}

//*******************************************************************

// Dear CompileJava users,

//

// CompileJava has been operating since 2013 completely free. If you

// find this site useful, or would otherwise like to contribute, then

// please consider a donation (link in 'More Info' tab) to support

// development of the new CompileJava website (stay tuned!).

//

// Most sincerely, Z.

//*******************************************************************

import java.lang.Math; // headers MUST be above the first class

import java.util.Scanner;

// one class needs to have a main() method

public class HelloWorld

{

public static double getInput()

{

System.out.println("Enter the distance in meters");

Scanner sc=new Scanner(System.in);

double dist = sc.nextDouble();

return dist;

}

public static boolean test(double no)

{

if(no<0)

return false;

else

return true;

}

public static double convert2km(double no)

{

return no*0.001;

}

public static double convert2inch(double no)

{

return no*39.37;

}

public static double convert2feet(double no)

{

return no*3.281;

}

public static void displayvalue(double in,double output)

{

System.out.println("value in meters:"+in);

System.out.println("desired output:"+output);

  

}

public static double menu()

{

System.out.println("Enter your choice:");

System.out.println("1)convert to kilometer:");

System.out.println("2)convert to inch:");

System.out.println("3)convert to feet:");

System.out.println("4)quit the program");

Scanner sc=new Scanner(System.in);

double choice = sc.nextDouble();

return choice;

}

// arguments are passed using the text field below this editor

public static void main(String[] args)

{

double dist =getInput();

if(test(dist)==false)

System.out.println("invalid value");

double ch = menu();

if(ch==1)

{

displayvalue(dist,convert2km(dist));

}

else if (ch==2)

displayvalue(dist,convert2inch(dist));

else if(ch==3)

displayvalue(dist,convert2feet(dist));

else

return ;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote