Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(THIS IS A JAVA ASSIGNMENT, THE GRADE DISTRIBUTION FILE AND GRADES GRAPH TEST IS PASTED BELOW) This homework is based on Project 3 on page

(THIS IS A JAVA ASSIGNMENT, THE GRADE DISTRIBUTION FILE AND GRADES GRAPH TEST IS PASTED BELOW)

This homework is based on Project 3 on page 372. Create a class that represents a grade distribution for a given course.

Download the attached GradeDistribution.txt, rename it to GradeDistribution.java

Complete the class definition by

Determine the needed instance variables

Define the set methods for each of the letter grades A, B, C, D, and F.

setAcount() setBcount() setCcount() setDcount()

setFcount()

Note: a set method should (1) have return type void (2) take a parameter for the new value of the instance variable. (3) assign the value of the instance variable to be the given parameter.

Define get method for each of the letter grades A, B, C, D, and F.

getAcount() getBcount() getCcount() getDcount()

getFcount()

Note: a get method should (1) takes no parameter (2) returns the value of an instance variable (3) the return type should be the type of the instance variable.

Define the following method which returns the total number of grades.

total number of grades is the sum of all grades. You don't need to define it as an instance variable, however if you choose to define it as instance variable, you have to make sure it is always the sum of all grades at any time, no matter where the user call the function or not.

Method that returns the percentage of each letter grade as a whole number between 0 and 100, inclusive.

getPercentA () getPercentB() getPercentC() getPercentD() getPercentF()

Draw a bar graph of the grade distribution.

draw() For example, if the grades are 1 A, 4 Bs, 6 Cs, 2 Ds, and 1 F, the total number of grades is 14, the percentage of As is 7, the percentage of Bs is 29, the percentage of Cs is 43, the percentage of Ds is 14, and the percentage of Fs is 7. The A row would contain 4 asterisks (7 percent of 50 rounded to the nearest integer), the B row 14, the C row 21, the D row 7, and the F row 4. The graph would look like this:

test the class:

download the GradesGraphTest.java, compile and run

compare the output with the attached sample output, debug your code if it doesnt look right.

GRADE DISTRIBUTION FILE:

import java.util.*; public class GradesDistribution { /* instance variables * / /** set methods to modify the data members */ /** get Methods to return values of data members */ /** Method to return total number of grades */ /** Methods to return percentages of each grade */ /** Method to graph grade counts by printing lines of asterisks */ public void draw() { } /** Methods to write (display) data members */ public void writeOutput() { System.out.println("Number of A's = " + Acount); System.out.println("Number of B's = " + Bcount); System.out.println("Number of C's = " + Ccount); System.out.println("Number of D's = " + Dcount); System.out.println("Number of F's = " + Fcount); } }
GRADES GRAPH FILE: 
/** File name: GradesGraphTest.java GradesGraphTest is a program to test GradesDistribution class. */ public class GradesGraphTest { public static void main(String[] args) { GradesDistribution grades = new GradesDistribution(); System.out.println("======Default constructor set all counts to be 0 ========================"); grades.writeOutput(); System.out.println(); grades.draw(); System.out.println(); System.out.println("=======change number of A, B, F to be 4, 6, 2 respectively =============="); grades.setAcount(4); grades.setBcount(6); grades.setFcount(2); grades.writeOutput(); System.out.println(); System.out.println("Total number of grades = "+ grades.getTotalNumberOfGrades()); System.out.println(); grades.draw(); System.out.println(); System.out.println("=======change number of B, C, D to be 4, 6, 2 respectively =============="); grades.setBcount(4); grades.setCcount(6); grades.setDcount(2); grades.writeOutput(); System.out.println(); System.out.println("Total number of grades = "+ grades.getTotalNumberOfGrades()); System.out.println(); System.out.println("check the percentage"); System.out.println("Percent of A = " + grades.getPercentA()); System.out.println("Percent of B = " + grades.getPercentB()); System.out.println("Percent of C = " + grades.getPercentC()); System.out.println("Percent of D = " + grades.getPercentD()); System.out.println("Percent of F = " + grades.getPercentF()); System.out.println(); System.out.println("==============================="); grades.draw(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5x-2y=2 line other than the y-int er'cept

Answered: 1 week ago