Write a Java program to continue creating your own userdefined
methods and introduce some do while loops. Write two valuereturning methods called farToCel() and celToFar(). These two methods will convert temperatures from Fahrenheit to Celsius and Celsius to Fahrenheit respectively. They will each take a single int parameter and return the converted value as an int.
Write an additional value returning method called displayMenu() to display a three
item menu and read input from the user which is their selection and return that as a
char. Consider using the Character class method toUpperCase() to narrow the
number of choices from six {F, f, C, c, Q, q} to three {F, C, Q}.
Note that displayMenu() has no parameters. The displayMenu() method should
only return one of three possible values. The choices are 'F' for Fahrenheit to Celsius
conversion, 'C' for Celsius to Fahrenheit conversion and 'Q' to quit.
Start by calling displayMenu() within a dowhile loop in the main() method
which will capture the return value of displayMenu() into a char variable. This value
will be used to determine what type of conversion is to be done and the loop will termine
when the user enters 'Q'.This would be a good opportunity for a dowhile
loop in the displayMenu()method as the user continues to make a bad selection. We would stay in the displayMenu() method until the user chooses a valid selection. By doing so, this method can never return bad selections to the main() method.
Once you have mastered your displayMenu() method, you can proceed to the other
two. Also, note that displayMenu() is not responsible for reading the temperatures;
the main() method will do this based on the choice made by the user.
The calculation for Fahrenheit to Celsius is:
( f - 32 ) * 5 / 9
The calculation for celsius to fahrenheit is:
c * 9 / 5 + 32
Just started and wanted to get this started for the class before I left class :) Below is just the start of my program not completed yet but always open to input from others to tell me how bad it looks and what I should change to make it look better.
For instance the printf lines will be changed later to println with /t to make the spaces.
Keep your head up dunkin donuts girl :)_________________________________________________________________________________________
import java.util.*;
public class p7
{
public static void main(String[] args)
{
displayMenu();
// farToCel();
// celToFar();
}
public static void displayMenu()
{
char letter;
int x, y;
String input;
Scanner kb = new Scanner(System.in);
System.out.println("Please select one of the following: \n");
System.out.printf(" F - to convert Fahrnheit to Celsius %n");
System.out.printf(" C - to conv2ert Celsius to Fahrnheit %n");
System.out.printf("%n Q - to Quit. %n");
System.out.printf("%nChoice:");
input = kb.nextLine();
letter = input.charAt(0);
/*while(input.toUpperCase("F, C, Q"))
{
System.out.println("The temperature " + input + "is" + (farToCel) + "Celsius.");
input = kb.nextLine();
letter = input.charAt(0);
System.out.println("The temperature " + input + "is" + (celToFar) + "Fahrenheit.");
}
}
public static void farToCel()
{
System.out.print("Please enter the Fahrenheit temperature:");
x = kb.nextInt();
}
public static void celToFar()
{
System.out.println("Please enter the Celsius temperature:");
y = kb.nextInt();
}
*/
}
}