# Temperature Conversion

Page 1 of 1

## 9 Replies - 1271 Views - Last Post: 06 April 2010 - 09:23 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=166564&amp;s=1df1504954ed8c4a772b24e7841d7690&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mothan

Reputation: -1
• Posts: 22
• Joined: 28-February 10

# Temperature Conversion

Posted 06 April 2010 - 07:40 PM

Can someone please help me! I'm doing a loop and I should have 3 options: 1. Fahrenheit to Celsius, 2. Celsius to Fahrenheit, and 3. exit. This is my code

```public class Project2 {
private static int num;

public static void main(String[] args) {
//Create a Scanner

//two variables, undefined.

double usersEnteredTemperature; //the temperature you wish to get from
//the user.
double convertedTemperature;    //the converted temperature based on
//the user choices and entered temperature.

//Enter Input
//Give user options and choices.

double celsius;
double fahrenheit;

do {

System.out.println("1. For Farenheit to Celsius");
System.out.println("2. For Celsius to Farenheit");
System.out.println("3.Exit");

if (num == 1) {
System.out.println("Enter Temperature in Farenheit : ");

//do some conversion based on userinput store output into
//convertedTemperature Celsius
convertedTemperature = (5.0 / 9) * (usersEnteredTemperature - 32);
System.out.println("Your degrees will be in celsius");
System.out.println(convertedTemperature);
} else if (num == 2) {
System.out.println("Enter Temperature in Celsius: ");

//do some conversion based on userinput store output into
//convertedTemperature Fahrenheit
convertedTemperature = (9.0 / 5) * usersEnteredTemperature + 32;
System.out.println("Your degrees will be in Farenheit");
System.out.println(convertedTemperature);
}

} while (num != 3);

System.out.println("Good Bye!");

}
}
```

Help please! This is the error I'm getting.

Quote

run:
Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
at Scanner.<init>(Scanner.java:16)
at Project2.main(Project2.java:14)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Moderator Edit: Please, in the future, .

-Locke

Is This A Good Question/Topic? 0

## Replies To: Temperature Conversion

### #2 pdkharkar

• D.I.C Regular

Reputation: 65
• Posts: 345
• Joined: 19-January 09

## Re: Temperature Conversion

Posted 06 April 2010 - 08:02 PM

you have to import java.util.* package which contains the scanner class

### #3 LiveToCode

Reputation: 11
• Posts: 37
• Joined: 17-March 10

## Re: Temperature Conversion

Posted 06 April 2010 - 08:07 PM

You forgot to import java.util.Scanner; and you should replace the variable "num" with "menuChoice" because menuChoice is more decriptive it is declared for a reason right. The variable num in this case is not necessary so you can just delete it.

Edit - Ninja'ed

This post has been edited by LiveToCode: 06 April 2010 - 08:08 PM

### #4 mothan

Reputation: -1
• Posts: 22
• Joined: 28-February 10

## Re: Temperature Conversion

Posted 06 April 2010 - 08:34 PM

I've add the import java.util.Scanner; and change the num to menuChoice, here is my code

package project2;

import java.util.Scanner;

public class Project2 {

public static void main(String[] args) {
//Create a Scanner

//two variables, undefined.

double usersEnteredTemperature; //the temperature you wish to get from
//the user.
double convertedTemperature; //the converted temperature based on
//the user choices and entered temperature.

//Enter Input
//Give user options and choices.

double celsius;
double fahrenheit;

do {

System.out.println("1. For Farenheit to Celsius");
System.out.println("2. For Celsius to Farenheit");
System.out.println("3.Exit");

System.out.println("Enter Temperature in Farenheit : ");

//do some conversion based on userinput store output into
//convertedTemperature Celsius
convertedTemperature = (5.0 / 9) * (usersEnteredTemperature - 32);
System.out.println("Your degrees will be in celsius");
System.out.println(convertedTemperature);
} else if (menuChoice == 2) {
System.out.println("Enter Temperature in Celsius: ");

//do some conversion based on userinput store output into
//convertedTemperature Fahrenheit
convertedTemperature = (9.0 / 5) * usersEnteredTemperature + 32;
System.out.println("Your degrees will be in Farenheit");
System.out.println(convertedTemperature);
}

System.out.println("Good Bye!");

}
}

The error I got is this.
run:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - class Project2 is public, should be declared in a file named Project2.java
at project2.Project2.<clinit>(Main.java:11)
Could not find the main class: project2.Project2. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Reputation: 6
• Posts: 44
• Joined: 26-December 09

## Re: Temperature Conversion

Posted 06 April 2010 - 08:38 PM

Your public class is named Project2 yet the file that contains this code is not named Project2.java. Either rename your class to match your file name, or rename the file to match the class name.

### #6 erik.price

• D.I.C Lover

Reputation: 486
• Posts: 2,690
• Joined: 18-December 08

## Re: Temperature Conversion

Posted 06 April 2010 - 08:39 PM

Quote

class Project2 is public, should be declared in a file named Project2.java

Also, since you declare the source to be in the package "project2", it should be in a folder named project2

http://java.sun.com/...agingfiles.html

### #7 mothan

Reputation: -1
• Posts: 22
• Joined: 28-February 10

## Re: Temperature Conversion

Posted 06 April 2010 - 09:05 PM

I've clean it up but it won't let me debug or run. please advice!

### #8 erik.price

• D.I.C Lover

Reputation: 486
• Posts: 2,690
• Joined: 18-December 08

## Re: Temperature Conversion

Posted 06 April 2010 - 09:10 PM

Could you post your modified code?

### #9 mothan

Reputation: -1
• Posts: 22
• Joined: 28-February 10

## Re: Temperature Conversion

Posted 06 April 2010 - 09:12 PM

Here is my code:
```package project2;

import java.util.Scanner;

public class Project2 {

public static void main(String[] args) {
//Create a Scanner

//two variables, undefined.

double usersEnteredTemperature; //the temperature you wish to get from
//the user.
double convertedTemperature;    //the converted temperature based on
//the user choices and entered temperature.

//Enter Input
//Give user options and choices.

double celsius;
double fahrenheit;

do {

System.out.println("1. For Farenheit to Celsius");
System.out.println("2. For Celsius to Farenheit");
System.out.println("3.Exit");

System.out.println("Enter Temperature in Farenheit : ");

//do some conversion based on userinput store output into
//convertedTemperature Celsius
convertedTemperature = (5.0 / 9) * (usersEnteredTemperature - 32);
System.out.println("Your degrees will be in celsius");
System.out.println(convertedTemperature);
} else if (menuChoice == 2) {
System.out.println("Enter Temperature in Celsius: ");

//do some conversion based on userinput store output into
//convertedTemperature Fahrenheit
convertedTemperature = (9.0 / 5) * usersEnteredTemperature + 32;
System.out.println("Your degrees will be in Farenheit");
System.out.println(convertedTemperature);
}

System.out.println("Good Bye!");

}
}
```

Edited by Dogstopper: USE THE CODE TAGS!

This post has been edited by Dogstopper: 07 April 2010 - 03:37 AM

### #10 erik.price

• D.I.C Lover

Reputation: 486
• Posts: 2,690
• Joined: 18-December 08

## Re: Temperature Conversion

Posted 06 April 2010 - 09:23 PM