I need help converting my code into an ArrayList. We are only supposed to use an ArrayList and not an array. I didn't see that part of my project and not too good with using ArrayList. Please help me figure this out.
public class Transcript {
private Course[] courses = new Course[10];
private int studentID;
private String studentName;
private int count;
public Transcript(int studentID, String studentName)
{
this.studentID = studentID;
this.studentName = studentName;
count = 0;
}
public void addCourse(String courseID, String letterGrade)
{
courses[count] = new Course(courseID,letterGrade);
count++;
}
public void updateCourse(String courseID, String letterGrade)
{
for(int i = 0;i<count;i++)
{
if(courseID.equals(courses[i].getCourseID()))
{
courses[i].updateGrade(letterGrade);
break;
}
}
}
public double getGPA()
{
return calculateGPA();
}
private double calculateGPA()
{
double GPA = 0;
double total = 0;
for(int i = 0;i<count;i++)
{
total = total + courses[i].getNumericGrade();
}
GPA = total/count;
return GPA;
}
public String getCourse(String courseID)
{
String str = courseID + " not found!";
for(int i = 0;i<count;i++)
{
if(courseID.equals(courses[i].getCourseID()))
{
str = courses[i].toString();
break;
}
}
return str;
}
@Override
public String toString()
{
String str = "ID:" + studentID + "\nName:" + studentName + "\nGPA:" + getGPA() + "\n";
for(int i = 0;i<count;i++)
{
str = str + courses[i].toString() + "\n";
}
return str;
}
}