nikese
asked on
Celsius conversion program
I am very new to Java and am having a really hard time writing programs. I am trying to write a program that converts celsius to fahrenheit. The program should ask a user to input a temperature and either f for fahrenheit or c for celsius. It should not be case sensitive. I am ALL messed up. Here is what I have, but i cannot for the life of me figure out how the numeric portion and the character portion of the users input will be calculated seperately. Any hints would be greatly appreciated.
public class Degrees
{
public static void main(String[] args)
{
/**List of tasks
Ask for input
Make sure type of degree is non-case sensitive
Perform converstion and output
Ask user to end program or perform another conversion
*/
//double number;
System.out.println("This program will convert degrees Celcius to Fahrenheit or vice versa"); //outputs sentence
do
{
System.out.println("\nPlea se enter a temperature and either a C for Celcius or F for Fahrenheit");
char input = SavitchIn.readLineNonwhite Char();
System.out.println();
//switch(input);
//int degree = input.indexOf('f') && ('c');
//number = (input.substring(0, degree));
//degree = line.substring(char);
double degreesC;
double degreesF;
degreesC = ((degreesF - 32) * 5)/9; //Fahrenheit to Celsius formula
degreesF = ((9 * degreesC)/5) + 32; //Celsius to Fahrenheit formula
System.out.println("Enter Q to quit or press any other key to perform another conversion");
char quitAnswer = SavitchInReadLineChar(); //reads user input
if(quitAnswer == 'q') //if user input is lowercase q
System.exit(0); //then exit the system
else if(quitAnswer == 'Q') //if user input is uppercase Q
System.exit(0); //then exit the system
}while (quitAnswer != 'q' && quitAnswer != 'Q'); //if it is neither, then start over
}
}
public class Degrees
{
public static void main(String[] args)
{
/**List of tasks
Ask for input
Make sure type of degree is non-case sensitive
Perform converstion and output
Ask user to end program or perform another conversion
*/
//double number;
System.out.println("This program will convert degrees Celcius to Fahrenheit or vice versa"); //outputs sentence
do
{
System.out.println("\nPlea
char input = SavitchIn.readLineNonwhite
System.out.println();
//switch(input);
//int degree = input.indexOf('f') && ('c');
//number = (input.substring(0, degree));
//degree = line.substring(char);
double degreesC;
double degreesF;
degreesC = ((degreesF - 32) * 5)/9; //Fahrenheit to Celsius formula
degreesF = ((9 * degreesC)/5) + 32; //Celsius to Fahrenheit formula
System.out.println("Enter Q to quit or press any other key to perform another conversion");
char quitAnswer = SavitchInReadLineChar(); //reads user input
if(quitAnswer == 'q') //if user input is lowercase q
System.exit(0); //then exit the system
else if(quitAnswer == 'Q') //if user input is uppercase Q
System.exit(0); //then exit the system
}while (quitAnswer != 'q' && quitAnswer != 'Q'); //if it is neither, then start over
}
}
ASKER
How to the calculations work from there? I think it should be something like if input includes f then perform degreesC calculation else if it includes c then perform degreesF calculation. That's what I am thinking but i don't know how to write it in java. Also, it needs to be non-case sensitive but when I type out input = input.equalsIgnoreCase(); I get compiler errors.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER
I wanted to thank you all tremendously!!!! I have worked on this program for four days now and it almost makes me laugh how easy it seemed to you. Thank you very much for your super fast replies. I think what I am going to do is run all of them to see the outcomes and take a little advice from each. Thanks again!
Don't know that Savitch class, but guess that should be
String input = SavitchIn.readLineNonwhite