![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 20
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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
__________________
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 20
Rep Power: 0
![]() |
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] |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Do you have any code for the student class? Even a little would give me a better idea of what to do
__________________
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
Can I get your Student Class please?
__________________
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2006
Posts: 20
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#7 |
|
Expert Programmer
|
It would help if you posted the error message you are getting when you try to access a CourseList object inside the GradeCalculator class.
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2006
Posts: 20
Rep Power: 0
![]() |
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
|
|
|
|
|
|
#9 |
|
Expert Programmer
|
I'm almost done just give me about 30 minutes ok
__________________
|
|
|
|
|
|
#10 |
|
Expert Programmer
|
Do you just need it to print out the
-class average -Student name and score
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|