-
debugging
hi, i am a new programmer to java. with my program, i seem to have one error that i have no idea how to fix(assuming everything else works the way i
want it too.) What happens is that i was making a program to convert celsius to fahrenheit and vice versa based on the input of the user. the error
message i get is that "it cannot find a symbol" during the compiling process. The compiler keeps on singling out the temperature object, but i don't know
why.
any ideas
Code:
public class temperature
{
public int degree, cel, fahren;
public String units;
public void temper()
{
degree = 0;
units = "NONE";
}
public String getUnits()
{
if(units.equalsIgnoreCase("C"))
units = "Celsius";
else if(units.equalsIgnoreCase("F"))
units = "Fahrenheit";
return units;
}
public int getDegree()
{
return degree;
}
public int getCel()
{
cel = (degree - 32) * (5/9);
return cel;
}
public int getFahren()
{
fahren = (degree *(9/5) + 32);
return fahren;
}
public String toString()
{
String temp = "You have entered " + degree + " " + units;
return temp;
}
}
Code:
import java.util.Scanner;
public class testTemp
{
public static void main(String[] args)
{
temperature t1 = new temper();
Scanner keyboard = new Scanner(System.in);
boolean exit = false;
while (!exit) {
System.out.println("Enter 'Y' for temperature conversion, 'N' to exit.");
String response = keyboard.nextLine();
if (response.equalsIgnoreCase("y")) {
System.out.println("enter the temperature.");
t1.degree = keyboard.nextInt();
System.out.println("Enter 'C' if the degree is in Celsius, Enter 'F' if the degree is in Fahrenheit.");
t1.units = keyboard.nextLine();
if(response.equalsIgnoreCase("C")) {
System.out.println(t1.toString());
System.out.println("In Fahrenheits, the degree is " + t1.getFahren());
}
else if(response.equalsIgnoreCase("F")) {
System.out.println(t1.toString());
System.out.println("In Celsius, the degree is " + t1.getCel());
}
else if(response.equalsIgnoreCase("n"))
exit = true;
}
}
}
}
-
Re: debugging
You need to post the error you are getting, and highlight the line(s) it is occurring on.
People won't copy and paste this code into their IDEs just to see what the problem is.
-
Re: debugging
ok, so the debugger is reading an error on the temperature class. It is highlighting on the line with "temperature t1 = new temper();" saying that it cannot find symbol. I don't understand why..
-
Re: debugging
Because there is no temper class its temperature class
-
Re: debugging
rename temper() and make a constructor termperature like
public temperature()
{
degree = 0;
units = "NONE";
}
and inside testTemp change t1 to
temperature t1 = new temperature();