 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
richardkreidl@northwester Guest
|
Posted: Tue Nov 22, 2005 10:12 pm Post subject: Newbie: error messages?? |
|
|
I'm getting the following two errors:
C:Documents and SettingsRichardSemesterStudent.java:17: cannot find
symbol
symbol : constructor CollegeCourse()
location: class CollegeCourse
courses[x] = new CollegeCourse();
^
C:Documents and SettingsRichardSemesterStudent.java:32: cannot find
symbol
symbol : variable courses
location: class Student
System.out.println(courses[1].getcourseID());
^
Here are my two java classes:
//CollegeCourse.java
class CollegeCourse
{
private int courseID;
private char grades;
private int hours;
public CollegeCourse(char grade, int course, int hour)
{
grades = grade;
courseID = course;
hours = hour;
}
public void setCourseID(int id)
{
courseID = id;
}
public int getCourseID()
{
return courseID;
}
public void setGrade(char Grade)
{
grades = Grade;
}
public char getGrade()
{
return grades;
}
public void setHours(int hr)
{
hours = hr;
}
public int geHours()
{
return hours;
}
}
//Student.java
public class Student {
private int idNumber;
public Student(int studentID)
{
idNumber = studentID;
}
public static void main(String[] args)
{
CollegeCourse[] courses = new CollegeCourse[5];
for (int x = 0; x < 5; ++x) {
courses[x] = new CollegeCourse();
}
}
public void setIDNumber(int num)
{
idNumber = num;
}
public int getIDNumber()
{
return idNumber;
}
public static void Show()
{
System.out.println(courses[1].getCourseID());
}
}
What I'm supposed to do is: Create a CollegteCourse class. The class
contains fields for the course ID(for ex: "CIS 210"), credit hours
(for ex: 3), and a letter grade (for ex: 'A').
Include a get() and set() methods for each field. Create a Student
class containing an ID number and an array fo five CollegeCourse
objects.
Create a get() and set() for the StudentID number. Also, create a get()
method that returns one of the Student's CollegeCOurses; the method
takes an integer argument and returns the CollegeCourse in that
position(0 through 4).
Next, create a set() method that sets the value of one of the Student's
CollegeCourses; the method takes two arguments -- a CollegeCOurse and
an integer(0 0through 4).
What am I doing wrong???
|
|
| Back to top |
|
 |
klynn47@comcast.net Guest
|
Posted: Tue Nov 22, 2005 10:22 pm Post subject: Re: Newbie: error messages?? |
|
|
Ok the first problem is that you're trying to call a noargument
constructor of CollegeCourse, and there isn't one.
The second problem is that you create the array courses in the main
method. It is local to the main method so you can't access it from
Show()
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Nov 22, 2005 10:43 pm Post subject: Re: Newbie: error messages?? |
|
|
On 22 Nov 2005 14:12:45 -0800, "richardkreidl (AT) northwesternmutual (DOT) com"
<richardkreidl (AT) northwesternmutual (DOT) com> wrote, quoted or indirectly
quoted someone who said :
| Quote: | CollegeCourse[] courses = new CollegeCourse[5];
|
this is a local variable known only inside main. If you want everyone
to see it, it should be static.
see http://mindprod.com/jgloss/scope.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|