Question

In: Computer Science

program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...

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%)

Solutions

Expert Solution

////////////////////////////////////////////////////


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);
   }
  
}
//////////////////////////////////////


Related Solutions

Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
In Java Write a program that allows Professor Poindexter to get class averages including the average...
In Java Write a program that allows Professor Poindexter to get class averages including the average for allher/his classes. Professor Poindexter has M classes. M will be input from the terminal. For each class he/she will input each student’s grade for that class until 0 is input. Once the goof prof inputs 0, The class average for that class is output in the form:   Average for Class X 1 is XXX.XX Finally, once all the M class data is input,...
In this question, you are asked to write a simple java program to understand natural language....
In this question, you are asked to write a simple java program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Robin came to Montreal, Canada in 2009. Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT