Question

In Java, write a class Grade with following member variables and method: int midtermExam, int finalExam:...

In Java, write a class Grade with following member variables and method:

int midtermExam, int finalExam: represent the scores of midterm and final exams respectively. The maximum score for each exam is 100.

double getOverallScore(): returns the overall score calculated as follows: 40% midterm and 60% final.

Write another class Grade180 that is a subclass of Grade and has the following member variables and method:

int midtermExam, int finalExam: inherited from Grade super class.

int hw1, int hw2, int project1, int project2 : represent the scores of homeworks, projects respectively. The maximum score for each homework and project is 100.

double getOverallScore(): overrides the method in Grade class and returns the overall score calculated as follows: 20% homeworks (each of equal weight), 30% projects (each of equal weight), 20% midterm and 30% final.

Note: data for member variables should be passed as arguments to their respective constructors and initialized in them.

You may use your main method for testing, but it will not be tested by webcat.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Code Modified

//Changes are in bold
//Grade clas that sets constrctor with midterm score
//and final exam score and calculate the getOverallScore.
//Grade.java
public class Grade
{
   private int midtermExam;
   private int finalExam;

   public Grade(int midtermExam, int finalExam)
   {
       this.midtermExam=midtermExam;
       this.finalExam=finalExam;
   }
   //returns the overall score calculated as follows: 40% midterm and 60% final.
   public double getOverallScore()
   {
       return midtermExam*(0.40)+finalExam*(0.60);
   }


   //returns the midtermExam  
   public int getMidTermExam()
   {
       return midtermExam;
   }

   //returns the midtermExam  
   public int getFinalExam()
   {
       return finalExam;
   }


}

-----------------------------------------------------------------------------------------------------------------------------


//Grade180.java that extends the super class Grade.
public class Grade180 extends Grade
{
//instance variabels of class Grade180
   private int hw1;
   private int hw2;
   private int project1;
   private int project2;
  
   //constructor that sets the mid term exam, final exam
   //home work1 and home work2 and project1 and project2 scores
   public Grade180(int midtermExam, int finalExam,
           int hw1, int hw2, int project1, int project2)
   {
       super(midtermExam, finalExam);  
       this.hw1=hw1;
       this.hw2=hw2;
       this.project1=project1;
       this.project2=project2;
   }
  
  
   //getter methods  
   public int getHw1()
   {
       return hw1;
   }
   public int getHw2()
   {
       return hw2;
   }
   public int getProject1()
   {
       return project1;
   }
   public int getProject2()
   {
       return project2;
   }
  
  
   // overrides the method in Grade class and returns the overall score
   //calculated as follows:
   //20% homeworks (each of equal weight means each of 10 percent (0.10))
   //30% projects (each of equal weight means each of 15 percent (0.15))
   //20% midterm and 30% final.
   //10(hw1)+10(hw2)+15(project1)+15(project2)+20(midterm )+30(final)=100 %
   @Override
   public double getOverallScore()
   {      
       //hw1 and hw2 each of equal weight is 10(0.10)% of 20%
       //projec1 and project2 each of equal weight is 15(0.15) % of 30%
       return hw1*(0.10)+hw1*(0.10)+project1*(0.15)+project2*(0.15)+
               getMidTermExam()*(0.20)+getFinalExam()*(0.30);
   }
  

  
}

---------------------------------------------------------------------------------------------------


public class TesterProgram
{
   public static void main(String[] args)
   {
      
       int midtermExam=50;
       int finalExam=50;
      
       int hw1=40;
       int hw2=40;
      
       int project1=80;
       int project2=80;
      
       //Create an instance of Grade180 class
       Grade180 grade180=new Grade180(midtermExam, finalExam, hw1, hw2, project1, project2);
      
       //print scores
       System.out.println("Home Work1 : "+grade180.getHw1());
       System.out.println("Home Work2 : "+grade180.getHw2());
       System.out.println("Project 1 : "+grade180.getProject1());
       System.out.println("Project 2 : "+grade180.getProject2());
       //calling getMidterExam score
       System.out.println("Mid term Score : "+grade180.getMidTermExam());
       //Calling final score
       System.out.println("Final score : "+grade180.getFinalExam());
       //calling getOverallScore
       System.out.println("Overall Score : "+grade180.getOverallScore());
      
   }
}


--------------------------------------------------------------------------------------------------------------------------------------------

Home Work1 : 40
Home Work2 : 40
Project 1 : 80
Project 2 : 80
Mid term Score : 50
Final score : 50
Overall Score : 57.0

Hope this helps you...

Add a comment
Know the answer?
Add Answer to:
In Java, write a class Grade with following member variables and method: int midtermExam, int finalExam:...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

  • Java Program 1. Write a class that reads in a group of test scores (positive integers...

    Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • C++ 8. Circle Class Write a Circle class that has the following member variables: • radius:...

    C++ 8. Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...

  • Question 3 alues, and a get method for each of the member variables. The class implements...

    Question 3 alues, and a get method for each of the member variables. The class implements the ne member variables to the given Comparable interface, and compares two candidates based on their numbers of votes. 2. Designing a class named VotingMachine that contains a collection of candidates and the following methods: . addCandidate (String name): Add a candidate of a given name to the collection of candidates. This method throws an exception if a candidate of the given name already...

  • C++ Write a program to calculate final grade in this class, for the scores given below...

    C++ Write a program to calculate final grade in this class, for the scores given below . Remember to exclude one lowest quiz score out of the 4 while initializing the array. Display final numeric score and letter grade. Use standard include <iostream> Implementation: Use arrays for quizzes, labs, projects and exams. Follow Sample Output for formatting. May use initialization lists for arrays. Weight distribution is as follows: Labs: 15% Projects: 20% Quizzes: 20% Exams: 25% Final Project: 20% Display...

  • For java class Assume a Student class has two variables: Name and Grade. Write an example...

    For java class Assume a Student class has two variables: Name and Grade. Write an example of a get method and a set method for each of the two variables

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Write a Java object class Cat with the member variables (fields) color, breed, birthday, and weight....

    Write a Java object class Cat with the member variables (fields) color, breed, birthday, and weight. Create an empty constructor and overload that constructor and have it accept values for each member variable. There should be manipulator (setter) and accessor (getter) methods for each member variable. Ensure the Cat object has a toString() method. The accessor method for the birthday should return the date in the format MM/DD/YYYY. Add an accessor method getAgeInYears() that calculates how many years old the...

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT