import java.util.*; /** Description: This program determines the
average of a list of (nonnegative) exam scores. Repeats for more
exams until the user says to stop. Input: Numbers, sum, answer
Output: Displays program description Displays instruction for user
Displays average Algorithm: 1. START 2. Declare variables sum,
numberOf Students, nextNumber, answer 3. Display welcome message
and program description 4. DOWHILE user wants to continue 5.
Display instructions on how to use the program 6. Inititalize sum
and number of student to 0 7. Get next number from keyboard 8.
WHILE there are more numbers 9. Accumulate sum 10. Add 1 to number
of students 11. Get next number 12. END WHILE 13. IF number of
students > o 14. Display average 15. ELSE 16. Display message
that no scores were entered 17. END IF 18 Ask user if they want to
continue 19. Get answer 20. END DOWHILE 21. Display end of program
message 22. STOP @author Sandra Perez @since 3/18/2015 */ public
class ExamAveragerWhile //Name of class (same as name of program) {
public static void main(String[] args) { //Declare variables double
sum; //Declare variable for sum int numberOfStudents; //Declare
variable for number of students double nextNumber; //Declare
variable for next number String answer; //Declare variable for
answer from user Scanner keyboard = new Scanner(System.in); //Set
up Scanner to get data from keyborad //Display welcome message and
description System.out.println("This Exam Averager program computes
the average of"); System.out.println("a list of (nonnegative) exam
scores."); //DoWhile user wants to continue do {
System.out.println( ); //Display a blank line
System.out.println("Enter all the exams to be averaged.");
//Display instructions System.out.println("\nEnter a negative
number after"); System.out.println("you have entered all the
scores."); sum = 0; //Initialize sum to 0 numberOfStudents =
0;//Initialize number of students to 0 //Get next number from
keyboard nextNumber = keyboard.nextDouble( ); //Loop to calculate
the sum while (nextNumber >= 0) //Loop while there are more
numbers //A negative number means no more numbers { sum = sum +
nextNumber; //Accumulate sum numberOfStudents++; //Add 1 to number
of students nextNumber = keyboard.nextDouble( ); //Get next number
from keyboard } //End while if (numberOfStudents > 0) //If more
students System.out.println("The average is " +
(sum/numberOfStudents)); //Display the average else //No more
students System.out.println("No grades to average."); //Else
display message no grades //ENDIF //Asks user if there is another
set of grades System.out.println("Do you want to average another
set of grades?"); System.out.println("Enter yes or no."); //Get
answer answer = keyboard.next( ); } while
(answer.equalsIgnoreCase("yes")); //End of while loop when
answer(ignore case) is yes //Display end of program message
System.out.println("Thank you for using the Exam Averager!"); }
//End of main } //End of class
instructions and directions are blow this point
The purpose of this assignment is to develop two
programs:
1. A revised version of the ExamAveragerWhile.java
program that is object oriented and uses methods as indicated
below
2. A second testing program that will test various
features of the program.
Problem Statement
Use the ExamAveragerWhile.java program and
make the following changes:
Revise the logic of the program to use methods for the
following activities in the program:
1.1 displayWelcome()
1.2 displayInstructions()
1.3 getNextNumber()
1.4 calculateSum()
1.5 displayAverage()
1.6 displayThankyou()
2. Add a method to verify that numeric data is
required.
3. Your main() method will contain the basic logic of
the program. You may want to add an additional method.
4. Add a comment with an appropriate name for your
class. Make certain that you have revised your Javadoc comments to
reflect the new logic for calling methods.
5. To make it clear name your program
ExamAveragerWhileOOYourFirstInitialYourLastInitial.java
Directions
Create a folder named like
Assignment6FirstnameLastname using your name.
Using the Template.java file create a Java program
named ExamAveragerWhileOOTestYourFirstInitialYourLastInitial.java
using your name and place it in your folder. Fill in the
documentation at the top of the program including description,
input, and output as well as the Javadoc tags.
Demonstrate that your program works by creating
another testing program to cover the following situations (you will
have to create a new object in your test program for each test
situation):
3.1 Create a test case that demonstrates the features
and use data test cases that includes:
a) no data is input
b) a negative number is input
c) three numbers input
3.2 Create a test case where the user enters text data
instead of integers.
3.3 Create a test case where the users run the program
a second time with a new set of data.
Note: You will need to create two programs one that
has the basic class with methods as stated in the Problem Statement
above and another testing program that uses various test cases. See
Student.java and StudentTest.java for an example for creating test
cases as we discussed in class.
4. Create a Word file named
Assignment6MethodsProgramDocumentFirstnameLastname to complete the
Program Design template including input, output, algorithm, and
screenshots of your program running each of the 5 test cases and
place it in your folder. At the end of your Program Design Document
include a class diagram for this program. You can use drawi.io to
create your class diagram as we did in class.
import java.util.Scanner;
// Name of class (same as name of program)
// Defines class ScoreAveragerWhile
class ScoreAveragerWhile
{
// Declare instance variables
// Declare variable for sum
double sum;
// Declare variable for number of students
int numberOfStudents;
// Declare variable for next number
double nextNumber;
// Set up Scanner to get data from keyborad
Scanner keyboard = new Scanner(System.in);
// Method to display welcome message
void displayWelcome()
{
// Display welcome message and
description
System.out.print("\n *********
Welcome to Average Calculater ********* ");
System.out.print("\n This Averager
program computes the average of");
System.out.print(" \n a list of
(nonnegative) scores.");
}// End of method
// Method to display instruction
void displayInstructions()
{
System.out.print("\n\n *********
Instruction to user ********* ");
//Display a blank line
System.out.print("\n Enter all the
score to be averaged.");
//Display instructions
System.out.print("\n Enter a
negative number after");
System.out.print(" you have entered
all the scores.\n");
}// End of method
// Method to accept score
void getNextNumber()
{
System.out.print("\n Enter score:
");
// Get next number from
keyboard
nextNumber = keyboard.nextDouble(
);
}// End of method
// Method to to calculate sum
void calculateSum()
{
// Loop to calculate the sum
// Loop while there are more
numbers
// A negative number means no more
numbers
while (nextNumber >=
0)
{
// Accumulate
sum
sum = sum +
nextNumber;
// Increase the
number of student by one
numberOfStudents++;
// Calls the
method to accept score
getNextNumber();
} //End while
}// End of method
// Method to calculate and display
average
void displayAverage()
{
// If more students
if (numberOfStudents > 0)
// Display the
average
System.out.print("\n The average is " + (sum /
numberOfStudents));
// No more students
else
// Else display
message no grades
System.out.print("\n No grades to average.");
// ENDIF
}// End of method
// Method to display thanks message
void displayThankyou()
{
// Display end of program
message
System.out.println("Thank you for
using the Score Averager App!");
}// End of method
}// End of class
// Driver class definition
public class ScoreAveragerWhileTest
{
// main method definition
public static void main(String[] args)
{
// Creates an object of class
ExamAveragerWhile
ScoreAveragerWhile eaw = new
ScoreAveragerWhile();
// Declare variable for answer from
user
String answer;
// Calls the method to display
welcome message
eaw.displayWelcome();
// Calls the method to display
instruction
eaw.displayInstructions();
// DoWhile user wants to
continue
do
{
// Initialize
sum to 0
eaw.sum =
0;
// Initialize
number of students to 0
eaw.numberOfStudents = 0;
// Calls the
method to accept score
eaw.getNextNumber();
// Calls the
method to calculate sum
eaw.calculateSum();
// Calls the
method to calculate average and displays it
eaw.displayAverage();
// Asks user if
there is another set of grades
System.out.print("\n Do you want to average another set of grades?
");
System.out.println("\n Enter yes or no.");
// Get
answer
answer =
eaw.keyboard.next( );
} while
(answer.equalsIgnoreCase("yes"));
// End of while loop when
answer(ignore case) is yes
// Calls the method to display
thanks message
eaw.displayThankyou();
} //End of main
}// End of driver class
Sample Output:
********* Welcome to Average Calculater *********
This Averager program computes the average of
a list of (nonnegative) scores.
********* Instruction to user *********
Enter all the score to be averaged.
Enter a negative number after you have entered all the scores.
Enter score: 10.0
Enter score: 20.0
Enter score: 30.0
Enter score: -3
The average is 20.0
Do you want to average another set of grades?
Enter yes or no.
yes
Enter score: -8
No grades to average.
Do you want to average another set of grades?
Enter yes or no.
yes
Enter score: 45.6
Enter score: 33.7
Enter score: 89.4
Enter score: 66.6
Enter score: 12.1
Enter score: -7
The average is 49.480000000000004
Do you want to average another set of grades?
Enter yes or no.
no
Thank you for using the Score Averager App!
import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores....
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...
IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...
CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...
have to create five different functions above and call it in the main fucntion. Project Exam Statistics A CIS 22A class has two midterm exams with a score between 0 and 100 each. Fractional scores, such as 88.3 are not allowed. The students' ids and midterm exam scores are stored in a text file as shown below // id exam1 exam2 DH232 89 92 Write a program that reads data from an input file named exams.txt, calculates the average of...
Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...
[JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...
use JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....
Write a program that performs the following: 1. Presents the user a menu where they choose between: a. Add a new student to the class i. Prompts for first name, last name ii. If assignments already exist, ask user for new student’s scores to assignments b. Assign grades for a new assignment i. If students already exist, prompt user with student name, ask them for score ii. Students created after assignment will need to...
Declare and initialize 4 Constants for the course category weights: The weight of Homework will be 15% The weight of Tests will be 35% The weight of the Mid term will be 20% The weight of the Fin al will be 30% Remember to name your Constants according to Java standards. Declare a variable to store the input for the number of homework scores and use a Scanner method to read the value from the Console. Declare two variables: one...
In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...