Question: Code in java Todo: 1. create an array of Student objects from the user's inputs 2. for each Student object, obtain his quiz scores from
Code in java
Todo: 1. create an array of Student objects from the user's inputs 2. for each Student object, obtain his quiz scores from the user's input 3. write aan instance method in the Student class to calculate and and return score average for each student. The followings are optionalfor advanced students: 4. create an intance method call equals to compare if two students have the same avage scores. 5. create a copy constructor so a new independent Student object can be created as clone of an existing ========================================================================= */
/* A class to keep each unique student with his 5 quiz scores */ class Student { private final int MAX_SCORES = 5; //used as max array size public static int id_gen = 1; //unique number generator private String name; private int id; //unique id private double[] scores; /** to be completed */ public Student(String name){ this.name = name; this.scores = new double[MAX_SCORES]; this.id = id_gen++; } /** to be completed */ public String toString(){ return " Name: " + this.name + " ID: " + this.id; } /** to be completed */ public double avgScore(){ return 0; ///dummy return } }
/** An in class illustration of classes, method, static fields and constants(final) */ public class StudentDriver{ /** this driver is used to test the Student class === to be completed === */ public static void main(String[] args){ Student[] students = new Student[5]; //create a few students students[0]= new Student("Ken"); students[1] = new Student("Jose"); //print the students out for(int i = 0; i < 2; i++){ System.out.println(students[i]); } //print out the unique id generator System.out.println("Current ID: " + Student.id_gen); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
