Here's what I have so far. After returning the value then I gotta print the avg in a separate method. I also need to check the names of the first and last student using an "equals" method. Please someone help with whatever you can. Here's what I got:
import java.util.Scanner;
public class StudentLists {
//Main method. Prompts user for the number of students.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter the number of students in this class: ");
int s = in.nextInt();
Student[] students=new Student[s];
FillStudents(s,students);
printAll(students);
}
public static void FillStudents(int s, Student[] students){
for (int i=0; i<s; i++)
{
Scanner inf = new Scanner(System.in);
System.out.println("Please enter student's first name: ");
String first = inf.nextLine();
System.out.println("Please enter student's last name: ");
String last=inf.nextLine();
System.out.println("Please enter the number of credits completed: ");
int c=inf.nextInt();
System.out.println("Please enter student's GPA: ");
Double g=inf.nextDouble();
students[i] = new Student(first, last, c, g);
}
}
public static void printAll(Student[] students) {
System.out.println("Names Credits GPA");
for(int i = 0; i < students.length; i++)
System.out.println(students);
}
public static Double getAvg(Student[] students, Double g){
double sum=0.0;
double avg=0.0;
for(int i=0; i<students.length; i++){
sum+=g;
}
avg=sum/students.length;
return avg;
}
}