Ok here is ALL the code, there are 3 seperate classes.
Transcript class:
import java.util.ArrayList;
import java.util.Iterator;
public class Transcript
{
//Instance Variables
private ArrayList<Course> courses;
private
String studentId;
private String studentName;
public Transcript(String id, String name)
{
//Initialize instance variables
studentId = id;
studentName = name;
courses = new ArrayList();
}
//returns the number of courses stored in the courses Array
public int numberOfCourses()
{
return courses.size();
}
//adds a course to the courses Array
public void addCourse(Course aCourse)
{
courses.add(aCourse);
}
public Course getCourse(int courseIndex)
{
if (courseIndex < 0)
{
return (null);
}
else if (courseIndex < numberOfCourses())
{
return courses.get(courseIndex);
}
else
{
return (null);
}
}
public char getLetterGrade(int courseIndex)
{
char grade;
if (courseIndex < 0)
{
return ' ';
}
else if (courseIndex < numberOfCourses())
{
courses.get(courseIndex);
return Grade.getLetterGrade();
}
else
{
return ' ';
}
}
}
Course class:
/**
Patrick Kent
3-8-06
This class takes information about a course, and allows the user to
set the grade and get the points from the grade class as well.
*/
public class Course
{
private String title;
private int creditHours;
private Grade grade;
//Allows the user to enter a course, credit worth, and letter grade
public Course(String courseTitle, int courseCredits, char letterGrade)
{
title = new String(courseTitle);
creditHours = courseCredits;
grade = new Grade(letterGrade);
}
//allows the user to reset the course title
public void setTitle(String newTitle)
{
title = newTitle;
}
//returns the course title
public String getTitle()
{
return title;
}
//allows the user to reset the amount of credit hours
public void setCreditHours(int credits)
{
creditHours = credits;
}
//returns the credit hours
public int getCreditHours()
{
return creditHours;
}
//returns the amount of points
public int getQualityPoints()
{
return grade.qualityPoints();
}
//allows the user to reset the grade
public void setGrade(char letterGrade)
{
grade.setLetterGrade(letterGrade);
}
//returns the grade
public char getGrade()
{
return grade.getLetterGrade();
}
//returns course and grade information
public String toString()
{
return "Course: " + title
+ " (" + creditHours + " credits);"
+ " grade " + getGrade();
}
}
Grade class:
public class Grade
{
private char letterGrade;
//takes the entered grade and converts it to an uppercase char
public Grade(char grade)
{
letterGrade = grade;
letterGrade = Character.toUpperCase(letterGrade);
}
//this method allows the user to change the grade entered
public void setLetterGrade(char grade)
{
letterGrade = grade;
letterGrade = Character.toUpperCase(letterGrade);
}
//returns the letter grade entered by the user
public char getLetterGrade()
{
return letterGrade;
}
//retruns a number of "points" based on the entered letter grade
public int qualityPoints()
{
int points;
if (letterGrade == 'A')
points = 4;
else if (letterGrade == 'B')
points = 3;
else if (letterGrade == 'C')
points = 2;
else if (letterGrade == 'D')
points = 1;
else
points = 0;
return points;
}
}