Question: Based on the code below use a word processor to create a class diagram for it. Code: import java.util.Scanner; public class PlanetTesterV3 { public static
Based on the code below use a word processor to create a class diagram for it.
Code:
import java.util.Scanner;
public class PlanetTesterV3 {
public static void main(String[] args) {
// declare variable
int grade1 = 85;
int grade2 = 92;
// create student object and pass the grade the value
StudentV3 obj1 = new StudentV3(grade1, grade2);
// calculate the average and difference
double average = obj1.calculateAverage();
int difference = obj1.calculateDifference();
// display the value
System.out.println("\t\t\tGrades:");
System.out.println("Grade1\t\tGrade2\t\tAverage\t\tDifference");
System.out.println("==========================================================");
System.out.print(grade1 + "\t\t" + grade2 + "\t\t" + average + "\t\t" + difference);
}
}
//create a class
class StudentV3 {
// declare private variable
private double grade1;
private double grade2;
// set the constructor
public StudentV3(double g1, double g2) {
this.grade1 = g1;
this.grade2 = g2;
}
// calculate the average of grade
public double calculateAverage() {
return (grade1 + grade2) / 2;
}
// calculate the grade difference
public int calculateDifference() {
if (grade1 > grade2)
return (int) (grade1 - grade2);
else
return (int) (grade2 - grade1);
}
}
sample output:
Grades:
Grade1 Grade2 Average Difference
===========================================
85 92 88.5 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
