Question
Grading It is time to help your instructor with all them grades. To do this, you want to code three public static methods: 1. A
Grading
It is time to help your instructor with all them grades. To do this, you want to code three public static methods:
1. A getScaledScore method: This method takes two parameters: and integer parameter and a Scanner parameter. The integer parameter represents the maximum number of points for an assignment (used for scaling purposes). The Scanner parameter (see below for more information) is used to prompt the instructor to enter a student's score, which will be an integer. The entered score is then scaled to an integer score in the 0 to 100 range (i.e., the percentage is calculated), and the integer scaled score returned. A few rules:
- Negative scaled scores are set to 0
- Scaled scores above 100 are set to 100
- If the scaling process yields a number that is not an integer, that number is rounded up. For example, if the method argument is 700 (= max possible points) and the instructor enters 626, the raw scaled score is 89.4286, which must be rounded UP to 90. Hint: To round a number up, you can use the Math.ceil() method but be careful; this method returns a double.
2. A calculateGrade method: This method takes an integer parameter, which represents a scaled score, or equivalently a percentage from 1 to 100, and returns a character, which represents the corresponding letter grade based on A >= 90 B >= 80 C >= 70 D >= 60 F < 60
3. A getGrade method, which combines the above two methods. The getGrade method has two parameters: the first is an integer representing the maximum possible points for the exam/assignment. The second is a Scanner instance. The method prompts the instructor to enter a student's score, and it returns the corresponding letter grade.
Examples
Max Points | Entered Score (prompt) | Scaled Score (percentage) | Letter Grade |
---|---|---|---|
60 | 47 | 79 | C |
25 | 13 | 52 | F |
50 | 55 | 100 | A |
Main method example
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println(getScaledScore(60, scan)); System.out.println("Grade is " + getGrade(25, scan)); // This calls getScaledScore internally scan.close(); }
Hints:
- Watch out for integer division.
- Both the getScaledScore and getGrade methods should prompt the user to enter a score using their parameter Scanner instance
Discussion
Why is a Scanner passed as a parameter to the getScaledScore method?
This is to enable us to close the Scanner only when we are done with possibly multiple calls to the getScaledScore method. If the Scanner were instantiated within the getScaledScore method, it could only be closed within the same method. Unfortunately, once a Scanner is closed, so is System.in, and it CANNOT BE REOPENED. So, if you instantiate the Scanner inside getScaledScore and close it when the method is done, you can only call the method once. Subsequent attempt at calling the method in the same program (as done in the example just above) will error out. An alternative would be to instantiate the Scanner inside the getScaledScore method and "forget" to close it therein, but this is not a good practice.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started