I am writing a program to recored and maintain student data. I have written most of the code but am a running into problems, calling methods. I would like to call the following methods.
printAll();
printInvalidEmails();
printAverageGrade();
remove(“3”);
remove(“3”);
I have written the following code for my Roster class.
import java.util.ArrayList; public class Roster { private static ArrayList<Student> studentinfo = new ArrayList<>(); public static void main(String[] args) { add("1 ", "John", "Smith", "John1989@gmail.com", 20, 88, 79, 59); add("2 ", "Suzan", "Erickson", "Erickson_1990@gmailcom", 19, 91, 72, 85); add("3 ", "Jack", "Napoli", "The_lawyer99yahoo.com", 19, 85, 84, 87); add("4 ", "Erin", "Black", "Erin.black@comcast.net", 22, 91, 98, 82); add("5 ", "Eric", "Johnson", "Ejohnson@gmail.com", 26, 97, 96, 99); } public static void add(String studentID, String fname, String lname, String eaddress, int age, double grade1, double grade2, double grade3) { double[] grades = {grade1, grade2, grade3}; Student newStudent = new Student(studentID, fname, lname, eaddress, age, grades); studentinfo.add(newStudent); } public static void printAll() { System.out.println("Student data"); for (int i = 0; i < studentinfo.size(); i++) { studentinfo.get(i).print(); } } public static void printAverageGrade(String studentID) { System.out.println("Print Average Grade"); for (Student a : studentinfo) { if (a.getStudentID().equals(studentID)) { double average = (a.getGrades()[0] + a.getGrades()[1] + a.getGrades()[2] + a.getGrades()[3] + a.getGrades()[4]) / 2.0; System.out.println("Student ID: " + a.getStudentID() + " average grade:" + average); } } } public static void remove(String studentID) { for (Student a : studentinfo) { if (a.getStudentID().equals(studentID)) { studentinfo.remove(a); return; } } System.out.println("Unable to remove, student ID was not found"); } public static void printInvalidEmails(String Eaddress) { for (Student a : studentinfo) { String email = a.getEaddress(); if (email.equals(Eaddress)) { if (!email.contains("@")) { System.out.println(email + " Is not a valid Email"); } if (!email.contains(".")) { System.out.println(email + " Is not a valid Email"); } if (email.contains(" ")) { System.out.println(email + " Is not a valid Email"); } } } } }
The code for my second class, student is:
import java.util.ArrayList; public class Roster { private static ArrayList<Student> studentinfo = new ArrayList<>(); public static void main(String[] args) { add("1 ", "John", "Smith", "John1989@gmail.com", 20, 88, 79, 59); add("2 ", "Suzan", "Erickson", "Erickson_1990@gmailcom", 19, 91, 72, 85); add("3 ", "Jack", "Napoli", "The_lawyer99yahoo.com", 19, 85, 84, 87); add("4 ", "Erin", "Black", "Erin.black@comcast.net", 22, 91, 98, 82); add("5 ", "Alan", "Bulmahn", "abulmah@wgu.edu", 26, 97, 96, 99); } public static void add(String studentID, String fname, String lname, String eaddress, int age, double grade1, double grade2, double grade3) { double[] grades = {grade1, grade2, grade3}; Student newStudent = new Student(studentID, fname, lname, eaddress, age, grades); studentinfo.add(newStudent); } public static void printAll() { System.out.println("Student data"); for (int i = 0; i < studentinfo.size(); i++) { studentinfo.get(i).print(); } } public static void printAverageGrade(String studentID) { System.out.println("Print Average Grade"); for (Student a : studentinfo) { if (a.getStudentID().equals(studentID)) { double average = (a.getGrades()[0] + a.getGrades()[1] + a.getGrades()[2] + a.getGrades()[3] + a.getGrades()[4]) / 2.0; System.out.println("Student ID: " + a.getStudentID() + " average grade:" + average); } } } public static void remove(String studentID) { for (Student a : studentinfo) { if (a.getStudentID().equals(studentID)) { studentinfo.remove(a); return; } } System.out.println("Unable to remove, student ID was not found"); } public static void printInvalidEmails(String Eaddress) { for (Student a : studentinfo) { String email = a.getEaddress(); if (email.equals(Eaddress)) { if (!email.contains("@")) { System.out.println(email + " Is not a valid Email"); } if (!email.contains(".")) { System.out.println(email + " Is not a valid Email"); } if (email.contains(" ")) { System.out.println(email + " Is not a valid Email"); } } } } }
Thank you for your help.