473,396 Members | 1,998 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,396 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 23224
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.