Link to home
Start Free TrialLog in
Avatar of Sapphireblue
SapphireblueFlag for United States of America

asked on

Inherited object class not being recognized? (Old homework, new computer)

Last semester I had an intro to java class, this semester I have an "advanced" java class with another professor. An assignment I have for the current class bears some similarity to one I did last semester so I thought I'd fire up the old homework and see what I could recyle. However, the old homework won't compile now.

Maybe it's related to the fact that I had a different development environment last semester. I don't remember what version of SDK etc I was using last semester; my hard drive exploded and I had to start over again this semester. This semester's prof is also having us use J2EE, which I didn't last semester. Even so, it looks like a REALLY straightforward compilation error... doesn't recognize an inherited object class I had created, though that class itself compiles fine... the files are there and I know it worked last semester. What gives? I'll paste the code for the 3 classes that make up the app, starting with the driver class & working my way down, along with the compilation errors for each.

----------

/*
Project 5-1: Use inheritance to display a student record
*/

import javax.swing.*;
import java.text.*;

public class StudentApp
{
      public static void main(String[] args)
      {
            String identificationNumberInput, majorInput, gradePointAverageInput;
            CollegeStudent userCollegeStudent;
            String userInput = "";

            try
            {
                  while (!(userInput.equalsIgnoreCase("x")))
                  {
                        identificationNumberInput = JOptionPane.showInputDialog("Enter college student's ID:");
                        majorInput = JOptionPane.showInputDialog("Enter college student's major:");
                        gradePointAverageInput = JOptionPane.showInputDialog("Enter college student's GPA:");
                        userCollegeStudent = new CollegeStudent(Integer.parseInt(identificationNumberInput), Double.parseDouble(gradePointAverageInput), majorInput);
                        userInput = JOptionPane.showInputDialog(userCollegeStudent.toString() + "\n\nPress Enter to continue or 'x' to exit");
                  }
            }
            catch(NullPointerException e)
            {
                  System.exit(0);
            }
            System.exit(0);
      }
}

C:\j2sdk1.4.0_01\bin\StudentApp.java:14: cannot resolve symbol
symbol  : class CollegeStudent  
location: class StudentApp
            CollegeStudent userCollegeStudent;
                ^
C:\j2sdk1.4.0_01\bin\StudentApp.java:24: cannot resolve symbol
symbol  : class CollegeStudent  
location: class StudentApp
                        userCollegeStudent = new CollegeStudent(Integer.parseInt(identificationNumberInput), Double.parseDouble(gradePointAverageInput), majorInput);
                                                         ^
2 errors

Tool completed with exit code 1

----------

/*
Project 5-1: Use inheritance to display a student record
*/

public class CollegeStudent extends Student
{
      public static String major;

      public CollegeStudent()
      {
            identificationNumber = 0;
            gradePointAverage = 0.0;
            major = "";
      }

      public CollegeStudent(int userIdentificationNumber, double userGradePointAverage, String userMajor)
      {
            super(userIdentificationNumber, userGradePointAverage);
            major = userMajor;
      }

      public String toString()
      {
            String collegeStudentInfoString = "Student number: " + identificationNumber
                                                      + "\nGPA: " + gradePointAverage
                                                      + "\nMajor: " + major;
            return collegeStudentInfoString;
      }

}

C:\j2sdk1.4.0_01\bin\CollegeStudent.java:6: cannot resolve symbol
symbol  : class Student  
location: class CollegeStudent
public class CollegeStudent extends Student
                                    ^
C:\j2sdk1.4.0_01\bin\CollegeStudent.java:12: cannot resolve symbol
symbol  : variable identificationNumber  
location: class CollegeStudent
            identificationNumber = 0;
                ^
C:\j2sdk1.4.0_01\bin\CollegeStudent.java:13: cannot resolve symbol
symbol  : variable gradePointAverage  
location: class CollegeStudent
            gradePointAverage = 0.0;
                ^
C:\j2sdk1.4.0_01\bin\CollegeStudent.java:25: cannot resolve symbol
symbol  : variable identificationNumber  
location: class CollegeStudent
            String collegeStudentInfoString = "Student number: " + identificationNumber
                                                                       ^
C:\j2sdk1.4.0_01\bin\CollegeStudent.java:26: cannot resolve symbol
symbol  : variable gradePointAverage  
location: class CollegeStudent
                                                      + "\nGPA: " + gradePointAverage
                                                                                      ^
5 errors

Tool completed with exit code 1

----------

/*
Project 5-1: Use inheritance to display a student record
*/

public class Student
{
      public static int identificationNumber;
      public static double gradePointAverage;

      public Student()
      {
            identificationNumber = 0;
            gradePointAverage = 0.0;
      }

      public Student(int userIdentificationNumber, double userGradePointAverage)
      {
            identificationNumber = userIdentificationNumber;
            gradePointAverage = userGradePointAverage;
      }

      public static double getGradePointAverage()
      {
            return gradePointAverage;
      }

      public static int getIdentificationNumber()
      {
            return identificationNumber;
      }

      public static void setGradePointAverage(double userGradePointAverage)
      {
            gradePointAverage = userGradePointAverage;
      }

      public static void setIdentificationNumber(int userIdentificationNumber)
      {
            identificationNumber = userIdentificationNumber;
      }

      public String toString()
      {
            String studentInfoString = "Identification number: " + identificationNumber
                                                      + "\nGrade point average: " + gradePointAverage;
            return studentInfoString;
      }
}

[this compiles fine]
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Put all your classes in the same directory and try

javac *.java
and put them in a single package
Avatar of Sapphireblue

ASKER

They were already all in the same dir, but I went ahead and tried the wildcard compile... no luck.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CEHJ, that works, so I guess you've earned the points, but can you tell me why I still do get the errors if I try to compile each of them individually working from the bottom up? It was never a problem before, and I'd really like to be able to do so, as my Java editor of choice (TextPad) only compiles on a one-at-a-time basis. Makes life so much easier just to hit Ctrl+1, Ctrl+2 in TextPad than bounce back and forth to a command prompt. Thanks very much.
Well it's a question of building them as far as their dependencies are concerned. Java can usually work this out if it's not too complex with a wildcard.
sigh. I was able to compile one at a time last semester, and don't understand why the more advanced J2EE environment would choke on that... thanks for your help though.
:-)

Try compiling StudentApp.java - it may automatically compile the others too
>  but can you tell me why I still do get the errors if I try to compile each of them individually working from the bottom up

There is no reason you shouldn't be able to, if you can't then the suggested solution is *not* a resolution toy our problem. Feel free to reopen the question if you would like to determine what the problem is.

> Well it's a question of building them as far as their dependencies are concerned.

Please explain more as I've never had a case where a single class could not be compiled.
>>if you can't then the suggested solution is *not* a resolution toy our problem

Then isn't it rather strange that my suggested solution solved the problem?

Its a hack, not a solution.
Compiling classes individually is fine