# Temperature conversion

Page 1 of 1

## 3 Replies - 7529 Views - Last Post: 29 April 2010 - 07:54 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=171075&amp;s=97a2d428be79339252a41096dceccb45&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Deon1342

Reputation: 0
• 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

• Born again Pastafarian.

Reputation: 618
• Posts: 1,873
• Joined: 02-August 09

## Re: Temperature conversion

Posted 29 April 2010 - 12:30 PM

But whats the problem?

### #3 Deon1342

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

## Re: Temperature conversion

Posted 29 April 2010 - 12:41 PM

Aphex19, 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?

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12298
• Posts: 45,399
• 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.