Results 1 to 12 of 12
- 11-07-2010, 06:29 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
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
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;
}
}
-
- 11-07-2010, 10:08 PM #3
- 11-08-2010, 12:58 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
To DB(aka java forum police):does it really matter if i posted it on another board..isnt that what these are for?? imma post this same reply on the other board to p!$$ u off
to the other guys who help:thanks
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
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;
}
}
- 11-08-2010, 01:12 AM #5
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
No one wants to waste time working out someone's problem when it's already been solved elsewhere in a cross-post. Ignoring this implies that the poster doesn't respect the time commitment made by the volunteers of the various forums. The best thing to do is to notify all if you've made cross-posts and where you've made them. This forum is no different from any of the others in this regard.
Saying "pi$$-off" may feel good at the time, but isn't likely to encourage others to help you further.
Suerte.
- 11-08-2010, 05:18 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
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
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);
}
}
-
Agree that the cross-posting issue is important. OP, you might want to address this, let us know if there are any more cross-posts and let us know that you will notify us and all other forums for cross-posts in the future. Thank you for your cooperation.
- 11-08-2010, 06:51 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
im getting errors in the output now
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();
}
}
- 11-08-2010, 08:32 PM #9
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Snapping at a respected member of this forum because he informed you of a forum etiquette faux pas is not a good way to get help. Why crossposting is looked down upon has been explained already.
Ever seen a dog chase its tail? Now that's an infinite loop.
- 11-08-2010, 09:44 PM #10
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
Im new to the board and didn't know about the crossposting policy and thats why I apologized
- 11-08-2010, 09:54 PM #11
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
To DB(aka java forum police):does it really matter if i posted it on another board[?]
A couple of things. First, it matters to me. I know you didn't address the question at me, but I'll answer anyway because that's how forums and dialogue in general works: you say/ask/observe something and people say/ask/observe things in response. And it matters to me mostly because crossposting frustrates that process of dialogue. Anyone participating in a discussion either doesn't know about - or has to jump through hoops to see - the rest of the dialogue. When you create a thread you offer it to the community. Those who respond, by responding make it their own. The thread is common property.
Secondly, "police"? That is simply not how it works. It's rhetoric, not fact. There are no police. What there are people engaged in dialogue (see above) who, by their participation, establish and sustain norms of conduct. No police: just people being civil.Last edited by pbrockway2; 11-08-2010 at 10:02 PM.
- 11-08-2010, 09:57 PM #12
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
Similar Threads
-
XLS to PDF conversion
By nitin2k2k in forum Advanced JavaReplies: 17Last Post: 09-20-2011, 08:41 AM -
[j2me] sprite rotation with degrees
By Rooneyz in forum CLDC and MIDPReplies: 0Last Post: 07-06-2009, 03:40 PM -
Doc to Pdf conversion
By praveen.kb in forum Advanced JavaReplies: 2Last Post: 01-16-2009, 12:27 PM -
string conversion??
By j2vdk in forum New To JavaReplies: 13Last Post: 09-19-2008, 03:35 PM -
Conversion from wav to vox
By bozovilla in forum Advanced JavaReplies: 1Last Post: 07-31-2008, 05:54 AM


LinkBack URL
About LinkBacks


Bookmarks