Question

In: Computer Science

rite a java program that uses the methods written in this section to do the following:Prompt...

rite a java program that uses the methods written in this section to do the following:Prompt the user for a number of grades using the getValidInput method. Ensure the number of grades is greater than 1 and less than 30. The error message is “You must enter a number between 1 and 30, please re-enter:”Prompt the user to enter the requested grades and total marks using the calculateLetterGrade method. The grades should be between 0 and 100. Display an appropriate error message where required. Use variables to count the number of each letter grade returned.When all grades have been entered display the distribution of grades using the showGradeDistribution method.?

Solutions

Expert Solution

import java.util.*;
public class Sample{
public static int getValidInput(){
Scanner input=new Scanner(System.in);
System.out.print("Enter grade greater then 1 and lessthan 30:");
while(true){
int n=input.nextInt();
if(n>=1 && n<=30){
return n;
}else{
System.out.print("You must enter the number between 1 and 30:");
}
}
}
public static int[] calculateLetterGrade(int n){
Scanner input=new Scanner(System.in);
int[] a=new int[]{0,0,0,0,0,0};
for(int i=0;i<n;i++){
System.out.print("Enter grade:");
while(true){
int grade=input.nextInt();
if(grade>=0 && grade<=100){
if(grade>90 && grade<=100)a[0]+=1;
else if(grade>80 && grade<=90)a[1]+=1;
else if(grade>70 && grade<=80)a[2]+=1;
else if(grade>60 && grade<=70)a[3]+=1;
else if(grade>50 && grade<=60)a[4]+=1;
else a[5]+=1;
break;
}else{
System.out.print("Enter the grade between 0 to 100 only:");
}
}
}
return a;

}
public static void GradeDistribution(int a[]){
char b[]=new char[]{'A','B','C','D','E','F'};
for(int i=0;i<6;i++){
System.out.println(b[i]+" "+a[i]);
}
}
public static void main(String args[]){
int cnt=getValidInput();
int[] a=new int[6];
a=calculateLetterGrade(cnt);
GradeDistribution(a);


}
}


Related Solutions

This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
rite a Java Program to play your version of the Texas Pick 3 Lottery. You will...
rite a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3 choice:0-999". Create a...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Objective: Create a program that uses the methods in the String and Math classes to do...
Objective: Create a program that uses the methods in the String and Math classes to do the following: Ask the user to enter two nouns Tell the user how many letters the nouns are from eachother in the dictionary. Tell the user the last letter of each of the nouns Tell the user the position of the letter "e" in each of the nouns, -1 if no "e" exists in the word. For full credit, you must use quotations around...
Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify...
Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify the given part of the program. Run your program against the provided Homework2Driver.java for requirements. */ /* Hint: This Queue implementation will always dequeue from the first element of the array i.e, elements[0]. Therefore, remember to shift all elements toward front of the queue after each dequeue. */ public class QueueArray<T> { public static int CAPACITY = 100; private final T[] elements; private int...
Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
I need this written in Java, it is a Linked List and each of it's Methods....
I need this written in Java, it is a Linked List and each of it's Methods. I am having trouble and would appreciate code written to specifications and shown how to check if each method is working with an example of one method being checked. Thank you. public interface Sequence <T> { /** * Inserts the given element at the specified index position within the sequence. The element currently at that * index position (and all subsequent elements) are shifted...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT