I've created all of my objects in my class "student" by hand and really just need to use an array to put the names, grades and ID numbers into. When I try, it gives me an error about incompatible types. I understand it's probably due to a restriction on some sort of syntax type of error. Could anyone help with the physical grammar of this portion please? It would be much appreciated!
package bilak_sackin_assignment_7;
public class Bilak_Sackin_Assignment_7 {
public static void main(String[] args) {
student Frank = new student("Frank", 95.2, 11231);
student Billy = new student("Billy", 65.6, 656454);
student Alex = new student("Alex", 65.2, 123456);
student Miranda = new student("Miranda", 80.0, 963852);
student Joel = new student("Joel", 89.9, 486248);
Frank.display();
Billy.display();
Alex.display();
Miranda.display();
Joel.display();
}
}
class student {
String[] name = new String[5];
double[] grade = new double[5];
int[] ID = new int[5];
public student(String[] n, double[] g, int[] d) {
name = n;
grade = g;
ID = d;
}
public void display() {
for (int i = 0; i < 4; i++) {
System.out.println("Names: " + name[i]);
System.out.println("Grades: " + grade[i]);
System.out.println("Student ID: " + ID[i]);
}
}
}
String[]as its first parameters; you are passing aString. Either pass e.g.new String[] { "Miranda" }instead of"Miranda", or change the type of the parameter toString.