Question

You are asked to write a Java program that allows a professor to enter five grades and calculates the average. After displaying the average it asks Do you want to enter more grades? If yes it repeats the program otherwise it automatically ends the program.

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

import java.util.Scanner;

class Main {
public static void main(String[] args) {
  
// declaring variables
int grade, total = 0;
Scanner sc = new Scanner(System.in);
String choice = "yes";
  
// as long as answer is yes, repeating it
while(choice.equals("yes"))
{
// resetting total to 0
total = 0;
  
// taking input of grades from user and adding them to the total
for(int i=0; i<5; i++)
{
System.out.print("Enter a grade: ");
grade = sc.nextInt();
total += grade;
}
  
// printing average
System.out.printf("Average is %.2f\n",total/5.0);
  
// asking if user wants to continue
System.out.print("\nWould you like to continue? (Type yes if so) ");
choice = sc.next();
}
}
}

/* OUTPUT
Enter a grade: 6
Enter a grade: 4
Enter a grade: 8
Enter a grade: 7
Enter a grade: 2
Average is 5.40

Would you like to continue? (Type yes if so) yes
Enter a grade: 7
Enter a grade: 8
Enter a grade: 6
Enter a grade: 7
Enter a grade: 9
Average is 7.40

Would you like to continue? (Type yes if so) no
*/

Add a comment
Know the answer?
Add Answer to:
You are asked to write a Java program that allows a professor to enter five grades...
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
  • Write a program that asks the user for a student name and asks for grades until...

    Write a program that asks the user for a student name and asks for grades until the user enters a non-number input, it should then ask if the user wants to enter another student, and keep doing the process until the user stops adding students. The student’s must be stored in a dictionary with their names as the keys and grades in a list. The program should then iterate over the dictionary elements producing the min, max, and mean of...

  • Write a program for a professor to calculate the average grade of a student. The program...

    Write a program for a professor to calculate the average grade of a student. The program should accept as many grades as the professor wants to enter. Therefore, ask the professor for the first grade, the second grade, and so on until the professor enters a negative value. A negative value indicates that the professor is finished entering grades. Once the professor is finished, your program should output: a) the average grade of the student b) the letter grade of...

  • Java language. Write a short program that allows the user to enter the year that they...

    Java language. Write a short program that allows the user to enter the year that they were born (as an integer) and outputs the age that they will be at the end of this year. Declare the current year as a constant.

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • Java: The local Driver's License Office has asked you to write a program that grades the...

    Java: The local Driver's License Office has asked you to write a program that grades the written portion of the driver's   license exam. The exam has 20 multiple choice questions.   Here are the correct answers:    1. B  6. A  11.B  16. C    2. D  7. B  12.C  17. C    3. A   8. A  13.D  18. B    4. A  9. C  14.A  19. D    5. C  10. D  15.D  20. A    Your program should store the correct answers in an array. (Store each question's answer in an element of a String array.) The program...

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • write pseudocode to represent the logic of a program that allows the user to enter a...

    write pseudocode to represent the logic of a program that allows the user to enter a value for the radius of a circle. The program calculates the diameter by multiplying the radius by 2, and then calculates the circumference by multiplying the diameter by 3.14. The program outputs both the diameter and the circumference.

  • Write a program in assembly code (8086) to Write the program that asks the Use to enter grades for three Course

    Write the program that asks the Use to enter grades for three Course (Course A, Course B, Course c) then prints the avarege of these grades.

  • Using Java, write a program that teachers can use to enter and calculate grades of individual...

    Using Java, write a program that teachers can use to enter and calculate grades of individual students by utilizing an array, Scanner object, casting, and the print method. First, let the user choose the size for the integer array by using a Scanner object. The integer array will hold individual assignment grades of a fictional student. Next, use a loop to populate the integer array with individual grades. Make sure each individual grade entered by the user fills just one...

  • 2. Write a java program that asks you to enter your last name, your country of...

    2. Write a java program that asks you to enter your last name, your country of origin, your age, and your expected graduation year. After you enter them, write out each answer on a separate line. You must use Scanner to input the 4 fields, and println to output the 4 fields separately.

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
ADVERTISEMENT