Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 22nd, 2006, 5:05 PM   #1
taporctv
Newbie
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 taporctv is on a distinguished road
Need help with java project using bluej

I've been searching the web for answers and I happened to stumble upon this forum.
Well here's the project specifications:
http://courses.cs.vt.edu/~cs1054/S06.../project3.html

Basically what i have to do is make three classes: CourseList, Student, Grade Calculator I've finished the CourseList and Student classes. I'm having trouble with the GradeCalculator class. It is supposed to be a subclass of CourseList and inherit all its methods. The GradeCalculator class is supposed to make 5 Student objects and 1 CourseList Object. When I use the inherited methods from the CourseList class none of them can interact with the objects created within the GradeCalculator.

Any help would be appreciated.. Thanks, Tim
taporctv is offline   Reply With Quote
Old Mar 22nd, 2006, 5:09 PM   #2
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Post some code and let me take a look also is this supposed to be saved in a data base because if it is then you lost me
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Mar 22nd, 2006, 5:19 PM   #3
taporctv
Newbie
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 taporctv is on a distinguished road
Here's the CourseList class
[PHP]
import java.util.ArrayList;
import java.text.DecimalFormat;

/**
* Write a description of class CourseList here.
*
* @author Tim Taporco
* @version March 21, 2006
*/
public class CourseList
{
// instance variables - replace the example below with your own
private ArrayList studentList;

/**
* Constructor for objects of class CourseList
*/
public CourseList()
{
studentList = new ArrayList();
}

/**
* Display all the student names, grades, and class average
**/
public void browseGrades()
{
// index variable
int index=0;
// sum variable
int gradeSum = 0;
// Person object
Student studentInformation;

// While loop
while(index < studentList.size()){

studentInformation = (Student) studentList.get(index);
System.out.println(studentInformation.getName() + " " + studentInformation.getJavaGrade());
gradeSum = gradeSum + studentInformation.getJavaGrade();
index++;

}
// Format output
DecimalFormat form = new DecimalFormat("0.00");
double classAverage = (double) gradeSum / studentList.size();
System.out.println("The class average is: " + form.format(classAverage));
}


/**
* Display the class average
*
* @return classAverage the class average
*/
public double calJavaAverage()
{
// index variable
int index=0;
// sum variable
int gradeSum = 0;
// Person object
Student studentInformation;

// While loop
while(index < studentList.size()){
studentInformation = (Student) studentList.get(index);
gradeSum = gradeSum + studentInformation.getJavaGrade();
index++;
}
// Format output
DecimalFormat form = new DecimalFormat("0.00");
double classAverage = (double) gradeSum / studentList.size();
System.out.println("The class average is: " + form.format(classAverage));

return classAverage;
}


/**
* Add a student to the course list
*
* @param student a student object
*/
public void addStudent(Student student)
{
studentList.add(student);
}

}

[/PHP]

Here's the GradeCalculator class. It is supposed to be a subclass of CourseList.

[PHP]
import java.util.ArrayList;
import java.lang.String;
/**
* Write a description of class GradeCalculator here.
*
* @author Tim Taporco
* @version March 21, 2006
*/
public class GradeCalculator extends CourseList
{


/**
* Constructor for objects of class GradeCalculator
*/
public GradeCalculator()
{

}

/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void createObject()
{
CourseList courseList = new CourseList();

Student student1 = new Student("Tim Taporco",99);
Student student2 = new Student("John Smith",100);
Student student3 = new Student("John Doe",88);
Student student4 = new Student("Jane Doe",90);
Student student5 = new Student("Jerry Rice",80);

courseList.addStudent(student1);
courseList.addStudent(student2);
courseList.addStudent(student3);
courseList.addStudent(student4);
courseList.addStudent(student5);


}
}
[/PHP]
taporctv is offline   Reply With Quote
Old Mar 22nd, 2006, 5:32 PM   #4
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Do you have any code for the student class? Even a little would give me a better idea of what to do
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Mar 22nd, 2006, 5:45 PM   #5
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Can I get your Student Class please?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Mar 22nd, 2006, 5:45 PM   #6
taporctv
Newbie
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 taporctv is on a distinguished road
Here's the student class code
[PHP]
import java.lang.String;
import java.lang.Object;
/**
* Write a description of class Student here.
*
* @author Tim Taporco
* @version March 21, 2006
*/

public class Student
{
// instance variables - replace the example below with your own
private String name;
private int javaGrade;

/**
* Constructor for objects of class Student
*/
public Student(String name, int javaGrade)
{
this.name = name;
if(javaGrade >=0){
this.javaGrade = javaGrade;
}
else{
System.out.println("Please enter a non negative java grade");
}
}

/**
* Constructor for objects of class Student
*/
public Student()
{
name = "Tim Taporco";
javaGrade = 96;
}
/**
* Update javaGrade to the new grade that is passed
*
* @param newGrade new grade that updates old grade
*/
public void updateJavaGrade(int newGrade)
{
javaGrade = newGrade;
}

/**
* Update name to the new name that is passed
*
* @param newName new name that updates old name
*/
public void updateName(String newName)
{
name = newName;
}

/**
* Return java grade
*
* @return javaGrade the java grade
*/
public int getJavaGrade()
{
return javaGrade;
}

/**
* Return the name
*
* @return name the name of student
*/
public String getName()
{
return name;
}

/**
* Print information about grades along with student name
*/



}
[/PHP]

Let me try to give you a better understanding of what im trying to do.
Bascally the CourseList class contains an ArrayList that stores Student objects. An object of the CourseList has a method called addStudent(Student student). This adds a student object to the array list in the CourseList class. Basically my problem is with the GradeCalculator class. Within the class it must have a method that creates 5 student objects and 1 CourseList object. GradeCalculator is a subclass of CourseList. When I use the inherited methods I cant access the CourseList object within GradeCalculator.
taporctv is offline   Reply With Quote
Old Mar 22nd, 2006, 5:50 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
It would help if you posted the error message you are getting when you try to access a CourseList object inside the GradeCalculator class.
titaniumdecoy is offline   Reply With Quote
Old Mar 22nd, 2006, 6:04 PM   #8
taporctv
Newbie
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 taporctv is on a distinguished road
No errors are popping up within blueJ. Basically when I create a GradeCalculator object and run the method to create 5 student objects and 1 CourseList Object, i'm having trouble using the inherited methods to display the contents of the CourseList object (The 5 Student objects created within the GradeCalculator Object are Added to the CourseList Object that is created in the Grade Calculator Object). Using the methods from CourseList display the ArrayList as empty. I think when I use the inherited methods within the GradeCalculator object, its using the empty ArrayList created in CourseList Class
taporctv is offline   Reply With Quote
Old Mar 22nd, 2006, 6:07 PM   #9
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
I'm almost done just give me about 30 minutes ok
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Mar 22nd, 2006, 6:08 PM   #10
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Do you just need it to print out the
-class average
-Student name and score
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC