Question

Write a program that prompts the user for student grades, calculates and displays the average grade...

Write a program that prompts the user for student grades, calculates and displays the average grade in the class. The user should enter a character to stop providing values.

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

Code:

import java.util.*;
public class Grades
{
public static boolean isNumeric(String s) {
    return java.util.regex.Pattern.matches("\\d+", s);   //checking regular expression will the given string is starting with digit or not
}
public static void main(String args[])
   {
   Scanner input=new Scanner(System.in);
   double count=0,sum=0;
   while (true)
       {
           System.out.print("Enter the grade of a student: ");
           String input_grade=input.nextLine(); //take grade input from user
           if (isNumeric(input_grade)==false) //if the grade input is not a Numeric value
               {
               System.out.println("The Average Grade in the Class is " + (sum/count)); //then print average
               break;//after that break the loop
               }
           else
               {
               sum=sum+Double.parseDouble(input_grade); //add the grade to sum
               count++;            //increment the count value
               }
       }
   }
}

Code and Outputs Screenshots:

Note : if you have any queries please post a comment thanks a lot..always available to help you..

Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user for student grades, calculates and displays the average grade...
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 prompts the user for student grades and displays the highest and lowest grades in the class.

    Write a program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values.example Enter as many student grades as you like. Enter a character to stop. The highest grade is: 92.0 The lowest grade is: 10.65# in java

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • 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...

  • Write a program that computes the average of a set of grades. The user is prompted...

    Write a program that computes the average of a set of grades. The user is prompted the following: 1-Number of grades to be entered. 2-The value of the minimum grade. 3-The value of the maximum grade. Make sure to write input validation for the following: 1-The number of grades cannot be negative! In case it is 0, it means that user has no grades to enter. 2-Each entered grade should be a valid grade between the minimum and maximum values...

  • I need to Write a test program that prompts the user to enter 10 double values...

    I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...

  • 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...

  • Write a program that prompts the user to enter two characters and displays the major and status represented in the characters.

    Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: M: MathematicsC: Computer Science T: Testing and Certification

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • Write a program that prompts the user for a String value and a character value. The...

    Write a program that prompts the user for a String value and a character value. The program should then find the last occurrence of the provided character in the provided String and display the corresponding index. If the character is not found in the String, display -1. For additional challenge, create a multi-class solution. The business class should consist of two instance varaibles to store the user provided values and one method to accomplish the given task. The tester class...

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