Question

6. Analyzable Interface Modify the CourseGrades class you created in Programming Challenge 5 so it implements...

6. Analyzable Interface

Modify the CourseGrades class you created in Programming Challenge 5 so it implements

the following interface:

public interface Analyzable

{

double getAverage();

GradedActivity getHighest();

GradedActivity getLowest();

}

The getAverage method should return the average of the numeric scores stored in the

grades array. The getHighest method should return a reference to the element of the grades

array that has the highest numeric score. The getLowest method should return a reference

to the element of the grades array that has the lowest numeric score. Demonstrate the new

methods in a complete program.

Homework Answers

Answer #1

Here i am providing the answer. Hope it helps, please give me a like. it helps me a lot.

Program Code:

public class CourseGradeDemo

{

/*Main method to demonstrate the classes CourseGrade,

* GradedActivity, PassFailExam, Essay, FinalExam.

*/

// start main method

public static void main(String[] args)

{

GradedActivity lowest;

GradedActivity highest;

// create an object for the GradedActivity class

GradedActivity ga = new GradedActivity();

// set score of the GradedActivity

ga.setScore(80);

// create an object for the PassFailExam class

PassFailExam pfe = new PassFailExam(10, 3, 90);

// create an object for the Essay class

Essay e = new Essay(28, 19, 18, 30);

// create an object for the FinalExam class

FinalExam fe = new FinalExam(50, 12);

// create an object for the CourseGrades class

CourseGrades coursegrade = new CourseGrades();

/* call the "setLab" method with the

GradedActivity object */

coursegrade.setLab(ga);

/* call the "setPassFailExam" method with the

PassFailExam object */

coursegrade.setPassFailExam(pfe);

/* call the "setEssay " method with the Essay

object */

coursegrade.setEssay(e);

/* call the "setFinalExam " method with the

FinalExam object */

coursegrade.setFinalExam(fe);

// call the "toString" method of courseGrade

System.out.println(coursegrade);

System.out.println("\n");

double average;

average= coursegrade.getAverage();

System.out.println("Average of the scores is:\t"

+average);

System.out.println("Lowest of the scores is:\t" +coursegrade.getLowest().getScoreOf());

System.out.println("Highest of the scores is:\t" +coursegrade.getHighest().getScoreOf());

} // end of main method

} // end of CourseGradeDemo class

  1. //Create an Interface Analyzable

    public interface Analyzable

    {

    double getAverage();

    GradedActivity getHighest();

    GradedActivity getLowest();

    }

    Comments (1)

  2. Step 5 of 13

    //File: CourseGrades.java

    // CourseGrades class implementation

    public class CourseGrades implements Analyzable

    {

    //create an array grades of 4 GradedActivity objects

    private GradedActivity[] grades = new GradedActivity[4];

    // Method setLAb() which assigns the gradedActivity

    //to first array element

    /*

    * setLab method accepts a GradedActivity object as

    * a parameter and then stores this object in the

    * grades array as the 0th element.*/

    // setLab method implementation

    public void setLab(GradedActivity ga)

    {

    grades[0] = ga;

    } // end of setLab method

    // setPassFailExam() which assigns the GradedActivity

    //to second array element

    /*

    * The following setPassFailExam method accepts a

    * PassFailExam object as a parameter and then stores

    * this object in the grades array as the 1st

    * element.

    */

    // setPassFailExam method implementation

    public void setPassFailExam(PassFailExam fe)

    {

    grades[1] = fe;

    } // end of setPassFailExam method

    // Method setEssay() which assigns the gradedActivity

    //to third array element

    /*

    * The following setEssay method accepts an Essay

    * object as a parameter and then stores this object

    * in the grades array as the 2nd element.

    */

    // setEssay method implementation

    public void setEssay(Essay e)

    Comment

Step 6 of 13

{

grades[2] = e;

} // end of setEssay method

// Method setFinalExam() which assigns the

//gradedActivity to fourth array element

/*

* The following setFinalExam method accepts

* a FinalExam object as a parameter and then stores

* this object in the grades array as the 3rd

* element.

*/

// setFinalExam method implementation

public void setFinalExam(FinalExam fe)

{

grades[3] = fe;

} // end of setFinalExam method

// Method string() which calls all the methods and

//return the values

/* The following toString method returns a string

* representation of the numeric scores and grades of

* all elements in the grades array. */

// toString method implementation

public String toString()

{

return "Lab:\n" + " Score: "

+ grades[0].getScoreOf()

+ ", Grade: " + grades[0].getGradeOf()

+ "\n\nPassFailExam:\n" + " Score: "

+ grades[1].getScoreOf() + ", Grade: "

+ grades[1].getGradeOf()

+ "\n\nEssay:\n"

+ " Score: " + grades[2].getScoreOf()

+ ", Grade: " + grades[2].getGradeOf()

+ "\n\nFinalExam:\n" + " Score: "

+ grades[3].getScoreOf() + ", Grade: "

+ grades[3].getGradeOf();

} // end of toString method

/*

* The following getAverage method computes and returns the average score

* of all elements in the grades array.

*/

// getAverage method implementation

public double getAverage()

{

double total = 0;

for (int i = 0; i < grades.length; i++)

{

total += grades[i].getScoreOf();

}

double average = total / grades.length;

return average;

} // end of getAverage method

/* The following getHighest method finds and returns

* the reference to the element with the highest

* score in the grades array. */

// getHighest method implementation

public GradedActivity getHighest()

{

GradedActivity highest = grades[0];

for (int i = 0; i < grades.length; i++)

{

if (grades[i].getScoreOf() > highest

.getScoreOf())

highest = grades[i];

}

return highest;

} // end of getHighest method

/* The following getLowest method finds and returns

* the reference to the element with the lowest score

* in the grades array.*/

// getLowest method implementation

public GradedActivity getLowest()

{

GradedActivity lowest = grades[0];

for (int i = 0; i < grades.length; i++)

{

if (grades[i].getScoreOf() < lowest.getScoreOf())

lowest = grades[i];

}

return lowest;

} // end of getLowest method

} // end of CourseGrades class

