473,287 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Convert temperatures in fahrenheit to celsius

Ok i need to create a java program that repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered.

My program is:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. // Converter.java
  3. public class Converter
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner sc = new Scanner(System.in);
  8.         System.out.print("Enter temp: ");
  9.         int temp = sc.nextInt();
  10.         System.out.println(convertToC(temp));
  11.     }
  12.          public static int convertToC(int temp)
  13.     {
  14.         return ((temp - 32 ) * 5/9);
  15.     }
  16. }                
  17.  
I would really appreaciate it. Thank you. <email removed>
Nov 14 '08 #1
11 23221
JosAH
11,448 Expert 8TB
What is your question?

kind regards,

Jos

ps. use those [ code ] tags for readability reasons next time when you post code.
Nov 14 '08 #2
What is your question?

kind regards,

Jos

ps. use those [ code ] tags for readability reasons next time when you post code.

umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.
Nov 14 '08 #3
JosAH
11,448 Expert 8TB
umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.
And what does your program do? Note that integer division does not do what
people expect it to do.

kind regards,

Jos
Nov 14 '08 #4
ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.
Nov 14 '08 #5
JosAH
11,448 Expert 8TB
ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.
Craft a liitle loop then and a small method that asks the user to enter a number
in Fahrenheit degrees:

Expand|Select|Wrap|Line Numbers
  1. for (int f= getFahrenheit(); f <= 212; f= getFahrenheit())
  2.    System.out.println(f+"F = "+convertToC(f)+"C");
  3.  
The convertToC() method converts Fahrenheit (its parameter) to Celcius.
You already have that method.

kind regards,

Jos
Nov 14 '08 #6
yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



"Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

Sorry about the confusion
Nov 14 '08 #7
JosAH
11,448 Expert 8TB
yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



"Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

Sorry about the confusion
But I just told you how to do that ...

kind regards,

Jos
Nov 14 '08 #8
oh, now I see it sorry about that. Not to sound stupid but, where would I insert that part you gave me at.
Nov 14 '08 #9
wow thanks alot for the help. I really needed it. Thanks again
Nov 14 '08 #10
But I just told you how to do that ...

kind regards,

Jos
Once again I am sorry, but I am a begginner in Java programming. I tried to do what you told me but I have one error. Line 17 has the error message that reads [PHP]1 error

----jGRASP wedge2: exit code for process is 1.[/PHP]

[PHP]import java.util.*;
// Converter.java
public class Converter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter temp: ");
int temp = sc.nextInt();
System.out.println(convertToC(temp));
}
public static int convertToC(int temp)
{
return ((temp - 32 ) * 5/9);
}
{
for (int f= getFahrenheit()); f <= 212;
f= getFahrenheit())
System.out.println(f+"F = "+convertToC(f)+"C");
for (int f= getFahrenheit();
f <= 212; f= getFahrenheit())
System.out.println(f+"F = "+convertToC(f)+"C");
}
}[/PHP]
Nov 15 '08 #11
JosAH
11,448 Expert 8TB
Basically your program structure looks like this now:

Expand|Select|Wrap|Line Numbers
  1. public class Converter {
  2.     public static void main(String[] args) { ... }
  3.      public static int convertToC(int temp) { ... }
  4.      { /* some garbage statements ... */ }
  5. }
  6.  
That doesn't make sense does it? I had expected that loop I wrote for you
somewhere in the main method; not dangling at the end of the class, not in
any method at all. On top of that that bunch of statements contain quite a
lot of garbage as well.

kind regards,

Jos
Nov 15 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
5
by: sjsn | last post by:
Basic C++, just started this course in school... So I'm very limited. What I'm at doing is, below I have a variable named inputTemp, which is the product of a char, F = Fahrenheit, C = Celsius...
2
by: lifeshortlivitup | last post by:
I am a java beginner and am trying to tackle a temperature conversion problem but I don't exactly know how to begin. The problem asks that I write a program that allows the user to conver either...
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
4
by: kipj77 | last post by:
Hi i was wondering why the hell this program isn't working for me, I am in a 100 level computer science class and need help. This program is supposed to take in data of degrees Fahrenheit and spit...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.