import java.util.*;
public class TestStudent
{
public static String firstName(String s)
{
return s.substring(0, s.indexOf(" "));
}
public static void printBook(List<Student> a)
{
System.out.println(" Name 01 02 03 04 05");
System.out.println("---------------------------------------------------------------");
for (Student i : a)
{
System.out.println(i);
}
}
public static void replaceName(List<Student> a, String s, String t)
{
for(Student v : a)
{
if(v.getName().equals(s))
{
v.setName(t);
}
}
System.out.println("Changing " + firstName(s) +"'s" + " name to " + t + ":");
}
public static void replaceQuiz(List<Student> a, String s, int q, int r)
{
for(Student v : a)
{
if(v.getName().equals(s))
{
v.setQuiz(q, r);
}
}
System.out.println("Replacing " + firstName(s) +"'s" + " quiz " + q + " score to " + r + ":");
}
public static void replaceStudent(List<Student> a, String s, String n, int q, int w, int e, int r, int t)
{
for(Student v : a)
{
if(v.getName().equals(s))
{
v.setName(n);
v.setQuiz(1, q);
v.setQuiz(2, w);
v.setQuiz(3, e);
v.setQuiz(4, r);
v.setQuiz(5, t);
}
}
System.out.println("Replacing " + firstName(s) + " with " + n + ": " + q + ", " + w + ", " + e + ", " + r + ", " + t + ":");
}
public static void insertStudent(List<Student> a, String s, String n, int q, int w, int e, int r, int t)
{
int c = 0;
for(Student k : a)
{
if(k.getName().equals(s))
{
a.add(c, new Student(n, q, w, e, r, t));
}
c++;
}
System.out.println("Inserting " + n + ": " + q + ", " + w + ", " + e + ", " + r + ", " + t + ", " + "before " + firstName(s) + ":");
}
public static void deleteStudent(List<Student> a, String s)
{
int c = 0;
for(Student q : a)
{
if (q.getName().equals(s))
{
a.remove(c);
}
c++;
}
System.out.println("Removing " + s + ":");
}
public static void main(String [] args)
{
List<Student> myClass = new ArrayList<Student>();
myClass.add(new Student("Mark Kennedy", 70, 80, 90, 100, 90));
myClass.add(new Student("Maz Gerard", 80, 85, 90, 85, 80));
myClass.add(new Student("Jean Smith", 50, 79, 89, 99, 100));
myClass.add(new Student("Betty Farm", 85, 80, 95, 88, 89));
myClass.add(new Student("Dilbert Gamma", 70, 70, 90, 70, 80));
System.out.println("Starting Gradebook: ");
System.out.println();
printBook(myClass);
System.out.println();
replaceName(myClass,"Betty Farm", "Betty Boop");
System.out.println();
printBook(myClass);
System.out.println();
replaceQuiz(myClass, "Jean Smith", 1, 60);
System.out.println();
printBook(myClass);
System.out.println();
replaceStudent(myClass, "Dilbert Gamma", "Mike Kappa", 00, 00, 00, 90, 90);
System.out.println();
printBook(myClass);
System.out.println();
insertStudent(myClass, "Betty Boop", "Lily Mu", 85, 95, 70, 0, 100);
System.out.println();
printBook(myClass);
System.out.println();
deleteStudent(myClass, "Max Gerard");
System.out.println();
printBook(myClass);
}
}