/**********************************************************

* The Following GradedActivity class demonstrates *

* the numeric score and calculating lettergrade with *

* the corresponding numeric score values *

*********************************************************/

//File: GradedActivity.java

//Implemetation of GradedActivity Class

/*Class to demonstrate the numeric score and the letter

grade calculation*/

public class GradedActivity

{

//declaring the variable scoreValue

private double scoreValue;

//setter to set a value for the scoreValue

public void setScore(double s1)

{

//setting value

scoreValue = s1;

}

//getter to get score

public double getScoreOf()

{

//return statement

return scoreValue;

}

//getter to get grade

public char getGradeOf()

{

//variable declaration

char letterGrade;

//checking each scoreValue to get a letter grade

/*Calculating the letter grade by comparing score

values of each stage*/

if (scoreValue >= 90)

letterGrade = 'A';

else if (scoreValue >= 80)

letterGrade = 'B';

else if (scoreValue >= 70)

letterGrade = 'C';

else if (scoreValue >= 60)

letterGrade = 'D';

else

letterGrade = 'F';

//return statement

return letterGrade;

}

}

Comment

public class PassFailActivity extends GradedActivity

{

//Declare a variable for Minimum Passing Score

private double minPassScore;

public PassFailActivity(double mp)

{

minPassScore = mp;

}

@Override

public char getGradeOf()

{

char letterGrade;

if(super.getScoreOf()>=minPassScore)

letterGrade='P';

else

letterGrade='F';

return letterGrade;

}

}

//File: PassFailExam.java

//Implemetation of PassFailExam Class

public class PassFailExam extends PassFailActivity

{

// Number of questions

private int numOfQuestions;

// Points for each question

private double pointsOfEach;

// Number of questions missed

private int numOfMissed;

/*Constructor which is passing the parameters

Questions,missed, minpassing and that can be

assigned for the private data members which is

already declared above.*/

//parameterised constructor which is passing

//Questions, missed and minPassing

public PassFailExam(int questions, int missed,

double minPassing)

{

// Call the superclass constructor.

super(minPassing);

// Declare a local variable for the score.

double numericScoreValue;

// Set the numQuestions and numMissed fields.

numOfQuestions = questions;

numOfMissed = missed;

// Calculate the points for each question and

// the numeric score for this exam.

/*Calculating the points of each and numeric score value

* which can be subtracted with 100 and multiplied by the

* points of each*/

pointsOfEach = 100.0 / questions;

numericScoreValue = 100.0 - (missed *

pointsOfEach);

// Call the superclass's setScore method to

// set the numeric score.

setScore(numericScoreValue);

}

//Get method to get each points

public double getPointsOfEach()

{

//return statement

return pointsOfEach;

}

//Get method to get nummissed

public int getNumOfMissed()

{

//return statement

return numOfMissed;

}

}

