In: Computer Science
program language: JAVA
For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the following methods in your WeightedCourseGrade class: Default constructor Constructor that takes both a category's weight (as a double between 0.0 and 1.0) and that category's grade (as a double between 0.0 and 1.0) (in that order). This constructor should 1) set the weighted subtotal to the category weight times the category grade and 2) set the total category weight to the category weight that was passed to this method. getCategoryWeightsTotal() returns the total category weights as a double getWeightedSubtotal() returns the weighted subtotal as a double addCategoryGrade() takes a category weight (as a double) and a category grade (as a double) and adds the weight to the total category weight field and multiples the two parameters and adds that to the weighted subtotal field getCurrentGrade() returns the weighted subtotal grade divided by the total category weights (as a double) Your WeightedCourseGradeDriver class should create a WeightedCourseGrade object to keep track of the users input. It repeatedly prompts the user for a category weight (between 0.0 and 1.0). If the weight is negative, it stops asking the user for input and displays the current grade (rounded to 3 decimal places). Otherwise, it requests the grade for that category (again, as a ratio, so 0.0 and 1.0). Furthermore, while the grade entered is negative or above 1.0, it prompts the user for a valid grade. If the category weights sum to 1.0 (really within 0.001 of 1.0), it stops asking the user for input and displays the current grade (rounded to 3 decimal places). Otherwise, it prompts the user for another category weight. Do not keep track of the total category weights entered in your WeightedCourseGradeDriver class. Instead, make the appropriate method call using the WeightedCourseGrade object. Each of the methods (which includes the two constructors) in your WeightedCourseGrade class will be tested using unit tests. Additionally, the output of your entire program will be tested with various inputs.
Example 1 Welcome to the Weighted Course Grade Calculator!
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.14
Please enter the category grade (0.0..1.0): 0.24
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.1
Please enter the category grade (0.0..1.0): 0.442
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.23
Please enter the category grade (0.0..1.0): -0.325
Please enter the category grade (0.0..1.0): -0.523
Please enter the category grade (0.0..1.0): -0.235
Please enter the category grade (0.0..1.0): 0.41
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.14
Please enter the category grade (0.0..1.0): 0.354
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.02
Please enter the category grade (0.0..1.0): 0.968
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.19
Please enter the category grade (0.0..1.0): 0.368
Please enter a category weight (0.0..1.0) (or a negative number to stop): -8.0
The current grade is 0.379 (37.9%)
Example 2 Welcome to the Weighted Course Grade Calculator!
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.50
Please enter the category grade (0.0..1.0): 0.90
Please enter a category weight (0.0..1.0) (or a negative number to stop): 0.50
Please enter the category grade (0.0..1.0): 0.80
The current grade is 0.85 (85.0%)
////////////////////////////////////////////////////
public class WeightedCourseGrade {
private double wSubTotal;// to store sub total
private double tcategoryWeight;// to store total
weight
// constructor
public WeightedCourseGrade(double a,double b){
this.wSubTotal=a*b;
this.tcategoryWeight=a;
}
// setter methods
public void setWeightedSubTotal(double
a){this.wSubTotal=a;}
public void setTotalCategoryWeight(double
b){this.tcategoryWeight=b;}
// getter methods
public double
getWeightedSubTotal(){return(this.wSubTotal);}
public double
setCategoryWeightsTotal(){return(this.tcategoryWeight);}
// add weight and corresponding grade
public void addCategoryGrade(double a,double b){
this.tcategoryWeight+=a;
this.wSubTotal+=a*b;
}
// get current grade
public double getCurrentGrade(){
return(this.wSubTotal/this.tcategoryWeight);
}
}
//////////////////////////////////////////////////////////////
public class WeightedCourseGrade {
private double wSubTotal;// to store sub total
private double tcategoryWeight;// to store total
weight
// constructor
public WeightedCourseGrade(double a,double b){
this.wSubTotal=a*b;
this.tcategoryWeight=a;
}
// setter methods
public void setWeightedSubTotal(double
a){this.wSubTotal=a;}
public void setTotalCategoryWeight(double
b){this.tcategoryWeight=b;}
// getter methods
public double
getWeightedSubTotal(){return(this.wSubTotal);}
public double
setCategoryWeightsTotal(){return(this.tcategoryWeight);}
// add weight and corresponding grade
public void addCategoryGrade(double a,double b){
this.tcategoryWeight+=a;
this.wSubTotal+=a*b;
}
// get current grade
public double getCurrentGrade(){
return(this.wSubTotal/this.tcategoryWeight);
}
}
//////////////////////////////////////