Question

In: Computer Science

I asked this question before, but I'm wondering if there are any other ways to do...

I asked this question before, but I'm wondering if there are any other ways to do this problem. My exam will be similar to this, so I'm looking for more examples to study with. Thank you!

For this Java program, you will write two classes: GradeCalculator and GradeCalculatorDriver.

In the GradeCalculator class, compute the final average and letter grade for a particular student.

The final average is calculated according to the following rules:

1) There are ten exams scored out of 100 points

2) The lowest exam score is not included in the calculation of the final average

3) The highest exam score is not included in the calculation of the final average

4) An average of 91-100 is an A

5) An average of 81-90 is a B

6) An average of 71-80 is a C

7) An average of 61-70 is a D

8) An average of 0-60 is an E

The GradeCalculator class must include the following methods:

1) A method to compute and return the highest score

2) A method to compute and return the lowest score

3) A method to compute the sum of all the scores

4) A method to compute the final average

5) A method to determine the letter grade

In the GradeCalculatorDriver class, include a main method that asks the user for the student’s name and their ten exam grades, reads the grades, calculates the letter grade and prints it. This process should be repeated until the user enters N.

For example, a run of the program might look something like this:

Welcome to Score Calculator

Want to compute a final average? Y

Please enter the student’s name: Sara Smith

Please enter test scores all on one line separated by one or more spaces.

The final score for Sara Smith is 100.

The letter grade for Sara Smith is A.

Want to compute another final average? N

Solutions

Expert Solution

Paste both classes in same package

Code:-

GradeCalculator class


public class GradeCalculator {
   public double highest_score(double arr[])
   {
       /*
       * to compute highest score
       */
       double max=arr[0];
       for(int i=0;i<arr.length;i++)
       {
           if(max<arr[i])
           {
               max=arr[i];
           }
       }
       return max;
   }
  
   public double lowest_score(double arr[])
   {
       /*
       * to compute lowest score
       */
       double min=arr[0];
       for(int i=0;i<arr.length;i++)
       {
           if(min>arr[i])
           {
               min=arr[i];
           }
       }
       return min;
   }
   public double sum(double arr[])
   {
       /*
       * to compute sum of scores
       */
       double sum=0;
       for(int i=0;i<arr.length;i++)
       {
           sum=sum+arr[i];
       }
       return sum;
   }
   public double final_average(double arr[])
   {
       /*
       * to compute final average by subtracting lowest and highest score from sum
       * and finding the average
       */
       double average=0;
       average=(sum(arr)-highest_score(arr)-lowest_score(arr))/(arr.length-2);
       return average;
   }
   public char letter_grade(double final_score)
   {
       /*
       * computing the grade based on the final score
       */
       if(0<=final_score && final_score<=60)
       {
           return 'E';
       }
       else if(61<=final_score && final_score<=70)
       {
           return 'D';
       }
       else if(71<=final_score && final_score<=80)
       {
           return 'C';
       }
       else if(81<=final_score && final_score<=90)
       {
           return 'B';
       }
       else if(91<=final_score && final_score<=100)
       {
           return 'A';
       }
       return 0;
   }
}

GradeCalculator class Snippet:

GradeCalculatorDriver class

import java.util.Scanner;
public class GradeCalculatorDriver {
public static void main(String[] args) {
   char ans,grade;
   String name="";
   int final_score;
   GradeCalculator obj=new GradeCalculator();
   //Gradecalculator object
   double arr[]=new double[10];
   System.out.println("Welcome to Score Calculator");
   System.out.print("Want to compute a final average?");
   Scanner sc=new Scanner(System.in);
   ans=sc.next().charAt(0);
   sc.nextLine();
   if(ans=='N')
   {
       System.exit(0);
   }else
   { do
       {
           System.out.print("Please enter the student’s name:");
           name=sc.nextLine();
           System.out.println("Please enter test scores all on one line separated by one or more spaces.");
           for(int i=0;i<10;i++)
           {
               arr[i]=sc.nextDouble();
           }
           final_score=(int) obj.final_average(arr);
           /*
           * calling method final score from GradeCalculator class to
           * compute finalscore
           */
           System.out.println("The final score for "+name+" is "+final_score);
           grade=obj.letter_grade(final_score);
           /*
           * pass finalscore to find out grade
           */
           System.out.println("The final grade for "+name+" is "+grade);
           System.out.print("Want to compute another final average?");
           ans=sc.next().charAt(0);
           sc.nextLine();
       }while(ans=='Y' || ans=='y');
   }}}

GradeCalculatorDriver class Snippet:

OUTPUT


Related Solutions

Hi, I'm currently doing an accounting case and I was wondering about this following statement: "On...
Hi, I'm currently doing an accounting case and I was wondering about this following statement: "On a tour of CEM's manufacturing facility, I noticed that their facilities have good security with cameras installed that have a view of all of the areas where inventory is stored. THere is a large holding area with various parts, nuts, bolts, and wire coils, etc. THe chief financial officer indicated that CEM keeps these leftover parts and supplies from finished construction projects in inventory...
I have a question pertaining to ruby on rails. I was wondering if there is a...
I have a question pertaining to ruby on rails. I was wondering if there is a way to set aspect ratios for different monitor sizes for images used on a page. Thanks for any help.
I have asked this question before however I am not getting the right answer. What is...
I have asked this question before however I am not getting the right answer. What is the evolutionary advantage to having the conduction velocity of neural impulses change with temperature, and which of the five major groups of vertebrate organisms might benefit most from this phenomenon? Explain thoroughly please.
Hello there, I'm wondering can you do this problem without arrays? Using the given code on...
Hello there, I'm wondering can you do this problem without arrays? Using the given code on C++ Platform. Let me know ASAP. #include <iostream> #include <time.h> using namespace std; void shoot(bool &targetAlive, double accuracy) { double random = (rand() % 1000) / 1000.; targetAlive = !(random < accuracy); } int startDuel(int initialTurn) { bool personAlive[3] = {true, true, true}; double accuracy[3] = {0.333, 0.5, 1.0}; int turn = initialTurn; // which person has to shoot, initialTurn represents the first person...
What do I really need to study before studying ANOVA? I'm very behind in stats but...
What do I really need to study before studying ANOVA? I'm very behind in stats but I have a test coming up on Single factor ANOVA, Randomised Blocks, Two Way ANOVA and Tests for normality. It's for a 2nd year course in Applied Statistics, I want to study but I don't know what I should revise first, confidence intervals? all of hypothesis tests? Apparently most of the work can be done on excel but I still need to understand the...
Do you think that there are any other good ways to maintain a positive classroom atmosphere?
Do you think that there are any other good ways to maintain a positive classroom atmosphere?
I have done a fcff in excel and i was wondering how do i preform a...
I have done a fcff in excel and i was wondering how do i preform a sensitivity analysis with it. I did the FCFF but need help with the sensitivity analysis. Here is the question: You are thinking of investing $1000 in a machine today. It would be used to produce sales for 10 years. The projected sales number in year 1 is 1200, after which sales will grow at 2% annually. Cost of manufacturing for this project is 50%...
I was wondering if I could get a step by step process to answer this question?
I was wondering if I could get a step by step process to answer this question?
This is Cost Accounting, I asked this question before, and when according to my professor some...
This is Cost Accounting, I asked this question before, and when according to my professor some of the answers were not correct, can you help me with this question please, thanks Decision Making – Equipment Replacement Mathews manages an assembly facility of Orthom Scientific. A supplier approaches Mathews about replacing a large piece of manufacturing equipment that Orthom uses in its process with a more efficient model. While the supplier made some compelling arguments in favor of replacing the 3-year-old...
Question 1: In at least 150 words, in what ways if any, do the value of...
Question 1: In at least 150 words, in what ways if any, do the value of spirituality demonstrate your commitment to helping others grow and building community at your school? Be specific (at least 150 words)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT