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,...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current...
LANGUAGE: JAVA Create a New Project called YourLastNameDomainName. Write a DomainName class that encapsulates the concept...
LANGUAGE: JAVA Create a New Project called YourLastNameDomainName. Write a DomainName class that encapsulates the concept of a domain name, assuming a domain name has a single attribute: the domain name itself. Include the following: - Constructor: accepts the domain name as an argument. - getDomain: an accessor method for the domain name field. - setDomain: a mutator method for the domain name field. - prefix: a method returning whether or not the domain name starts with www. - extension:...
PUT IN JAVA PROGRAMMING LANGUAGE The Rectangle class: Design a class named Rectangle to represent a...
PUT IN JAVA PROGRAMMING LANGUAGE The Rectangle class: Design a class named Rectangle to represent a rectangle. The class contains: • Two double data fields named width and height that specify the width and height of a rectangle. The default values are 1 for both width and height. • A no-arg (default) constructor that creates a default rectangle. • A constructor that creates a rectangle with the specified width and height. • A method named findArea() that finds the area...
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...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT