Temperature conversion

I am converting Celsius to Farenheit

Page 1 of 1

3 Replies - 5200 Views - Last Post: 29 April 2010 - 07:54 PM Rate Topic: -----

#1 Deon1342  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-April 10

Temperature conversion

Posted 29 April 2010 - 12:20 PM

In this program Im suppose to use methods to write a temperature conversion program. This program will loop thru several tasks that will ask the user to type in a temperature and type (C/F), and then call the appropriate method to convert it to either Celsius or Fahrenheit. In summary this program will use all three basic control structures of:
• sequence (methods: main, celsiusTOFahrenheit, fahrenheitTOcelsius)
• selection (IF/Else to determine current temperature type)
• iteration (loop until user wants to exit program)


import java.util.Scanner;
import java.io.*;  //this method is necessary for input output (hence the io)
//This is a simple class that will make conversions and play with methods.
public class Conversions {

    //this method asks for a temperature in celsius and returns it as Fahr
    public double convertToFahrenheit(double celsius)
    {
        double fahrenheit = celsius * 9/5 + 32;
        return fahrenheit;
    }

    public void testConversions()
    {
        Scanner scan=new Scanner(System.in);
        System.out.println("Type in a temperature in Celsius and I will convert it to Fahr");
        double celsius = scan.nextDouble();
        double fahr = convertToFahrenheit(celsius);
        System.out.println("The temperature in Fahrenheit is " + fahr);

}
String input = JOptionPane.showInputDialog(null, "Enter which temperature you wish to convert using C or F:");
	String temp = String.parseString(input);

		 }

Attached File(s)


This post has been edited by Martyn.Rae: 29 April 2010 - 12:27 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Temperature conversion

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Temperature conversion

Posted 29 April 2010 - 12:30 PM

But whats the problem?
Was This Post Helpful? 0
  • +
  • -

#3 Deon1342  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-April 10

Re: Temperature conversion

Posted 29 April 2010 - 12:41 PM

View PostAphex19, on 29 April 2010 - 11:30 AM, said:

But whats the problem?

the program was compiling but,I'm suppose to use joption pane to Ask the user if they want to type in a temperature? (Y/N)
 Ask the user for the temperature
 Ask the user to type in C (Celsius) or F (Fahrenheit)
 Check temperature TYPE and call the appropriate method
 display the result
 Ask the user if they want to continue?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

Re: Temperature conversion

Posted 29 April 2010 - 07:54 PM

So what's stopping you from using JOptionPane instead of Scanner? We will be happy to help you debug code you wrote, but we won't modify it to incorporate JOptionPane.

If you are unfamiliar with JOptionPane's methods, you may want to check out the API.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1