Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Inst. 4.2] Use the below mentioned code for following question(s). Scanner keyboard = new Scanner(System.in); int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades

[Inst. 4.2] Use the below mentioned code for following question(s).

Scanner keyboard = new Scanner(System.in);

int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If there are 8 students and they have taken 8, 10, 5, 3, 7, 11, 12, and 9 tests respectively, how many times will the inner loop execute for all students?

A. 8
B. 57
C. 65
D. Cannot tell

[Inst. 4.2] Use the below mentioned code for following question(s).

Scanner keyboard = new Scanner(System.in);

int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If there are 5 students and each student has 10 grades, how many times will the inner loop execute for each student?

A.
5
B. 10
C. 50
D. Cannot tell

[Inst. 4.2] Use the below mentioned code for following question(s).

Scanner keyboard = new Scanner(System.in);

int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If 10 students are entered and each student has 12 grades, how many times does the outer loop execute?

A. 10
B. 12
C. 120
D.

Cannot tell

[Inst. 4.2] Use the below mentioned code for following question(s).

Scanner keyboard = new Scanner(System.in);

int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. The if (totalNumberOfGrades != 0)

A. Is not necessary because at least one grade will always be entered
B. Ensures that we do not divide by 0, which is an error
C. Assigns a value of 0 to the student's average if no grades are entered

D. Ensures that each grade is greater than 0

[Inst. 4.2] Use the below mentioned code for following question(s).

Scanner keyboard = new Scanner(System.in); int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. In the while (studentID != 0)) statement, what is the function of "0"?

A. If there is 0 students, the while statement will not be executed
B. It tells the program to give the student a grade of 0, if he does not have any grades
C. It is a sentinel
D. It initializes the count of the number of students

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions

Question

=+2. Is this public actively seeking information on this issue?

Answered: 1 week ago

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago