Question

Write a Java program, including comments, to compute statistics for how students did on an exam....

Write a Java program, including comments, to compute statistics for how students did on an exam. The program should compute various things about a student and print it all out. Then it repeats the process for each new student until the entire set of data has been completed.

(a) The program reads in and prints the ID number of a student [see step (g) below] and then the number of right answers and the number of wrong answers. (The total number of questions on the test is 50.) For example, the program could read in the following:

1234 20 5 (ID number 1234 has 20 right and 5 wrong)

(b) The program computes and prints the total number of questions answered plus the number omitted (which is simply 50 minus the number answered). The number right plus the number wrong will never be more than 50 [see optional (a) below].

(c) The program computes the student's correct answer percentage, which is a decimal value between 0 and 1. The correct answer percentage is the number of right answers divided by the number of questions answered. [The student always answers at least one question--see optional (b).] For the data values shown for ID number 1234 above, the correct answer percentage is 20 / 25 = 0.800. The program should print this out as shown, with three decimal places.

(d) The program also assigns the student a numerical grade on the exam. The numerical grade is the number of right answers times 2 (ignoring the wrong answers). For example, ID number 1234 got a numerical grade of 40 on the exam (20 right x 2). The program prints the student's grade.

(e) The program determines if the student had more right than wrong answers, the same number of each, or more wrong than right answers. It prints an appropriate message.

(f) The program determines if the student omitted ten or more questions. It prints a message with this information.

(g) Then the program skips a few lines and repeats the entire process for the next student until the last student is finished. (You must decide how to recognize the last student.) (Hint: use a sentinel.)

(h) At that point, print the total number of students in the class (you must keep track of this as the program executes) and stop.

Data: Be sure to read in data for at least 12 students. Make sure that you have at least two with the same number right and wrong, at least two with more wrong than right, and at least two with more right than wrong. Include a student with all wrong answers and one with all right answers (but not 50 right). Have some students who don't omit anything and some who omit almost all the questions.


(I) If a student answered more than 50 questions, print an error message,

skip the rest of the processing and go on to the next student.

(j) Make sure that you do not divide by 0 if the student answered no questions (everything was omitted). Print a special message and go on to the next student.

(k) Keep track of the student with the best correct answer percentage and the one with the highest grade. (These do not have to be the same--to test, make sure they are different.) Print these out at the end.

(l) use a table to display the output

Note:
Output must be file directed.
Do not send prompts to the output file. Do not use global file objects.

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

solution:

// StudentGrades.java

import java.util.Scanner;

public class StudentGrades {

public static void main(String[] args) {

//defining all required variables

int right, wrong, totalAnswered, grade, id = 0, total = 50, count = 0;

double percent;

//defining a Scanner to read user input

Scanner scanner = new Scanner(System.in);

//displaying a description on how to use this program

System.out

.println("Input format: student_id <space> right_answers <space> wrong_answers");

System.out.println("To finish, enter -1");

//looping until sentinel value (-1) is entered

do {

//getting id

id = scanner.nextInt();

//checking if id is not sentinel value

if (id != -1) {

//getting number of right and wrong answers

right = scanner.nextInt();

wrong = scanner.nextInt();

//finding total questions answered

totalAnswered = right + wrong;

//if above value is greater than 50, displaying error

if (totalAnswered > total) {

System.out

.println("Total answered questions cannot be more than "

+ total);

} else {

//calculating and displaying all stats

System.out.println("ID: " + id);

System.out.println(right + " right\t" + wrong + " wrong");

System.out.println("Total answered: " + totalAnswered);

System.out.println("Number omitted is "

+ (total - totalAnswered));

grade = right * 2;

System.out.println("Grade is " + grade);

if (right > wrong) {

System.out.println("More right than wrong");

} else if (right < wrong) {

System.out.println("More wrong than right");

} else {

System.out.println("Same number of right and wrong");

}

//checking if total answered is greater than zero, to prevent

//division by zero

if (totalAnswered > 0) {

percent = (double) right / totalAnswered;

} else {

percent = 0;

}

System.out.printf("Correct answer pct. is %.3f\n", percent);

if ((total - totalAnswered) >= 10) {

System.out.println("10 or more omitted.");

} else {

System.out.println("less than 10 omitted.");

}

System.out.println("\n\n\n\n\n");

count++;

}

}

} while (id != -1);

//after the loop, printing number of students processed

System.out.println("Total number of students: " + count);

}

}

output:

Add a comment
Know the answer?
Add Answer to:
Write a Java program, including comments, to compute statistics for how students did on an exam....
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 complete JAVA program, including comments (worth 2 pts -- include a good comment at...

    Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at the top and at least one more good comment later in the program), to process data for the registrar as follows: NOTE: Include prompts. Send all output to the screen. 1. Read in the id number of a student, the number of credits the student has, and the student’s grade point average (this is a number like 3.25). Print the original data right after...

  • You have been asked to write a program to grade several multiple-choice exams. The exam has...

    You have been asked to write a program to grade several multiple-choice exams. The exam has 20 questions, each answered with a letter in the range of ‘a’ through ‘f’. The answers key is declared in the program as constant of type string. An example of answer key is “abcdefabcdefabcdefab”. Your program should work for any other answer key. The program should first ask users for the number of students to be graded. Then it should have a while loop...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • C# Write a program that takes a list of information and grades of the students of...

    C# Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program. The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user: Which task you want to do (choose an option between 1-2), 1- Entering new information 2- Searching a student If the user types something rather...

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

  • IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the...

    IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade a student earned in each test, and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : In test 1 the highest grade was 93% and...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [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:...

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

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