Question

In: Computer Science

In Java Write a program that allows Professor Poindexter to get class averages including the average...

In Java
Write a program that allows Professor Poindexter to get class averages including the average for allher/his classes. Professor Poindexter has M classes. M will be input from the terminal. For each class he/she will input each student’s grade for that class until 0 is input. Once the goof prof inputs 0, The class average for that class is output in the form:

  Average for Class X 1 is XXX.XX

Finally, once all the M class data is input, the final message will be output:

The Average for All of Professor Poindexter’s M classes is XX.XX

Here is the data you will use for your run:

How many classes does Professor Poindexter Have?

2

Input a student grade for class 1:

100

80

90

0

The Average for Class 1 is XX.XX

Input the grades for class 2:

80

75

90

99

0

The Average for Class 2 is XX.XX

The Average for All of Professor Poindexter’s M classes is XX.XX

Solutions

Expert Solution

import java.util.*;

public class Main
{
        public static void main(String[] args)
        {
            //initializing scanner 
            Scanner sc=new Scanner(System.in);
            int M,i,j,totalStudents;
            double marks,classMarks,totalMarks,classAverage;
            //taking input for number of batches
            System.out.println("How many classes does Professor Poindexter Have?");
            M=sc.nextInt();
            totalMarks=0.0;
            totalStudents=0;
            for(i=1 ; i<=M ; i++)
            {
                System.out.println("Input a student grade for class "+i+" :");
                //initializing random inputs for the while loop execution
                marks=-999.0;
                j=0;
                classMarks=0.0;
                //while loop will execute till it gets 0 as input
                while(marks!=0)
                {
                    //taking marks input
                    marks=sc.nextDouble();
                    //calculating total marks for each class
                    classMarks=classMarks+marks;
                    //counting number of stuents for the class
                    if(marks!=0)
                    {
                        j++;
                    }
                }
                //calculating total marks for all students of all classes
                totalMarks=totalMarks+classMarks;
                //calculating total students for all students of all classes
                totalStudents=totalStudents+(j);
                System.out.printf("The Average for Class %d is %.2f\n",i, (classMarks/(j)));
            }
            //calculating average for all class average
            classAverage=totalMarks/totalStudents;
            System.out.printf("The Average for All of Professor Poindexter’s M classes is %.2f",classAverage );
        }
}

Related Solutions

program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
Write a program that utilizes a Professor class. A professor has a first name, last name,...
Write a program that utilizes a Professor class. A professor has a first name, last name, affiliation, easiness grade, and a helpfulness grade. Grades range from 1 (lowest) to 5 (highest). The Professor class has two constructors. The first constructor initiates the object with just the first name, the last name, and the affiliation. The default value for easiness and helpfulness grade is 3. The second constructor initiates the object using the first name, the last name, the affiliation, and...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
Write a Java program that allows the user to specify a file name on the command...
Write a Java program that allows the user to specify a file name on the command line and prints the number of characters, words, lines, average number of words per line, and average number of characters per word in that file. If the user does not specify any file name, then prompt the user for the name.
in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the...
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the user to enter multiple levels of a text, consisting of a 'start', an 'exit', 'walls', and 'floors'. The letter S represents the start. E is the exit. O (the letter 'oh') represents a 'floor' (meaning a path you can follow). X is a wall (meaning a block you cannot pass). The program will accept Standard Input (System.in), It is up to you whether you...
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT