Question

In: Computer Science

Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...

Java program.

Need to create a class names gradesgraph which will represent the GradesGraphtest program.

Assignment

Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks:

• Set the number of each of the letter grades A, B, C, D, and F.

• Read the number of each of the letter grades A, B, C, D, and F.

• Return the total number of grades.

• Return the percentage of each letter grade as a whole number between 0 and 100, inclusive.

• Draw a bar graph of the grade distribution.

The graph will have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row is proportionate to the percentage of grades in each category. Let one asterisk represent 2 percent, so 50 asterisks correspond to 100 percent. Mark the horizontal axis at 10 percent increments from 0 to 100 percent, and label each line with its letter grade.

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.

Test Program

public class GradesGraphTest

{

   public static void main(String[] args)

   {

int numberOfAs;

int numberOfBs;

int numberOfCs;

int numberOfDs;

int numberOfFs;

System.out.println();

System.out.println("Test case 1: readInput() and writeOutput()");

GradesGraph grades = new GradesGraph();

grades.readInput();

System.out.println();

grades.writeOutput();

System.out.println();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 2:");

System.out.println("set counts as a group: A=1, B=2, etc.");

grades.set(1, 2, 3, 4, 5);

System.out.println();

System.out.println("Verify results with writeOutput():");

grades.writeOutput();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 3:");

System.out.println("set counts individually");

System.out.println("A=10, B=9, etc.");

grades.setAcount(10);

grades.setBcount(9);

grades.setCcount(8);

grades.setDcount(7);

grades.setFcount(6);

System.out.println();

System.out.println("Verify results with writeOutput():");

grades.writeOutput();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 4:");

System.out.println("write (display) counts individually:");

System.out.println();

System.out.println("Verify A=10, B=9, etc.");

System.out.println();

grades.writeAcount();

grades.writeBcount();

grades.writeCcount();

grades.writeDcount();

grades.writeFcount();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 5:");

System.out.println("return counts individually:");

System.out.println();

System.out.println("Verify A=10, B=9, etc.");

System.out.println();

System.out.println("A count = " + grades.getAcount());

System.out.println("B count = " + grades.getBcount());

System.out.println("C count = " + grades.getCcount());

System.out.println("D count = " + grades.getDcount());

System.out.println("F count = " + grades.getFcount());

System.out.println();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 6:");

System.out.println("return total number of grades");

System.out.println();

System.out.println("Verify total = 40");

System.out.println();

System.out.println("Total number of grades = "

+ grades.getTotalNumberOfGrades());

System.out.println();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 7:");

System.out.println("return percentages of each grade");

System.out.println();

System.out.println("Verify A=25, B=23, C=20, D=18, & F=15");

System.out.println();

System.out.println("A = " + grades.getPercentA());

System.out.println("B = " + grades.getPercentB());

System.out.println("C = " + grades.getPercentC());

System.out.println("D = " + grades.getPercentD());

System.out.println("F = " + grades.getPercentF());

System.out.println();

System.out.println("===============================");

System.out.println();

System.out.println();

System.out.println("Test case 8:");

System.out.println("Draw graph of grade percentages");

System.out.println();

System.out.println("Verify A=25, B=23, C=20, D=18, & F=15");

System.out.println();

grades.draw();

System.out.println();

System.out.println("Test case 9:");

System.out.println("Draw graph of grade percentages");

System.out.println();

System.out.println("Verify A=100%");

grades.set(1, 0, 0, 0, 0);

System.out.println();

grades.draw();

System.out.println();

System.out.println("Test case 10:");

System.out.println("Draw graph of grade percentages");

System.out.println();

System.out.println("Verify all 0%");

grades.set(0, 0, 0, 0, 0);

System.out.println();

grades.draw();

   }

}

  

The output will be:

Test case 1: readInput() and writeOutput()

How many A's?

5

How many B's?

9

How many C's?

5

How many D's?

6

How many F's?

2

Number of A's = 5

Number of B's = 9

Number of C's = 5

Number of D's = 6

Number of F's = 2

===============================

Test case 2:

set counts as a group: A=1, B=2, etc.

Verify results with writeOutput():

Number of A's = 1

Number of B's = 2

Number of C's = 3

Number of D's = 4

Number of F's = 5

===============================

Test case 3:

set counts individually

A=10, B=9, etc.

Verify results with writeOutput():

Number of A's = 10

Number of B's = 9

Number of C's = 8

Number of D's = 7

Number of F's = 6

===============================

Test case 4:

write (display) counts individually:

Verify A=10, B=9, etc.

Number of A's = 10

Number of B's = 9

Number of C's = 8

Number of D's = 7

Number of F's = 6

===============================

Test case 5:

return counts individually:

Verify A=10, B=9, etc.

A count = 10

B count = 9

C count = 8

D count = 7

F count = 6

===============================

Test case 6:

return total number of grades

Verify total = 40

Total number of grades = 40

===============================

Test case 7:

return percentages of each grade

Verify A=25, B=23, C=20, D=18, & F=15

A = 25

B = 23

C = 20

D = 18

F = 15

===============================

Test case 8:

Draw graph of grade percentages

Verify A=25, B=23, C=20, D=18, & F=15

2 10 20 30 40 50 60 70 80 90 100

| | | | | | | | | | |

**************************************************

************ A

*********** B

********** C

********* D

******* F

Test case 9:

Draw graph of grade percentages

Verify A=100%

2 10 20 30 40 50 60 70 80 90 100

| | | | | | | | | | |

**************************************************

************************************************** A

B

C

D

F

Test case 10:

Draw graph of grade percentages

Verify all 0%

2 10 20 30 40 50 60 70 80 90 100

| | | | | | | | | | |

**************************************************

A

B

C

D

F

Solutions

Expert Solution

Code:-

GradesGraph.java

import java.util.Scanner;

public class GradesGraph
{
private int Acount;
private int Bcount;
private int Ccount;
private int Dcount;
private int Fcount;
private int asteriskCount;

/**

Methods to set data members

*/

//Interactively assign values to all data members
public void readInput() {
Scanner keyboard = new Scanner(System.in);

System.out.println("How many A's?");
Acount = keyboard.nextInt();
System.out.println("How many B's?");
Bcount = keyboard.nextInt();
System.out.println("How many C's?");
Ccount = keyboard.nextInt();
System.out.println("How many D's?");
Dcount = keyboard.nextInt();
System.out.println("How many F's?");
Fcount = keyboard.nextInt();
}
//The following method sets all grades to newGradeCount
public void set(int newAcount, int newBcount,
int newCcount, int newDcount,
int newFcount) {

Acount = newAcount;
Bcount = newBcount;
Ccount = newCcount;
Dcount = newDcount;
Fcount = newFcount;
}

//While these methods set individual grades to newGradeCount
public void setAcount(int newAcount) {
Acount = newAcount;
}

public void setBcount(int newBcount) {
Bcount = newBcount;
}

public void setCcount(int newCcount) {
Ccount = newCcount;
}

public void setDcount(int newDcount) {
Dcount = newDcount;
}

public void setFcount(int newFcount) {
Fcount = newFcount;
}

public void writeOutput() { //Write out all grade counts
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);
}

//Display data to user
public void writeAcount() {
System.out.println("Number of A's = " + Acount);
}

public void writeBcount() {
System.out.println("Number of B's = " + Bcount);
}

public void writeCcount() {
System.out.println("Number of C's = " + Ccount);
}

public void writeDcount() {
System.out.println("Number of D's = " + Dcount);
}

public void writeFcount() {
System.out.println("Number of F's = " + Fcount);
}

//Return data for grades
public int getAcount() {
return Acount;
}

public int getBcount() {
return Bcount;
}

public int getCcount() {
return Ccount;
}

public int getDcount() {
return Dcount;
}

public int getFcount() {
return Fcount;
}

public int getTotalNumberOfGrades() { //Returns all five gradeCounts
return (Acount + Bcount + Ccount + Dcount + Fcount);
}

//These get the percentages
public int getPercentA() {
return (int)((float)Acount/this.getTotalNumberOfGrades() * 100
+ 0.5);
}

public int getPercentB() {
return (int)((float)Bcount/this.getTotalNumberOfGrades() * 100
+ 0.5);
}

public int getPercentC() {
return (int)((float)Ccount/this.getTotalNumberOfGrades() * 100
+ 0.5);
}

public int getPercentD() {
return (int)((float)Dcount/this.getTotalNumberOfGrades() * 100
+ 0.5);
}

public int getPercentF() {
return (int)((float)Fcount/this.getTotalNumberOfGrades() * 100
+ 0.5);
}


public void draw() { //Draws the graph thing.
//Draw scale
System.out.println("2 10 20 30 40 50 60 70 80 90 100");
System.out.println("| | | | | | | | | | |");
System.out.println("**************************************************");

//For loops count the asterisks down to get gradeCount

for(asteriskCount = 1;
asteriskCount <= getPercentA()/2;
asteriskCount++) {
System.out.print("*");
}
System.out.println(" A");

for(asteriskCount = 1;
asteriskCount <= getPercentB()/2;
asteriskCount++) {
System.out.print("*");
}
System.out.println(" B");

for(asteriskCount = 1;
asteriskCount <= getPercentC()/2;
asteriskCount++) {
System.out.print("*");
}
System.out.println(" C");

for(asteriskCount = 1;
asteriskCount <= getPercentD()/2;
asteriskCount++) {
System.out.print("*");
}
System.out.println(" D");

for(asteriskCount = 1;
asteriskCount <= getPercentF()/2;
asteriskCount++) {
System.out.print("*");
}
System.out.println(" F");
}
}

GradesGraphTest.java

public class GradesGraphTest

{
public static void main(String[] args)
{

int numberOfAs;
int numberOfBs;
int numberOfCs;
int numberOfDs;
int numberOfFs;

System.out.println();
System.out.println("Test case 1: readInput() and writeOutput()");
GradesGraph grades = new GradesGraph();
grades.readInput();
System.out.println();
grades.writeOutput();
System.out.println();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 2:");
System.out.println("set counts as a group: A=1, B=2, etc.");
grades.set(1, 2, 3, 4, 5);
System.out.println();
System.out.println("Verify results with writeOutput():");
grades.writeOutput();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 3:");
System.out.println("set counts individually");
System.out.println("A=10, B=9, etc.");
grades.setAcount(10);
grades.setBcount(9);
grades.setCcount(8);
grades.setDcount(7);
grades.setFcount(6);
System.out.println();
System.out.println("Verify results with writeOutput():");
grades.writeOutput();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 4:");
System.out.println("write (display) counts individually:");
System.out.println();
System.out.println("Verify A=10, B=9, etc.");
System.out.println();
grades.writeAcount();
grades.writeBcount();
grades.writeCcount();
grades.writeDcount();
grades.writeFcount();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 5:");
System.out.println("return counts individually:");
System.out.println();
System.out.println("Verify A=10, B=9, etc.");
System.out.println();
System.out.println("A count = " + grades.getAcount());
System.out.println("B count = " + grades.getBcount());
System.out.println("C count = " + grades.getCcount());
System.out.println("D count = " + grades.getDcount());
System.out.println("F count = " + grades.getFcount());
System.out.println();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 6:");
System.out.println("return total number of grades");
System.out.println();
System.out.println("Verify total = 40");
System.out.println();
System.out.println("Total number of grades = "
+ grades.getTotalNumberOfGrades());
System.out.println();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 7:");
System.out.println("return percentages of each grade");
System.out.println();
System.out.println("Verify A=25, B=23, C=20, D=18, & F=15");
System.out.println();
System.out.println("A = " + grades.getPercentA());
System.out.println("B = " + grades.getPercentB());
System.out.println("C = " + grades.getPercentC());
System.out.println("D = " + grades.getPercentD());
System.out.println("F = " + grades.getPercentF());
System.out.println();
System.out.println("===============================");
System.out.println();

System.out.println();
System.out.println("Test case 8:");
System.out.println("Draw graph of grade percentages");
System.out.println();
System.out.println("Verify A=25, B=23, C=20, D=18, & F=15");
System.out.println();
grades.draw();

System.out.println();
System.out.println("Test case 9:");
System.out.println("Draw graph of grade percentages");
System.out.println();
System.out.println("Verify A=100%");
grades.set(1, 0, 0, 0, 0);
System.out.println();
grades.draw();

System.out.println();
System.out.println("Test case 10:");
System.out.println("Draw graph of grade percentages");
System.out.println();
System.out.println("Verify all 0%");
grades.set(0, 0, 0, 0, 0);
System.out.println();
grades.draw();

}
}

Output:-

if u like my asnwer then please give a thumbs up..!!


Related Solutions

Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to...
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to do fraction arithmetic. To get you used to the idea of unit testing, this homework does not require a main method. You can create one if you find it useful, however, we will not be grading or even looking at that code. You should be comfortable enough with the accuracy of your test cases that you do not need to use print statements or...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
For this assignment, you will create flowchart using Flowgorithm to represent the logic of a program...
For this assignment, you will create flowchart using Flowgorithm to represent the logic of a program that allows the user to enter a number of dollars and convert it to Euros and Japanese yen. You will have to do some research on current rates of monetary exchange for this one. Don't forget to declare your variables and use output statements to prompt the user to enter specific values prior to including an input statement. You will use an assignment statement...
Objective: Create a program that has a class to represent a cup of coffee that combines...
Objective: Create a program that has a class to represent a cup of coffee that combines the properties: name and caffeine content. The class should also have a method that calculates the number of cups that would be maximally risky to consume in a short period of time. The program should create two instances of the class coffee where the user enters their properties and should output the amount of coffees that consumed would be risky. Requirements: Write a class...
Objective: Create a program that has a class to represent a cup of coffee that combines...
Objective: Create a program that has a class to represent a cup of coffee that combines the properties: name and caffeine content. The class should also have a method that calculates the number of cups that would be maximally risky to consume in a short period of time. The program should create two instances of the class coffee where the user enters their properties and should output the amount of coffees that consumed would be risky. Requirements: Write a class...
Java program In this assignment you are required to create a text parser in Java/C++. Given...
Java program In this assignment you are required to create a text parser in Java/C++. Given a input text file you need to parse it and answer a set of frequency related questions. Technical Requirement of Solution: You are required to do this ab initio (bare-bones from scratch). This means, your solution cannot use any library methods in Java except the ones listed below (or equivalent library functions in C++). String.split() and other String operations can be used wherever required....
java For this assignment, you will create a Time class that holds an hour value and...
java For this assignment, you will create a Time class that holds an hour value and a minute value to represent a time. We will be using "military time", so 12:01 AM is 0001 and 1 PM is 1300. For this assignment, you may assume valid military times range from 0000 to 2359. Valid standard times range from 12:00 AM to 11:59 PM. In previous assignments, we had a requirement that your class be named Main. In this assignment, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT