Question: Help me come up with a for each statement to print their letter grade. this is the code i have so far and then this

Help me come up with a for each statement to print their letter grade. this is the code i have so far and then this is the given code from student.java
public class GradeBook {
public static void main(String[] args){
final String GRADEDELIMITERS =",";
/* TODO: Create a new ArrayList of Student objects called gradebook. */
ArrayList gradebook = new ArrayList();
/********* START PHASE 1 TODO ITEMS *********/
/*
* TODO: Create student objects to populate your ArrayList using the following
*
* Student 1
* First Name: Samwise
* Last Name: Gamgee
* Student ID: 1234
* Grade: 93
*
* Student 2
* First Name: Frodo
* Last Name: Baggins
* Student ID: 2345
* Grade: 88
*
* Student 3
* First Name: Pippin
* Last Name: Took
* Student ID: 3456
* Grade: 70
*
* Student 4
* First Name: Meriadoc
* Last Name: Brandybuck
* Student ID: 4567
* Grade: 70
*/
Student s1= new Student("Samwise", "Gamgee", 1234);
Student s2= new Student("Frodo", "Baggins", 2345);
Student s3= new Student("Pippin", "Took", 3456);
Student s4= new Student("Meriadoc", "Brandybuck", 4567);
gradebook.add(s1);
gradebook.add(s2);
gradebook.add(s3);
gradebook.add(s4);
/********* END PHASE 1 TODO ITEMS *********/
Student.java
public class Student {
private String firstName;
private String lastName;
private int id;
private int grade;
/**
* Create a new student object
* @param firstName First name of student
* @param lastName Last name of student
* @param id Student's id number
*/
public Student(String firstName, String lastName, int id){
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.grade =-1;
}
/**
* @return the firstName
*/
public String getFirstName(){
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName){
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName(){
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName){
this.lastName = lastName;
}
/**
* @return the id
*/
public int getId(){
return id;
}
/**
* @param id the id to set
*/
public void setId(int id){
this.id = id;
}
/**
* @return the grade
*/
public int getGrade(){
return grade;
}
/**
* @param grade the grade to set
*/
public void setGrade(int grade){
this.grade = grade;
}
/**
* Get a letter grade that represents the student's current score
* @return String containing the letter grade representing the student's course grade
*/
public String getLetterGrade(){
String letterGrade;
if (this.grade >=90){
letterGrade ="A";
} else if (this.grade >=80){
letterGrade ="B";
} else if (this.grade >=70){
letterGrade ="C";
} else if (this.grade >=60){
letterGrade ="D";
} else if (this.grade >=0){
letterGrade ="F";
} else {
letterGrade ="No grades have been entered for student";
}
return letterGrade;
}
@Override
public String toString(){
String output ="";
String letter = this.getLetterGrade();
output += this.firstName +""+ this.lastName +" has "+((letter.equals("A")||letter.equals("F"))?"an ":"a ")+ letter +".";
return output;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!