Results 1 to 4 of 4
  1. #1
    gnng is offline Member
    Join Date
    Mar 2011
    Location
    San Diego, CA
    Posts
    34
    Rep Power
    0

    Default Cannot find symbol class, but why not?

    Newbie to Java - I created a new class called Temperature and now am trying to write a class called TempDemo to test everything - but can't get past "linking" the two programs. I think I followed the format of my other programs by:

    1) Naming the first program
    Java Code:
    public class Temperature
    2) Using the following to tell the second program to go to this class
    Java Code:
    Temperature t = new Temperature();
    When I do this it comes back with an error "cannot find symbol class Temperature". Can't figure this out! Here is the complete code. Thanks in advance for any help you can provide. Gary

    FIRST PROGRAM
    Java Code:
    public class Temperature
    {
    	private double tempValue;
    	private char scale;
    
    
    	//constructors
    
    public Temperature(double tempValue)
    {
    	this.tempValue = tempValue;
    	scale = 'C';
    }
    
    public Temperature(char scale)
    {
    	 tempValue = 0;
    	 this.scale = scale;//should this be C?
    }
    
    public Temperature(double tempValue, char scale)
    {
    	 this.tempValue = tempValue;
    	 this.scale = scale;
    }
    
    public Temperature()
    {
    	 tempValue = 0;
    	 scale = 'C';
    }
    
    //mutators or setters
     public void setTempValue(double tempValye)
    	 {
    	 	this.tempValue = tempValue;
    	 }
    
    public void setScale(char scale)
    	 {
    	 	this.scale = scale;
    	 }
    
    public void setBoth(double tempValue, char scale)
    {
    	this.tempValue = tempValue;
    	this.scale = scale;
    }
    
    //getters
    
    public double getTempValue() //not sure I need this but put it in so boolean works
    {
    	double tempValue = 0;
    	return tempValue;
    }
    
    public double getTemperatureF()
    {
    
    	 double degreesF = (9 * (tempValue / 5)) + 32;
    	 return degreesF;
    }
    public double getTemperatureC()
    {
    
    	 double degreesC = 5 *(tempValue - 32) /9;
    	 return degreesC;
    }
    
    //boolean needed to 1) test whether two temps are equal, and 2) test if one temp is less han the other
    
    public boolean equals(Temperature otherTemperature)
    {
    	return(this.getTempValue() == otherTemperature.getTempValue());
    
    }
    public boolean isLessThan(Temperature otherTemperature)
    {
    	return(getTemperatureF() < getTemperatureC());
    
    }
    
    public boolean isGreaterThan(Temperature otherTemperature)
    {
    	return(getTemperatureF() > getTemperatureC());
    }
    
    //toString
    
    public String toString()
    {
       return tempValue + " " + scale;
    }
    }
    SECOND PROGRAM (HAVE NOT GOTTEN VERY FAR, I KNOW)

    Java Code:
    import java.util.*;
    
    
    public class TempDemo
    {
    
    public static void main(String[] args)
    {
    	//use all of the constructors
    	Temperature t = new Temperature();
    
    }
    
    }

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Have you compiled the first program before using it in second class.

    also make sure, both programs are in same directory.

  3. #3
    gnng is offline Member
    Join Date
    Mar 2011
    Location
    San Diego, CA
    Posts
    34
    Rep Power
    0

    Default

    Don't I feel like an idiot! It wasn't working because I took this project to school on a flash drive and it was saving the first program to that, and since I started the second program at home it was saving it on the hard drive. Like I said, total idiot!

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Like you said, you are new, you will run into these types of errors often, just get used to the problems and learn from your mistakes. Please mark your thread solved with the thread tools at the top.

Similar Threads

  1. Extended Class - Cannot Find Symbol
    By javak in forum New To Java
    Replies: 15
    Last Post: 02-27-2011, 04:43 PM
  2. can't find symbol
    By globo in forum New To Java
    Replies: 21
    Last Post: 01-17-2011, 04:06 AM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 08:30 AM
  5. cannot find symbol class error
    By po0oker in forum New To Java
    Replies: 5
    Last Post: 10-31-2007, 02:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •