I've got both classes of my code. Skip down to about 3/4 just above the main method to public class Roster. The errors seem to be in reference to my ArrayList not liking type Students(String didn't work either). Can someone put this in an IDE and help me figure out what's wrong?
I'm getting errors on the lines that read:
1)Students newStudent = new String(studentId, firstName, lastName, email, age, grades);
2)studentRoster.get(i).print();
3)int average = (newStudent.getGrades()[0] + newStudent.getGrades()[1]+ newStudent.getGrades()[2])/3;
4) System.out.println("Student Number: " + newStudent.getstudentId() + " average grade: " + average);
5)if(b.getstudentId().equals(studentId))
6)if(b.getQuantity() > 0)
What I have tried:
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
public class Student{
private String studentId;
private String firstName;
private String lastName;
private String email;
private String age;
private int[] grades;
public Student(String studentId, String firstName, String lastName, String email, String age, int[] grades){
setStudentId(studentId);
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
setAge(age);
setGrades(grades);
}
public String getStudentId(){
return studentId;
}
public void setStudentId(String studentId){
this.studentId = studentId;
}
public String getFirstName(){
return firstName;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public String getLastName(){
return lastName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
public String getEmail(){
return email;
}
public void setEmail(String email){
this.email = email;
}
public String getAge(){
return age;
}
public void setAge(String age){
this.age = age;
}
public void setGrades(int[] grades){
this.grades = grades;
}
public int[] getGrades(){
return grades;
import java.util.ArrayList;
public class Roster {
private static ArrayList<students> studentRoster = 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@gmail.com","19", 91, 72, 85);
add("3","Jack","Napoli","The_lawyer99@yahoo.com","19", 85, 84, 87);
add("4","Erin","Black","Erin.black@comcast.net","22", 91, 98, 82);
add("5","Jason","Hancock","jhanc21@wgu.edu","30", 98, 95, 96);
printAllStudents();
printAverageGrades();
}
public static void add(String studentId, String firstName, String lastName, String email, String age, int grades1, int grades2, int grades3){
int[] grades = {grades1, grades2, grades3};
Students newStudent = new String(studentId, firstName, lastName, email, age, grades);
studentRoster.add(newStudent);
}
public static void printAllStudents(){
System.out.println("Student Roster");
for(int i=0; i < studentRoster.size(); i++){
studentRoster.get(i).print();
}
}
public static void printAverageGrades(){
System.out.println("Average Grades");
for(Students newStudent : studentRoster){
int average = (newStudent.getGrades()[0] + newStudent.getGrades()[1]+ newStudent.getGrades()[2])/3;
System.out.println("Student Number: " + newStudent.getstudentId() + " average grade: " + average);
}
}
public static void findStudent(String studentId){
for(Students b: studentRoster){
if(b.getstudentId().equals(studentId)){
if(b.getQuantity() > 0){
System.out.println(studentId + " is a student.");
return;
}else{
System.out.println(studentId + " is not a student.");
return;
}
}
}
System.out.println("We do not have a student number " + studentId);
}
}
Eclipse is accepting my private static ArrayList<students> studentRoster = new ArrayList<>;
I know Students isn't a type, but I tried String, and that didn't work either.