Hi all. How would I modify my current program to make it perform the conversion with the main method calling other methods instead of performing the conversion in the main method itself? I have attached a .pdf file that has a list of all the methods that must be used with this. Any help is greatly appreciated! Here is my current program:
import java.util.Scanner;
public class Javaid1492HW1 {
public static void main (String [] args){
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.println();
System.out.println("This is Mohammad's program:");
int value;
value = 1;
while(value != 0)
// Display menu
{
System.out.println();
System.out.println();
System.out.println();
System.out.println(" Welcome to the Distance Conversion System");
System.out.println();
System.out.println(" Main menu ");
System.out.println(" ____________________ ");
System.out.println();
System.out.println(" 1- Convert from Feet to Inch. ");
System.out.println(" 2- Convert from Inch to Feet. ");
System.out.println(" 3- Convert from Yard to Feet. ");
System.out.println(" 4- Convert from Feet to Yard. ");
System.out.println(" 5- Convert from Yard to Mile. ");
System.out.println(" 6- Convert from Mile to Yard. ");
System.out.println(" 0- Exit ");
System.out.println();
System.out.print("Enter your choice: ");
value = keyboard.nextInt();
switch (value){
case 1:
System.out.print("Enter a distance in feet to be converted to inches: ");
value = keyboard.nextInt(); System.out.println(value + " feet to inches: " + value * 12);
break;
case 2:
System.out.print("Enter a distance in inches to be converted to feet: ");
value = keyboard.nextInt();
System.out.println(value + " inches to feet: " + (double) value/12.0);
break;
case 3:
System.out.print("Enter a distance in yards to be converted to feet: ");
value = keyboard.nextInt();
System.out.println(value + " yards to feet: " + value * 3);
break;
case 4:
System.out.print("Enter a distance in feet to be converted to yards: ");
value = keyboard.nextInt();
System.out.println(value + " feet to yards: " + (double) value/3.0);
break;
case 5:
System.out.print("Enter a distance in yards to be converted to miles: ");
value = keyboard.nextInt();
System.out.println(value + " yards to miles: " + (double) value/1760.0);
break;
case 6:
System.out.print("Enter a distance in miles to be converted to yards: ");
value = keyboard.nextInt();
System.out.println(value + " miles to yards: " + value * 1760);
break;
case 0:
break;
default:
System.out.println("Invalid selection, please try again..!");
}
}
}
}