Answer to Question #328255 in Java | JSP | JSF for Claire

Question #328255

Create an OOP Java program that will ASK the user for the Prelim, Midterm, Prefinal, and Finals grades. Calculate for the FINAL GRADE (follow the calculation instructions below). Display the final grade on the console.





Calculation for Final Grade:



Get the 20% of the Prelim Grade.



Get the 20% of the Midterm Grade.



Get the 20% of the Prefinal Grade.



Get the 40% of the Finals Grade.



Add all four results. This will be the Final Grade.







1. Create two (2) classes: MyMainClass and SecondClass.




2.The class SecondClass has 5 double attributes: prelim, midterm, prefinal, finals.




3.Create one (1) constructor method to set the prelim, midterm, prefinal, and finals grades.




4.Create one (1) accessor method to calculate for and return the final grade output.




Display the final grade output in the MyMainClass.





Sample output:



Enter prelim grade:75



Enter the midterm grade: 80



Enter the prefinal grade: 90



Enter the final grade: 91



Your final grade is 85.4

1
Expert's answer
2022-04-13T09:18:41-0400


import java.util.*;


class SecondClass {
	private double prelim, midterm, prefinal, finals;


	public SecondClass(double prelim, double midterm, double prefinal, double finals) {
		this.prelim = prelim;
		this.midterm = midterm;
		this.prefinal = prefinal;
		this.finals = finals;
	}


	/***
	 * Get the 20% of the Prelim Grade. Get the 20% of the Midterm Grade Get the 20%
	 * of the Prefinal Grade. Get the 40% of the Finals Grade.
	 * 
	 * @return
	 */
	public double calculateFinalGrade() {
		return this.prelim * 0.2 + this.midterm * 0.2 + this.prefinal * 0.2 + this.finals * 0.4;
	}
}


class MyMainClass  {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);


		System.out.print("Enter prelim grade: ");
		double prelim = keyboard.nextDouble();
		System.out.print("Enter the midterm grade: ");
		double midterm = keyboard.nextDouble();
		System.out.print("Enter the prefinal grade: ");
		double prefinal = keyboard.nextDouble();
		System.out.print("Enter the final grade: ");
		double finals = keyboard.nextDouble();
		SecondClass secondClass = new SecondClass(prelim, midterm, prefinal, finals);


		System.out.printf("Your final grade is %.1f", secondClass.calculateFinalGrade());


		keyboard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS