You are here:

Java/I m stuck in the homework


CreateaCollegeCourse class. The class contains fields for the course ID (for example,“CIS 210”), credit hours (for example, 3), and a letter grade (for example, ‘AIncludeget() andset()methods for each field. Create aStudent class containing an
ID number and an array of fiveCollegeCourse objects. Create aget() andset() method for theStudentID number. Also create aget() method that returns one of theStudent’sCollegeCourses; the method takes an integer argument and returns theCollegeCourse in that position (0 through 4). Next,create aset() method that sets the value of one of theStudent’sCollegeCourses; the method takes two arguments—aCollegeCourse and an integer representing the CollegeCourse’s position (0 through 4). Save the files as and

i have tried this:
package lesson4;

public class CollegeCourse {
    static char[] grades = {'A','B','C','D','F'};
      static int[] credithours = {4,3,2,1,0};
      static String[] courseI={"CIS420","CIS320"};
   public static void main (String[] args) {

package lesson4;

public class Student {
   int studentNumber;
   private int[] studentPoints = new int[5];
  public int  getStudentIdNumber() {
         return studentNumber;
   public String[] getStudentCollegeCourses(){
   return CollegeCourse.courseI;   
   public void setGrade(int sub, char grade) {
      CollegeCourse.grades[sub] = grade;
       // added in exercise 5b
       for (int i = 0; i < 5; i++)
         if (grade == CollegeCourse.grades[i])
         studentPoints[sub] =CollegeCourse.credithours[i];
   public int getNumber() {
       return studentNumber;
   // printGrades() added in exercise 5b
   public void printGrades() {
       System.out.println("Student number " + studentNumber);
       int total = 0;
       for (int i = 0; i < 5; i++) {
         System.out.println("\t" + " grade " + (i + 1)
         + " is "
         + CollegeCourse.grades[i]
         + " for "
         + studentPoints[i] + " points ");
         total += studentPoints[i];
   // printGrades() added in exercise 5b

Your CollegeCourse should not have any static fields. Instead they should all be non-array non-static values. Your Student class should have 2 fields, one for the student number, and one for the courses (which should be CollegeCourse[] type). You need to initialize the values in the college course array in your constructor for you Student class. The get and set methods need to go into the CollegeCourse[] variable to change it's value. E.g. collegeCourse[sub].grade = grade;

I don't see any directions to keep a total of the student points, so don't do it. It doesn't make any sense to at this point since the grades are not scores, but simply letters.


All Answers

Answers by Expert:

Ask Experts


Artemus Harper


I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.


I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Washington State University

MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 All rights reserved.