Question: Part 1 : Student.java Define your Student class to meet the following criteria: 3 fields, all private: String name, double [ ] grades, and int

Part 1: Student.java
Define your Student class to meet the following criteria:
3 fields, all private: String name, double[] grades, and int year.
Non-default constructor that sets values for name, year, and grades.
A public non-static method getName(), which returns the students name.
A private non-static method calculateAverage() which uses a for loop over the students grades to determine and return their average. If the student has no grades (i.e. the length of the array is 0), return 0 as the average instead.
A public non-static method canGraduate() that returns true if the students year is 12 and their average is >=75(use calculateAverage()).
Depending on how you style your code, the length of this class will vary my version is just over 30 lines long, for comparisons sake. Theres not any majorly complicated logic in here, its just an exercise in creating a class.
Part 2: StudentDemo.java
StudentDemo should contain 3 methods. main(), makeStudent(), and graduateCheck(). This part of the lab is focused creating objects of a custom class, and utilizing methods to better organize your program and reduce repetition.
Start with graduateCheck(). It should be defined as public static void and it should accept a single Student object as parameter. All the method needs to do is print can graduate, congratulations! if their canGraduate() method returns true, otherwise print cant graduate, oh well.... Youll need to use getName() for each student here.
Next, do makeStudent(). It should be defined as public static and return a Student object. It should accept a Scanner object as parameter. Start by asking for the necessary information to create a Student their name and year first. Then, ask for how many grades they have, and create a double[] with that size. You can then use a for loop to fill up the array with grades entered by the user. After all that, return the new Student using the information given. Youll also need to flush the stream right before the return since the method ends with nextDouble() and starts with nextLine(). For the grade loop, it should look something like this:
for(int i =0; i < numOfGrades; ++i){
//ask for a grade to add to the array
//grades[i]= that new grade
}
Lastly, you have main(), which will serve as the main program flow. Create a Scanner object and ask for how many students there are. Use a for loop to get Student objects from makeStudent() and call graduateCheck() on each after. Youll need to flush the stream after asking for the number of students and before calling makeStudent the first time. Your for loop should look something like this:
for(int i =0; i < studentNum; ++i){
//retrieve a new student object from makeStudent
//call graduateCheck with that student
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!