• February 4th, 2013, 10:06 AM
XxDarkstarxX
Hi Im new to everything the forum and java. But anyways I need some help with my coding. I need my program to to have a max value of 212 and convert a value from fahrenheit to celsius and then to kelvin, also feet to inches and pounds to stones. I also need to it say if the value is out of range for ex. 213 is out of range, and that a value is not valid ex. abs is not a valid entry.

Heres my code so far.
Code :

``` import java.util.Scanner;   public class Project1 { private static final int MAX_VALUE = 212;       public static void main(String[] args) {     //Declare constants final double CS = (5.0 / 9); final double ME = 0.3048; final double KL = 0.4536;   //Declare variables Scanner input = new Scanner(System.in); String entry; int fahrenheit, feet, pounds, count = 0, guess = -1, number; double fahrenheit1, feet1, pounds1;   System.out.println(" J A "); System.out.println(" Project Title ");   //Get input System.out.println("Enter a temperature in fahrenheit (integer): "); fahrenheit1 = input.nextInt(); System.out.println("Enter a distance in feet (integer): "); feet1 = input.nextInt(); System.out.println("Enter a weight in pounds (integer): "); pounds1 = input.nextInt();   number = getRandomNumber (MAX_VALUE); System.out.println("Kelvin, Inches, Stones"); while (guess != number) { System.out.println("\nEnter a Fahrenheit temperature between 0 and " + "MAX_VALUE" + ": ");   entry = input.next (); if(validInput(entry)) { count++; guess = Integer.parseInt(entry); } else if (guess <= number) { System.out.println("The entered value is invalid"); }     //Conversions double celsius = (CS) * (fahrenheit1 - 32); double meters = (ME) * (feet1); double kilograms = (KL) * (pounds1); double Kelvin = (fahrenheit1 + 459.67)* 5/9; double inches = (feet1 * 12); double stones = (pounds1 * 0.0714285714);   //Display results System.out.println("Fahrenheit " + fahrenheit1 + "is" + celsius + " in Celsius" + Kelvin + " in Kelvin "); System.out.println("Feet " + feet1 + "is" + meters + "in Meters" + "is" + inches + "in Inches"); System.out.println("Pounds " + pounds1 + "is" + kilograms + "in Kilograms" + "is" + stones + "in Stones");         }   }   private static boolean validInput(String entry) { // TODO Auto-generated method stub boolean isValid = false; return isValid = false; }       private static int getRandomNumber(int MAX_VALUE) { // TODO Auto-generated method stub return 0; }```
• February 4th, 2013, 10:08 AM
KevinWorkman
When posting code, please use the highlight tags to preserve formatting.

What exactly is the problem? You've posted your requirements and your code, but where are you stuck? What does your code do so far? Does it compile? Does it throw an error?
• February 4th, 2013, 10:13 AM
XxDarkstarxX
My code runs and compiles I just need it to say whether or not the value entered is in range and it will convert the entry or that it is out of range or invalid. If that makes sense.
• February 4th, 2013, 10:23 AM
KevinWorkman
That makes sense, but what's your question? Where exactly are you stuck? What are you confused about?
• February 4th, 2013, 10:27 AM
XxDarkstarxX
The entered value is invalid
Fahrenheit 212.0is100.0 in Celsius373.15000000000003 in Kelvin
Feet 100.0is30.48in Metersis1200.0in Inches
Pounds 100.0is45.36in Kilogramsis7.14285714in Stones

those are my results. No matter what I put in it still comes up with those exact results. It asks for a value in each fahrenheit, foot, and pound. My question is how do i fix this? How do I code it to where I can enter any value between 0 and the max value (212) and it runs the program and doesnt say the entered value is invalid unless it actually is. Sorry Im really new to this and even confused a little on how to word the question at times.
• February 4th, 2013, 10:31 AM
KevinWorkman
• February 4th, 2013, 10:36 AM
XxDarkstarxX
How do I add the highlight tags on the forums and maybe that could help? I believe if I'm answering this right, return isValid = false.
• February 4th, 2013, 10:42 AM
KevinWorkman
There's a link in my signature that explains how to add the tags, or you can quote other posts that use them to see how to do it.

That is what is on your return line, but what exactly does that mean? First off, remember that = is not the same as ==. But perhaps more importantly, what do you want to be returning from that function?
• February 4th, 2013, 10:49 AM
XxDarkstarxX
Enter a Fahrenheit temperature (integer) [0-212] : 212
Enter a distance in feet (integer) [0-100] : 100
Enter a weight in pounds (integer) [0-100] : 100
Fahrenheit 212.0is100.0 in Celsius373.15000000000003 in Kelvin
Feet 100.0is30.48in Metersis1200.0in Inches
Pounds 100.0is45.36in Kilogramsis7.14285714in Stones

Enter a fahrenheit temp (integer) [0-212] : 213
The entered temp value is out of range [0-212]

I need my program to do that.
I fixed the quote up there too.
Sorry if this is confusing you, im lost on how to fix it.
• February 4th, 2013, 11:03 AM
KevinWorkman
You're going to have to fill in the validInput() method. Right now what it's doing doesn't make a whole lot of sense. You might even need to add parameters to it or create more functions, if you want to check the validity of several values.

I recommend you take a step back and only worry about one conversion for now. Don't try to do everything at once. How do you convert Fahrenheit to celsius or kelvin? What are the valid values?

Recommended reading: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
• February 4th, 2013, 11:28 AM
XxDarkstarxX