Sapphireblue
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.equalsIgnoreC ase("x")))
{
identificationNumberInput = JOptionPane.showInputDialo g("Enter college student's ID:");
majorInput = JOptionPane.showInputDialo g("Enter college student's major:");
gradePointAverageInput = JOptionPane.showInputDialo g("Enter college student's GPA:");
userCollegeStudent = new CollegeStudent(Integer.par seInt(iden tification NumberInpu t), Double.parseDouble(gradePo intAverage Input), majorInput);
userInput = JOptionPane.showInputDialo g(userColl egeStudent .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\Stude ntApp.java :14: cannot resolve symbol
symbol : class CollegeStudent
location: class StudentApp
CollegeStudent userCollegeStudent;
^
C:\j2sdk1.4.0_01\bin\Stude ntApp.java :24: cannot resolve symbol
symbol : class CollegeStudent
location: class StudentApp
userCollegeStudent = new CollegeStudent(Integer.par seInt(iden tification NumberInpu t), Double.parseDouble(gradePo intAverage Input), 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(userIdentificationNu mber, userGradePointAverage);
major = userMajor;
}
public String toString()
{
String collegeStudentInfoString = "Student number: " + identificationNumber
+ "\nGPA: " + gradePointAverage
+ "\nMajor: " + major;
return collegeStudentInfoString;
}
}
C:\j2sdk1.4.0_01\bin\Colle geStudent. java:6: cannot resolve symbol
symbol : class Student
location: class CollegeStudent
public class CollegeStudent extends Student
^
C:\j2sdk1.4.0_01\bin\Colle geStudent. java:12: cannot resolve symbol
symbol : variable identificationNumber
location: class CollegeStudent
identificationNumber = 0;
^
C:\j2sdk1.4.0_01\bin\Colle geStudent. java:13: cannot resolve symbol
symbol : variable gradePointAverage
location: class CollegeStudent
gradePointAverage = 0.0;
^
C:\j2sdk1.4.0_01\bin\Colle geStudent. java:25: cannot resolve symbol
symbol : variable identificationNumber
location: class CollegeStudent
String collegeStudentInfoString = "Student number: " + identificationNumber
^
C:\j2sdk1.4.0_01\bin\Colle geStudent. 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(doubl e userGradePointAverage)
{
gradePointAverage = userGradePointAverage;
}
public static void setIdentificationNumber(in t userIdentificationNumber)
{
identificationNumber = userIdentificationNumber;
}
public String toString()
{
String studentInfoString = "Identification number: " + identificationNumber
+ "\nGrade point average: " + gradePointAverage;
return studentInfoString;
}
}
[this compiles fine]
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,
CollegeStudent userCollegeStudent;
String userInput = "";
try
{
while (!(userInput.equalsIgnoreC
{
identificationNumberInput = JOptionPane.showInputDialo
majorInput = JOptionPane.showInputDialo
gradePointAverageInput = JOptionPane.showInputDialo
userCollegeStudent = new CollegeStudent(Integer.par
userInput = JOptionPane.showInputDialo
}
}
catch(NullPointerException
{
System.exit(0);
}
System.exit(0);
}
}
C:\j2sdk1.4.0_01\bin\Stude
symbol : class CollegeStudent
location: class StudentApp
CollegeStudent userCollegeStudent;
^
C:\j2sdk1.4.0_01\bin\Stude
symbol : class CollegeStudent
location: class StudentApp
userCollegeStudent = new CollegeStudent(Integer.par
^
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(userIdentificationNu
major = userMajor;
}
public String toString()
{
String collegeStudentInfoString = "Student number: " + identificationNumber
+ "\nGPA: " + gradePointAverage
+ "\nMajor: " + major;
return collegeStudentInfoString;
}
}
C:\j2sdk1.4.0_01\bin\Colle
symbol : class Student
location: class CollegeStudent
public class CollegeStudent extends Student
^
C:\j2sdk1.4.0_01\bin\Colle
symbol : variable identificationNumber
location: class CollegeStudent
identificationNumber = 0;
^
C:\j2sdk1.4.0_01\bin\Colle
symbol : variable gradePointAverage
location: class CollegeStudent
gradePointAverage = 0.0;
^
C:\j2sdk1.4.0_01\bin\Colle
symbol : variable identificationNumber
location: class CollegeStudent
String collegeStudentInfoString = "Student number: " + identificationNumber
^
C:\j2sdk1.4.0_01\bin\Colle
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(doubl
{
gradePointAverage = userGradePointAverage;
}
public static void setIdentificationNumber(in
{
identificationNumber = userIdentificationNumber;
}
public String toString()
{
String studentInfoString = "Identification number: " + identificationNumber
+ "\nGrade point average: " + gradePointAverage;
return studentInfoString;
}
}
[this compiles fine]
and put them in a single package
ASKER
They were already all in the same dir, but I went ahead and tried the wildcard compile... no luck.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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.
ASKER
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
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.
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?
Then isn't it rather strange that my suggested solution solved the problem?
Its a hack, not a solution.
Compiling classes individually is fine
Compiling classes individually is fine
javac *.java