• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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]
0
Sapphireblue
Asked:
Sapphireblue
  • 5
  • 3
  • 2
  • +1
1 Solution
 
CEHJCommented:
Put all your classes in the same directory and try

javac *.java
0
 
bloodredsunCommented:
and put them in a single package
0
 
SapphireblueAuthor Commented:
They were already all in the same dir, but I went ahead and tried the wildcard compile... no luck.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
You may find there are conflicting classes in your classpath. Put all 3 in a *new* directory and

set classpath=.

javac *.java
0
 
SapphireblueAuthor Commented:
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.
0
 
CEHJCommented:
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.
0
 
SapphireblueAuthor Commented:
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.
0
 
CEHJCommented:
:-)

Try compiling StudentApp.java - it may automatically compile the others too
0
 
objectsCommented:
>  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.
0
 
CEHJCommented:
>>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?

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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now