?
Solved

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

Posted on 2005-03-06
11
Medium Priority
?
240 Views
Last Modified: 2010-03-31
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
Comment
Question by:Sapphireblue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13471356
Put all your classes in the same directory and try

javac *.java
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13471377
and put them in a single package
0
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13471379
They were already all in the same dir, but I went ahead and tried the wildcard compile... no luck.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 13471384
You may find there are conflicting classes in your classpath. Put all 3 in a *new* directory and

set classpath=.

javac *.java
0
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13471424
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13471435
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
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13471466
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13471476
:-)

Try compiling StudentApp.java - it may automatically compile the others too
0
 
LVL 92

Expert Comment

by:objects
ID: 13472057
>  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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13476229
>>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
 
LVL 92

Expert Comment

by:objects
ID: 13481418
Its a hack, not a solution.
Compiling classes individually is fine
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question