Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we are going to review some of the concepts of OOP .. Well create an interface, a super class, a subclass, and test it with

we are going to review some of the concepts of OOP .. Well create an interface, a super class, a subclass, and test it with an application.

StudentInterface.java (interface)

Create an interface, StudentInterface with the following methods:

String getName(); int getId(); double getAvgGrade(); boolean addScore( int grade );

Also create a constant, INIT_NUM_GRADES set to 5.

Student.java (super class)

Create Student.java which will implement the StudentInterface. This class will have the following protected fields:

ID

Name

Array of integer test scores. This array will initially store INIT_NUM_GRADES. If the array fills up, the method addScore() will create a new array that is double the length, copy the existing grades, and then set this reference to the new array.

An index to the location of where the next score will be stored in the array defined above.

The next ID to use for a new student. This is a static variable and is incremented after each new student is created.

In addition to implementing the StudentInterface, the Student should have the following methods:

A one argument constructor with the name. The ID will be set to the static next ID and that variable will be incremented. Create the array of 5 integer test scores.

A two argument constructor with the name and ID. If the specified ID is greater than the next ID, set next ID to the specified ID plus one. Create the array test scores.

A static method to display the toString() message headers. This method is defined below.

A toString() method, which matches the data defined within the getHdr method: name, id, average test score, list of all tests.

public static String getHdr() { return String.format("%15s %3s %6s %6s",

"name", "id", "tests", "scores"); }

GradStudent.java (subclass)

GradStudent will inherit everything from Student. In addition, a GradStudent has an additional essayScore (double) field.

Add the following method:

Add 2 constructors, which will call the super classs constructor (with super(....) ).

Override the getAvgGrade() method with the following weighted average: essayScore * 25% + averageTestScore * 75%. Call the super classs getAvgGrade() with a reference to super: super.getAvgGrade(). If the essayScore was not set (equal to 0), count the 100% of the averageTestScore. If no testScores have been added (average = 0), use 100% of essayScore. Note to get the testScore grade, call the super classs method:

double tests = super.getAvgGrade();

Add a mutator to set the essayScore: void setEssayScore( int score )

Add a static method to print the header for the toString(), shown below.

Add the corresponding toString() method to display the name, ID, essayScore, average test score, overall grade (call getAvgGrade()), and list all the test scores.

public static String getHdr() { return String.format("%15s %3s %6s %6s %6s %6s",

"name", "id", "essay", "tests",

"grade", "scores"); }

School.java (application) you do not need to modify this file

School is the application and creates an array of Students and GradStudents. The grades for each student are populated with random values. The array is then traversed and each Student is display by calling the toString().

Question: Why can we populate the array with both Students and GradStudents?

A sample run of School

name id tests scores

Mary Smith 1 80.3 75, 79, 78, 84, 87, 70, 84, 85,

Sam Adams 2 72.0 41, 41, 41, 100, 96, 101, 84,

Bill Butcher 3 74.6 75, 78, 71, 76, 75, 72, 74, 75, 75,

Sue Thomas 4 86.6 76, 81, 84, 97, 94, 86, 98, 77,

Sarah Billings 5 78.8 111, 84, 53, 63, 76, 86,

name id essay tests grade scores

Bob Jones 6 84 87.6 86.7 79, 87, 99, 89, 84,

Mary Parker 7 84 74.5 76.9 77, 67, 81, 71, 85, 72, 75, 68,

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 Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

What are your expectations of new employees?

Answered: 1 week ago

Question

1. Explain how business strategy affects HR strategy.

Answered: 1 week ago