# help w/ conversion of degrees(CtoF, FtoC)

• November 7th, 2010, 12:18 PM
robertsbd
help w/ conversion of degrees(CtoF, FtoC)
here is what we're supposed to do
This assignment is a Celsius to Fahrenheit and Fahrenheit to Celsius temperature conversion program.

Write a class that contains the following two methods ( class will have a total of 3 methods ):
public static double celtofahr ( double celsius)
and public static double fahrtocel ( double fahrenheit )

main should prompt the user for a celsius, call / use the celtofahr method to do the conversion, next display the result to the user. Next, prompt the user for a Fahrenheit, call / use the fahrtocel method to do the conversion, next display the result to the user.

Note : the formula for conversion is
fahrenheit = ( ( 9.0 / 5.0 ) * celsius ) + 32

WHERE DO I PUT THE STRING TO PROMPT THE USER TO ENTER EACH DEGREE?

here is my code

Code java:

```public class Assign8_Roberts{   private double fahrenheit; private double celsius; private String displayString;   public Assign8_Roberts (double Fahrenheit, double Celsius) { this.fahrenheit = Fahrenheit; this.celsius = Celsius; }   public double GetFahrenheitTemp() { return this.fahrenheit; }   public double FahrtoCel(double fahrenheit) { double result = (fahrenheit - 32)/1.8; return result; }   public double GetCelsiusTemp() { return this.celsius; }   public void FahrenheitTemp(double fahrenheitVal) { this.fahrenheit = fahrenheitVal; }   public double CeltoFahr(double celsius) { double result = (1.8 * celsius) + 32; return result; }   public void CelsiusTemp(double celsiusVal) { this.celsius = celsiusVal; }   }```
• November 7th, 2010, 12:35 PM
retsameht
Re: help w/ conversion of degrees(CtoF, FtoC)
you need a main class to execute and get user input

void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a value: ");

float f = scan.nextFloat();

//use f as input to your methods
}

Hope it helps
• November 7th, 2010, 12:43 PM
Darryl.Burke
Re: help w/ conversion of degrees(CtoF, FtoC)
Quote:

WHERE DO I PUT THE STRING TO PROMPT THE USER TO ENTER EACH DEGREE?
Don't shout.

The assignment tells you.
Quote:

main should prompt the user for a celsius, ... Next, prompt the user for a Fahrenheit
db
• November 7th, 2010, 04:10 PM
Darryl.Burke
Re: help w/ conversion of degrees(CtoF, FtoC)
• November 7th, 2010, 04:55 PM
javapenguin
Re: help w/ conversion of degrees(CtoF, FtoC)
Quote:

Originally Posted by Darryl.Burke

PLEASE STOP THIS. SOMETIMES PEOPLE DO THIS JUST BECAUSE THEY HAVE DEADLINES AND DAYS GO BY WITH NO RESPONSE. I'VE BEEN THERE BEFORE.
• November 7th, 2010, 07:02 PM
robertsbd
Re: help w/ conversion of degrees(CtoF, FtoC)
here's my updated program..when i run it, it runs previous assignment that i've done instead of this one so something isnt right

Code java:

```import java.util.Scanner ;   public class Assign8_Roberts{     private double fahrenheit; private double celsius; private String displayString;   public Assign8_Roberts (double Fahrenheit, double Celsius) { this.fahrenheit = Fahrenheit; this.celsius = Celsius; }   public double GetFahrenheitTemp() { return this.fahrenheit; }   public double FahrtoCel(double fahrenheit) { double result = (fahrenheit - 32)/1.8; return result; }   public double GetCelsiusTemp() { return this.celsius; }   public void CelsiusTemp(double celsiusVal) { this.celsius = celsiusVal; { Scanner scan = new Scanner(System.in); System.out.println("Enter a value: ");   float c = scan.nextFloat();   //use c as input to your methods } } public void FahrenheitTemp(double fahrenheitVal) { this.fahrenheit = fahrenheitVal;   { Scanner scan = new Scanner(System.in); System.out.println("Enter a value: ");   float f = scan.nextFloat();   //use f as input to your methods }   }   public double CeltoFahr(double celsius) { double result = (1.8 * celsius) + 32; return result; }       }```
• November 7th, 2010, 09:20 PM
copeg
Re: help w/ conversion of degrees(CtoF, FtoC)
Quote:

Originally Posted by robertsbd
To DB(aka java forum police):does it really matter if i posted it on another board..isnt that what these are for??

Yes it does matter, especially when doing so violates the policy's of the very forum's those posts reside. The policies of certain forums were created for a reason.

While 'cross posting' is not against the policy of these forums, we recommend posting links to the other forums where the question has been asked so responders, who do this without pay and in their spare time, do not spend their time answering a question which has already been answered elsewhere.

Quote:

Originally Posted by robertsbd
here's my updated program..when i run it, it runs previous assignment that i've done instead of this one so something isnt right

Please describe what you mean by 'it runs the previous assignment...instead of this'. What input did you provide, and what output did you receive? This information is important information to help you
• November 7th, 2010, 10:17 PM
robertsbd
Re: help w/ conversion of degrees(CtoF, FtoC)
ok sorry about my previous rant..i apologize
but when i run the program, the output is the same as the output of another assignment on my workspace
• November 8th, 2010, 08:36 AM
copeg
Re: help w/ conversion of degrees(CtoF, FtoC)
Are you using Eclipse? Sounds more like an IDE issue that happens when you have more than one main function. In eclipse (if you are using it) go to to Run->Run Configuration and select the appropriate main to run.
• November 8th, 2010, 09:42 AM
robertsbd
Re: help w/ conversion of degrees(CtoF, FtoC)
yeah im using eclipse, ill give it a try when i get home..i just upgraded from vista to 7 so idk if that has anything to do w/ it
• November 8th, 2010, 11:19 AM
robertsbd
Re: help w/ conversion of degrees(CtoF, FtoC)
ok i've changed my program around and while im getting the correct results, im not sure if i have it designed the way the assignment says

Code java:

```public class Assign8_Roberts{   public static void main(String[] args) {   double fahrenheit; double celsius;   Scanner input = new Scanner(System.in);   System.out.println("Enter the Degrees in Fahrenheit"); fahrenheit = input.nextDouble(); celsius = (5.0/9.0)*(fahrenheit - 32); System.out.println("The number of degrees of Fahrenheit: " + fahrenheit); System.out.println("Converted to Celsius is: " + celsius);//end convert to celsius   System.out.println("Enter the Degrees in Celsius"); celsius = input.nextDouble(); fahrenheit = (9.0/5.0)* celsius + 32; System.out.println("The number of degrees of Celsius: " + celsius); System.out.println("Converted to Fahrenheit is: " + fahrenheit); }   }```
• November 8th, 2010, 11:37 AM
copeg
Re: help w/ conversion of degrees(CtoF, FtoC)
Quote:

Originally Posted by robertsbd
ok i've changed my program around and while im getting the correct results, im not sure if i have it designed the way the assignment says

The assignment mentions you need 3 methods, one of which is main. So I'd suggest pulling out those C->F and F->C calculations into their own methods (named as per the assignment guidelines).
• November 8th, 2010, 12:38 PM
robertsbd
Re: help w/ conversion of degrees(CtoF, FtoC)
i think im more in the ballpark in what the assignment says..my errors are coming in the output

Code java:

```import java.util.Scanner;   public class Assign8_Roberts{   //Converts between CandF private double celsius; private double fahrenheit;   //converts from CtoF public void CeltoFahr(double temp){ fahrenheit = (9.0/5.0*temp) + 32; celsius = temp; }   //converts from FtoC public void FahrtoCel(double temp){ celsius = (5.0/9.0) * (temp-32); fahrenheit = temp; }   //displays temp in C public void outputCelsius(){ System.out.println("The temperature is " + celsius + "C"); }   //displays temp in F public void outputFahrenheit(){ System.out.println("The temperature is " + fahrenheit + "F"); }   //output public static void main(String[] args) { Scanner temp = new Scanner(system.in); temp t = new temp(); t.setCelsius(100); t.outputFahrenheit(); t.outputCelsius(); }   }```