public class FinalExam extends GradedActivity

{

// Number of questions

private int numOfQuestions;

// Points for each question

private double pointsOfEach;

// Questions missed

private int numOfMissed;

//Constructor for the class FinalExam

public FinalExam(int questions, int missed)

{

// To hold a numeric score

double numericScoreValue;

// Set the numQuestions and numMissed fields.

numOfQuestions = questions;

numOfMissed = missed;

/*Calculating the points of each and numeric

score value which can be subtracted with 100 and

multiplied by the points of each*/

// the numeric score for this exam.

pointsOfEach = 100.0 / questions;

numericScoreValue = 100.0 - (missed * pointsOfEach);

// Call the inherited setScore method to

// set the numeric score.

setScore(numericScoreValue);

}

//Get method to get each points

//Method to get points

public double getPointsOfEach()

{

//return statement

return pointsOfEach;

}

//Method which is getting the num of missed

//Get method to get nummissed

public int getNumOfMissed()

{

//return statement

return numOfMissed;

}

}

//File: Essay.java

// Essay class implementation

public class Essay extends GradedActivity

{

/* declare the variables to store the points for the

grammar, spelling, correct length, and content */

private int grammars;

private int spellings;

private int correctLengths;

private int contents;

/*Constructors which is passing the parameters egrammer,

* espelling, ecorrectlength and econtent */

// parameterized constructor

public Essay(int egrammar, int espelling,

int ecorrectLength, int econtent)

{

grammars = egrammar;

spellings = espelling;

correctLengths = ecorrectLength;

contents = econtent;

/*Summing the grammars, spelling, correct length

* and the contents*/

setScore(grammars + spellings + correctLengths

+ contents);

} // end of constructor

} // end of Essay class

Sample Output:

Lab:

Score: 80.0, Grade: B

PassFailExam:

Score: 70.0, Grade: F

Essay:

Score: 95.0, Grade: A

FinalExam:

Score: 76.0, Grade: C

The average of the scores is: 80.25

The lowest of the scores is: 70.0

The highest of the scores is: 95.0

Thank you. please like.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
10. Number Array Class Design a class that has an array of floating-point numbers. The constructor...
10. Number Array Class Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically allocate the array to hold that many numbers. The private data members of the class should include the integer argument in a variable to hold the size of the array and a pointer to float type to hold the address of the first element in the array. The destructor should free the memory held by the array....
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue class . Call your class Queue. it must be a template class. public class Queue { } I have put a driver program in the module . It is called CircularQueue.java This driver program should then run with your Queue class (no modifications allowed to the driver program). Your Queue class should have at least the following methods: one or more constructors, enqueue, dequeue,...
C# programming Assume we have a student final exam score lookup table like this: John 40...
C# programming Assume we have a student final exam score lookup table like this: John 40 Henry 0 Mary 59 Hillary 39 Pikachu 100 Write a class that helps check if student passes or fails the course. If a student's score is greater than or equal to a parameter passScore, we will consider it a pass. If a student's name is NOT found in the table, we assume they have missed the exam and thus consider failed. The method should...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and make a java program for your bank. However, there is another type of customer that may not have money in the bank and may not in fact have a back account with this bank at all, but may have a loan here. Make another class in the application you are making called CarLoan. Carloan's should have a name, amount owed, a rate, and a...
You are working for a company that is responsible for determining the winner of a prestigious...
You are working for a company that is responsible for determining the winner of a prestigious international event, Men’s Synchronized Swimming. Scoring is done by eleven (11) international judges. They each submit a score in the range from 0 to 100. The highest and lowest scores are not counted. The remaining nine (9) scores are averaged and the median value is also determined. The participating team with the highest average score wins. In case of a tie, the highest median...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...