468,253 Members | 1,226 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

Help with Java Arrays and methods ASAP Please!!!

First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method to get a course. It does this by taking an integer and returning the course to that position (0 through 4). Then I must create a set method that sets the value of one of the courses by taking two arguements a name and an integer and returning the name to the position indicated by the integer.

After that I must write an application that prompts the user for grades for 5 different courses: it will prompt for the the id number, then course data for each of 5 courses for that ID number. The user will enter the ID number of the student, then when prompted a number from 1 to 5 indicating which course, and a letter grade for the course.

So far this is what I have:
Expand|Select|Wrap|Line Numbers
  1. // CollegeCourse.java
  2. // Chapter 8, Exercise 5a
  3. // A CollegeCourse has an ID, credits, and a letter grade
  4.  
  5. public class CollegeCourse
  6. {
  7.     private String courseID;
  8.     private int credits; 
  9.     private char grade;
  10.     public String getID()
  11.     {
  12.         return courseID;
  13.     }
  14.     public int getCredits()
  15.     {
  16.         return credits;
  17.     }
  18.     public char getGrade()
  19.     {
  20.         return grade;
  21.     }
  22.     public void setID(String idNum)
  23.     {
  24.  
  25.     }
  26. }
  27.  
  28.  
Expand|Select|Wrap|Line Numbers
  1. // Student.java
  2. // Chapter 8, Exercise 5c
  3. // A Student has an ID, and five CoollegeCourses,
  4.  
  5. public class Student
  6. {
  7.     private int stuID;
  8.     private CollegeCourse[] course = new CollegeCourse[5]; 
  9.  
  10.     public int getID()
  11.     {
  12.         return stuID;
  13.     }
  14.  
  15. *******stuck here***********
  16.     }
  17. }
  18.  
Expand|Select|Wrap|Line Numbers
  1. // InputGrades.java
  2. // Chapter 8, Exercise 5b
  3. // Allows input of 5 grades each for 10 students
  4.  
  5. import javax.swing.*;
  6. public class InputGrades
  7. {
  8.     public static void main(String[] args)
  9.     {
  10. // http://www.brpreiss.com/books/opus5/html/page89.html
  11.         Student[] students = new Student[10]; 
  12.  
  13.         int x, y, z;
  14.         String courseEntry, entry = "", message;
  15.         int idEntry, credits;
  16.         char gradeEntry = ' ';
  17.         boolean isGoodGrade = false;
  18.         char[] grades = {'A', 'B', 'C', 'D', 'F'};
  19.         for(x = 0; x < students.length; ++x)
  20.         {
  21.             Student stu = new Student();
  22.             entry = JOptionPane.showInputDialog(null, "For student #" + (x + 1) + ", enter the student ID");
  23.             idEntry = Integer.parseInt(entry);
  24.             stu.setID(idEntry);
  25. *********stuck here****************
  26.             CollegeCourse temp = new CollegeCourse();
  27.             temp.setID(courseEntry);
  28.             temp.setCredits(credits);
  29.             temp.setGrade(gradeEntry);
  30.             stu.setCourse(temp, y);
  31.         }
  32.         students[x] = stu;
  33.     }
  34.         for(x = 0; x < students.length; ++x)
  35.         {
  36.             message = "Student #" + (x + 1) + " ID #" + students[x].getID();
  37.             for(y = 0; y < 5; ++y)
  38.             {
  39.                 CollegeCourse temp = new CollegeCourse();
  40.                 temp = students[x].getCourse(y);
  41.                 message = message + "\n" + temp.getID() + " " + temp.getCredits() + " credits. Grade is " + temp.getGrade(); 
  42.                 JOptionPane.showMessageDialog(null,message);
  43.             }
  44.             System.exit(0);
  45.         }
  46.     }
  47. }
  48.  
Mar 29 '08 #1
1 3208
pronerd
392 Expert 256MB
So your questions is?
Apr 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Radha News | last post: by
1 post views Thread by Newbie19 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.