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
  • 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...

  • 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...

  • 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...

  • using if/switch statements (C++) Write a grading program for a class with the following grading policies:...

    using if/switch statements (C++) Write a grading program for a class with the following grading policies: There are two quizzes, each graded on the basis of 10 points There is one midterm exam and one final exam, each graded on the basis of 100 points The final exam counts for 50% of the grade, the midterm counts for 25% and the two quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores. They should...

  • In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName,...

    In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName, GPA (double), and Major. Extend your class for a Student to include classes for Graduate and Undergraduate. o Include a default constructor, a constructor that accepts the above information, and a method that prints out the contents FOR EACH LEVEL of the object, and a method that prints out the contents of the object. o Write a program that uses an array of Students...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • Write a program to calculate your final grade in this class. Three(8) assignments have yet to...

    Write a program to calculate your final grade in this class. Three(8) assignments have yet to be graded: Quiz 7, Lab 7 and Final Project. Assume ungraded items receive a grade of 100 points. Remember to drop the lowest two quiz scores. Display final numeric score and letter grade. Implementation: Weight distribution is listed in canvas. Use arrays for quizzes, labs, projects and exams. You are allowed to use initialization lists for arrays. Use at least three (3) programmer defined...

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
ADVERTISEMENT