Question

In Java Main method Your main program will prompt the user for a test name and...

In Java

Main method

Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade.

GradeBook Object

Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At some point (inside a constructor or some other method), call a user-created method called setLetterGrades( ) that will set the letter grades that corresponds to the scores arraylist.

*There are multiple ways to set this up. You pick. Again, ultimate freedom. Get used to it.

Verify that the GradeBook object has getter and setter methods for all instance variables. Also, include a default no-argument constructor.

Use the chart below to figure out the appropriate letter grade.

Score (Greater than or equal to)

Letter Grade

90

A

80

B

70

C

60

D

Less than 60

F

Get the values back into the main program and print everything out.

Your output should look something like the example on page 2, with the user selecting different numbers for the scores array each time the program is ran or using a sentinel value loop.

Sample run

How many scores would you like to enter? 5

Enter a score: 46

Enter a score: 64

Enter a score: 72

Enter a score: 86

Enter a score: 94

Score -------- Grade

46 --------   F

64 --------   D

72 --------   C

86 --------   B

94 --------   A

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Java code for the above question is given below:

import java.util.*;
/**
 * GradeBook Class
 */
public class GradeBook {
    /**
     * Data members of the class
     * testName -- it denotes the name of the test
     * letterGrades  --- arraylist which denotes the letter grades of the score
     * scores -----  arraylist which denotes the scores
     */
    private String testName;
    private ArrayList<Character> letterGrades;
    private ArrayList<Integer> scores;

    /**
     * Default constructor  
     */
    GradeBook() {
        testName = "sample test";
    }

    /**
     * Parameterized constructor
     * parameters : name of the test and arraylist of scores
     */
    GradeBook(String name, ArrayList<Integer> arr) {
        testName = name;
        scores = arr;
        letterGrades = calculateLetterGrades(arr); // method to convert the score to letterGrades 
    }

    /**
     * Method to convert the scores to the letterGrades
     * It returns an arrayList of characters storing the lettergrades
     */
    public ArrayList<Character> calculateLetterGrades(ArrayList<Integer> arr) {
        ArrayList<Character> grade = new ArrayList<Character>(arr.size());
        for(int i=0;i<arr.size();i++) {
            if(arr.get(i) >= 90)
                grade.add('A');
            else if(arr.get(i) >= 80)
                grade.add('B');
            else if (arr.get(i) >= 70)
                grade.add('C');
            else if (arr.get(i) >= 60)
                grade.add('D');
            else
                grade.add('F');
        }
        return grade;
    }
    /**
     * Getters and Setters
     */
    public String getTestName() {
        return testName;
    }
    public void setTestName(String testName) {
        this.testName = testName;
    }
    public ArrayList<Character> getLetterGrades() {
        return letterGrades;
    }
    public void setLetterGrades(ArrayList<Character> letterGrades) {
        this.letterGrades = letterGrades;
    }
    public ArrayList<Integer> getScores() {
        return scores;
    }
    public void setScores(ArrayList<Integer> scores) {
        this.scores = scores;
    }

    /**
     * Main Method 
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String testName;
        System.out.print("Enter Test Name : ");
        testName = scan.nextLine(); // input the test name
        int numberOfScores;
        System.out.print("How many scores would you like to enter? ");
        numberOfScores = scan.nextInt();  // input the number of scores
        ArrayList<Integer> arr = new ArrayList<Integer>(numberOfScores);
        for(int i=0;i<numberOfScores;i++) {
            System.out.print("Enter a Score: ");
            int score = scan.nextInt();  // input the scores
            arr.add(score);
        }
        GradeBook gradeBook = new GradeBook(testName, arr); // create an instance of GradeBook class
        ArrayList<Character> letterGrades = gradeBook.getLetterGrades(); // getting the letterGrades
        ArrayList<Integer> scores = gradeBook.getScores(); // getting the scores
        System.out.println("Score -------- Grade");
        for(int i=0;i<scores.size();i++) {
            System.out.println(scores.get(i) + " -------- " + letterGrades.get(i));
        }
    }
}

Sample Input and Output:

Screenshot of the code is given below:

If the answer helped please upvote, it means a lot and for any query please comment.

Add a comment
Know the answer?
Add Answer to:
In Java Main method Your main program will prompt the user for a test name and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • Create a C++ program to : Prompt user for seven test score Store the scores into...

    Create a C++ program to : Prompt user for seven test score Store the scores into an array Print the array before and after sorting Print the test average Convert the average to letter grade Search for a test score 90, using linear search Print, if test score 90 was found and at what position Add Comments SEPARATE THE FILES INTO 3 : header.h, functions.cpp, main.cpp

  • Write a program called printGPA. The program should contain at least 3 methods: main, gradeAverage, and...

    Write a program called printGPA. The program should contain at least 3 methods: main, gradeAverage, and letterGrade. The user will type a line of input containing the student's name, then a number that represents the number of scores, followed by that many integer scores (user input is in bold below). The data type used for the input should be one of the primitive integer data types. Here are two example dialogues: Enter a student record: Maria 5 72 91 84...

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Score Letter Grade...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Look at this partial class definition, and then answer questions a - b below: Class Book...

    Look at this partial class definition, and then answer questions a - b below: Class Book    Private String title    Private String author    Private String publisher    Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant    Public Module message()       Display "I'm a plant."    End Module...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write a test program that prompt the user to enter seven numbers, stores them in an...

    Write a test program that prompt the user to enter seven numbers, stores them in an array list and do the following: 1. Displays its elements (numbers) in increasing order by invoking a method with the following header that sorts the array: public static void sort(ArrayList<Integer>list) 2. Write a method that returns and displays the sum of all numbers (elements) of the ArrayList. Using the following header: public static double sum(ArrayList<Integer>list) 3. Write a method that removes the duplicate numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT