Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago