Question

Thank you in advance. Create a class called Main and write the main method. I need...

Thank you in advance.

Create a class called Main and write the main method. I need help with calling the printChart method

  • Declare a variable to hold the grade as it is read in
  • Declare 5 variables to hold counts to count the number of As, Bs, Cs, etc
  • declare a variable to hold the class name and ask the user to enter the name of the class whose grades are going to be entered.
  • Write a loop that reads in an integer (the grade) a negative value will terminate the loop
  • The loop should check the grade entered and then add to the appropriate count depending on if the grade is an A, B, C, etc (90 – 100 is an A, 80 – 89 is a B, etc)
  • After the loop has ended and all the counts have the values, create an object of the GradeHistogram class using the constructor in the class.
  • Use the printChart method to print the histogram for the object you created.

The GradeHistogram class is:

public class GradeHistogram
{
private String className;
private int numAs;
private int numBs;
private int numCs;
private int numDs;
private int numFs;
  
public GradeHistogram(String className, int numAs, int numBs, int numCs,int numDs, int numFs)
{
this.className = className;
this.numAs = numAs;
this.numBs = numBs;
this.numCs = numCs;
this.numDs = numDs;
this.numFs = numFs;
}
  
public void setClassName(String name)
{
className = name;
}
public void setNumAs(int num)
{
numAs = num;
}
public void setNumBs(int num)
{
numBs = num;
}
public void setNumCs(int num)
{
numCs = num;
}
public void setNumDs(int num)
{
numDs = num;
}
public void setNumFs(int num)
{
numFs = num;
}
  
public String getClassName()
{
return className;
}
public int getNumAs()
{
return numAs;
}
public int getNumBs()
{
return numBs;
}
public int getNumCs()
{
return numCs;
}
public int getNumDs()
{
return numDs;
}
public int getNumFs()
{
return numFs;
}
  
private void printDataRow(String string, int numAs2)
{
System.out.print(string + ": ");
for (int i = 0; i < numAs2; i++) {
System.out.print("*");
}
System.out.println();
}
  
public void printChart()
{
System.out.println("Class Name: " + className);
printDataRow("Number of As", numAs);
printDataRow("Number of Bs", numBs);
printDataRow("Number of Cs", numCs);
printDataRow("Number of Ds", numDs);
printDataRow("NUmber of Fs", numFs);
  
}
  
}

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

The printChart function is needed to be called from somewhere. For this purpose, it can be called from constructor at the end.

public GradeHistogram(String className, int numAs, int numBs, int numCs, int numDs, int numFs) {
this.className = className;
this.numAs = numAs;
this.numBs = numBs;
this.numCs = numCs;
this.numDs = numDs;
this.numFs = numFs;
//calling the printchart function
printChart();
}

Beow is the screenshot of the snippet that is changed and the sample output.

Please ask in comments if you have any doubts.

Add a comment
Know the answer?
Add Answer to:
Thank you in advance. Create a class called Main and write the main method. I need...
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
  • You will have to write one method in the GradeHistogram class The method should be called...

    You will have to write one method in the GradeHistogram class The method should be called printDataRow It has two formal parameters A string for the row label An int for how many asterisks are in the row The method will print The string that was passed in followed by a colon and a space The asterisks (*) After the last asterisk it will print a newline Example: the statement: printDataRow("Number of As", 7); would output the following Number of...

  • I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public...

    I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase {    // instance variables    private String itemName;    private String itemDescription;    private int itemPrice;    private int itemQuantity;    // default constructor    public ItemToPurchase() {        this.itemName = "none";        this.itemDescription = "none";        this.itemPrice = 0;        this.itemQuantity = 0;    }    public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) {   ...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • Need help debugging. first class seems fine. second class is shooting an error on s =...

    Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt);   third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console {     private Scanner sc;     boolean isValid;     int i;     double d;        public Console()     {         sc = new Scanner(System.in);     }     public String getString(String prompt)     {         System.out.print(prompt);         return sc.nextLine();...

  • Java help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the...

    Java help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the TA class to represent the course the student is TA'ing. 1.3) Provide a constructor for the class so the code in the PeopleFactory will work as provided. 1.4) Provide a toString() method for the TA  class so that TA's will output as shown in the sample code. Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • NOTE: Use the Account class codes in the section below these questions. Modify the main method...

    NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...

  • Need some help on homework practice problems, Thank you in advance! Problem 1: Write a method,...

    Need some help on homework practice problems, Thank you in advance! Problem 1: Write a method, parallelSum(), that uses the fork-join framework to compute the sum of the elements of an array. Its skeleton as well as its Javadoc is provided in the file ParallelSum.java. Simple code for testing and timing your method is also provided in the main method. This problem is essentially the same as ParallelMax in structure. Therefore, follow the code for ParallelMax to complete ParallelSum. Problem...

  • I need to make this code access the main method I suppose, but I don't know...

    I need to make this code access the main method I suppose, but I don't know how to make that happen... Help please! QUESTION: Write a method called switchEmUp that accepts two integer arrays as parameters and switches the contents of the arrays. Make sure that you have code which considers if the two arrays are different sizes. Instructor comment: This will work since you never go back to the main method, but if you did, it wouldn't print out...

  • ble and instance variable, and then use clas 4. Please discuss the difference between class variable...

    ble and instance variable, and then use clas 4. Please discuss the difference between class variable and instant variable to complete the following code for the count of number of stud public class Student _//q1: fill this line to create a class variable num. public Student 1/ 22: fill this line to increase num. public static int getNum() return num; public static void main(String[] args) { Student stl=new Student O; Student st2-new Student ; Student st3-new Student ; //q3: fill...

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