Hello,
I'm a student working on my first hands-on assignment. One of the questions is this:
Q4: Write a program that converts a user input temperature from degree Celsius to Fahrenheit or Fahrenheit to Celsius using:
C = 5 (F -32)/9 or F = 9C/5 + 32
The user must input temperature with a ācā or āfā (case insensitive) after the number and the program should output the corresponding value. If any other letter, is used, print an error. [10]
This is what I have so far, but it's returning 7 errors - one of them being "enum types must not be local", and the rest are about the illegal start of an expression, else without if, and that a semicolon was expected. I feel like I'm pretty close (except for the 7 errors!) Any pointers would be much appreciated. Thank you!
import java.util.*;
import java.util.Scanner;
public class TemperatureConverter{
public static void main(String[] args){
int temperature;
enum TempType {C, c, F, F}
System.out.println ("Enter a temperature in whole degrees only.");
Scanner keyboard = new Scanner(System.in);
temperature = keyboard.nextInt( );
System.out.println ("Now enter an 'F' if the temperature is Fahrenheit or a 'C' if it is Celsius.");
TempType = keyboard.nextChar( );
if (TempType == 'c') | (TempType == 'C')
System.out.println (temperature + " degrees Celsius equals " + (((temperature * 9)/5) + 32) + " degrees Fahrenheit.");
else if (TempType == 'f') | (TempType == 'F')
System.out.println (temperature + " degrees Fahrenheit equals " + (((temperature - 32) * 5) / 9) + " degrees Celsius.");
else
System.out.println ("I'm sorry. You did not enter a 'C' or an 'F.'");
}
}