Question

In: Computer Science

rite a method with the following header: public static void showGradeDistribution(int a, int b, int c,...

rite a method with the following header:

public static void showGradeDistribution(int a, int b, int c, int d,

int f)

It should print a graph (using asterisks) for each of the letters entered in the reverse order of the

parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C

and D and F, the message “Strong class!” should be displayed. For example a method call of:

showGradeDistribution(5,7,4,4,3);

Would print:

A: *****

B: *******

C: ****

D: ****

F: ***

Strong clas

Solutions

Expert Solution

public class GradeGraph {
        public static void main(String[] args) {
                showGradeDistribution(5, 7, 4, 4, 3); //supply values for grades
        }
//function that takes grades as parameters
        public static void showGradeDistribution(int a, int b, int c, int d, int f) //function that takes grades as parameters
        {
                System.out.print("A: "); //print asterisks for A grade
                for(int i = 0; i<a; i++) //loop until a
                {
                        System.out.print('*'); //print asterisk for number of times A is received
                }
                System.out.println();
                System.out.print("B: "); //print asterisks for B grade
                for(int i = 0; i<b; i++)
                {
                        System.out.print('*');
                }
                System.out.println();
                System.out.print("C: "); //print asterisks for C grade
                for(int i = 0; i<c; i++)
                {
                        System.out.print('*');
                }
                System.out.println();
                System.out.print("D: "); //print asterisks for D grade
                for(int i = 0; i<d; i++)
                {
                        System.out.print('*');
                }
                System.out.println();
                System.out.print("F: "); //print asterisks for F grade
                for(int i = 0; i<f; i++)
                {
                        System.out.print('*');
                }
                System.out.println();
                if((a+b)>=(c+d+f)) //as per question if sum of a and b is >= sum of c d and f
                {
                        System.out.println("Strong class!"); //print strong class
                }
        }
}

OUTPUT OF THE PROGRAM ON INPUT: showGradeDistribution(5,7,4,4,3);

OUTPUT OF THE PROGRAM ON INPUT: showGradeDistribution(2,7,4,4,3);

Notice here strong class is missing.

Thanks and please do not forget to leave a thuumbs up :)


Related Solutions

Write a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down Java codes to invoke m1 method, declare variables as needed, (Do NOT implement the method)
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int length, int width)
public class Problem1 {    public static void partition(int[] A)    {        /*Rearrange the...
public class Problem1 {    public static void partition(int[] A)    {        /*Rearrange the array to have the following property:        Suppose the first element in the original array has the value x.        In the new array, suppose that x is in position i, that is data[i] = x.        Then, data[j] <= x for all j < I and data[j] > x for all j > i.        Thus, informally, all the...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of length at least two as an argument, and swaps the smallest value of the array into the 0th position and swaps the largest value of the array into the last position. For example, if int[] a = {4, 3, 2, 6, 1, 5}, the method call minMax(a) should modify the array so that it is {1, 3, 2, 5, 4, 6}. The method should...
import javax.swing.JOptionPane; public class RandomGuess { public static void main(String[] args) { int guess; int result;...
import javax.swing.JOptionPane; public class RandomGuess { public static void main(String[] args) { int guess; int result; String msg; final int LOW = 1; final int HIGH = 10; result = LOW + (int)(Math.random() * HIGH); guess = Integer.parseInt(JOptionPane.showInputDialog(null, "Try to guess my number between " + LOW + " and " + HIGH)); if(guess == result) msg = "\nRight!"; else if(guess < result) msg = "\nYour guess was too low"; else msg = "\nYour guess was too high"; JOptionPane.showMessageDialog(null,"The number...
public class Main { public static void main(String [] args) { int [] array1 = {5,...
public class Main { public static void main(String [] args) { int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65}; int numElements = 10; System.out.println("Part 1"); // Part 1 // Enter the statement to print the numbers in index 5 and index 8 // put a space in between the two numbers and a new line at the end // Enter the statement to print the numbers 8 and 53 from the array above //...
---------------------------------------------------------------------------- public class Main { public static void main(String[] args) { int[] A = {11, 12,...
---------------------------------------------------------------------------- public class Main { public static void main(String[] args) { int[] A = {11, 12, -10, 13, 9, 12, 14, 15, -20, 0}; System.out.println("The maximum is "+Max(A)); System.out.println("The summation is "+Sum(A)); } static int Max(int[] A) { int max = A[0]; for (int i = 1; i < A.length; i++) { if (A[i] > max) { max = A[i]; } } return max; } static int Sum(int[] B){ int sum = 0; for(int i = 0; i --------------------------------------------------------------------------------------------------------------------------- Convert...
class ArrayReverse1{ public static void reverse(int[] a, int index) { if (index >0) { index= index...
class ArrayReverse1{ public static void reverse(int[] a, int index) { if (index >0) { index= index - 1; // Decrementing the index System.out.printf("%d%n", a[index]); reverse(a, index); // Recursive call } return; } public static void main (String args[]) { int [] array = { 1, 2, 3, 4, 5 }; int n=array.length; reverse(array,n); // function call } } Write a generic version of the corrected recursive reverse method that could be used to print any of the following arrays (or...
Consider the following recursive method in Java public static int mystery(int n) {   if (n ==...
Consider the following recursive method in Java public static int mystery(int n) {   if (n == 0)   return 1;    else    return 4 * mystery (n - 1);   } What is the output of  mystery (3) using the code segment above Show your work on your trace file
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT