Question

In: Computer Science

For this exercise, you will implement two programs that allow the user to enter grades in...

For this exercise, you will implement two programs that allow the user to enter grades in a gradebook. The first program will use one‐dimensional arrays, and the second program will use two‐dimensional arrays. The two programs function the same

Write an application that prints out the final grade of the students in a class and the average for the whole class. There are a total of 3 quizzes. You will need 4 arrays:

1. An array of type int to store all the ID's

2. An array of type double to store all scores for quiz 1

3. An array of type double to store all scores for quiz 2

4. An array of type double to store all scores for quiz 3

How to proceed:

1. Ask the user how many students are in the class, so you can set the length of all the arrays.

2. Allocate 4 arrays that will store the data.

3. Use a FOR loop to retrieve and store all the data.

4. Use another FOR loop to  

a. Output the final score for each student.

b. Keep track of all scores to later compute the average for the class.

5. Calculate and Output the average for the class.

Format all floating‐point numbers to 2 decimal places

Your program MUST receive user input as shown in the sample output.

Please leave comments on the program so i can give you a thumbs up :)!

Also, this is for java language.

Solutions

Expert Solution

CODE:

USING ONE DIMENSIONAL ARRAY:

import java.util.Scanner;

public class Average1D {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("How many Students in the class ?");

//Getting total number of students
int numberOfStudents = input.nextInt();

//Declaring Arrays for studentIds,quiz1,qui2,quiz3 of size n
int[] studentIds = new int[numberOfStudents];

double[] quiz1 = new double[numberOfStudents];

double[] quiz2 = new double[numberOfStudents];

double[] quiz3 = new double[numberOfStudents];

//Getting n students id,quiz1,quiz2,quiz3 data
for (int i = 0; i < numberOfStudents; i++) {

System.out.println("Enter The Student Id: ");

studentIds[i] = input.nextInt();

System.out.println("Enter score for Quiz 1: ");

quiz1[i] = input.nextDouble();

System.out.println("Enter score for Quiz 2: ");

quiz2[i] = input.nextDouble();

System.out.println("Enter score for Quiz 3: ");

quiz3[i] = input.nextDouble();

}

//For calculating the average of n students;
double[] average = new double[numberOfStudents];

double classTotal = 0.0;

for (int i = 0; i < numberOfStudents; i++) {

   //average = (Sum of items)/(No of items)
average[i] = (quiz1[i] + quiz2[i] + quiz3[i]) / 3;

classTotal = classTotal + average[i];

}

//Displaying the average of each student
for (int i = 0; i < numberOfStudents; i++) {

System.out.println("ID " + studentIds[i] + " - Final Grade: " + average[i]);

}

//Displaying the totalClassAverage
System.out.println("Class Avergae: " + classTotal/numberOfStudents);

}

}

Sampel Output:

How many Students in the class ?

4

Enter The Student Id:

111

Enter score for Quiz 1:

100

Enter score for Quiz 2:

95

Enter score for Quiz 3:

90

Enter The Student Id:

222

Enter score for Quiz 1:

90

Enter score for Quiz 2:

85

Enter score for Quiz 3:

80

Enter The Student Id:

333

Enter score for Quiz 1:

100

Enter score for Quiz 2:

100

Enter score for Quiz 3:

100

Enter The Student Id:

444

Enter score for Quiz 1:

90

Enter score for Quiz 2:

90

Enter score for Quiz 3:

90

ID 111 - Final Grade: 95.0

ID 222 - Final Grade: 85.0

ID 333 - Final Grade: 100.0

ID 444 - Final Grade: 90.0

Class Avergae: 92.5

USING TWO DIMENSIONAL ARRAY:

class Average2D {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("How many Students in the class ?");

//Getting total number of students
int numberOfStudents = input.nextInt();

//Declaring Array to store studentId of size n
int[] studentIds = new int[numberOfStudents];

//Declaring 2D Array, Since we have 3 quiz test marks of size(nxNo.of students).
double[][] quiz = new double[3][numberOfStudents];

for (int i = 0; i < numberOfStudents; i++) {

System.out.println("Enter The Student Id: ");

//Getting student ID
studentIds[i] = input.nextInt();

for (int j = 0; j < 3; j++) {

System.out.println("Enter score for Quiz " + j + 1 + ":");

//Respective student 3 quiz test marks
quiz[j][i] = input.nextDouble();

}

}

double[] average = new double[numberOfStudents];

double classTotal = 0.0;

for (int i = 0; i < numberOfStudents; i++) {
     
   //Calculating average of three quiz test marks
average[i] = (quiz[0][i] + quiz[1][i] + quiz[2][i]) / 3;

classTotal = classTotal + average[i];

}

//Displaying the average of each student
for (int i = 0; i < numberOfStudents; i++) {

System.out.println("ID " + studentIds[i] + " - Final Grade: " + average[i]);

}

//Displaying the totalClassAverage
System.out.println("Class Avergae: " + classTotal / numberOfStudents);

}

}

Sample Output:

How many Students in the class ?

4

Enter The Student Id:

111

Enter score for Quiz 1:

100

Enter score for Quiz 2:

90

Enter score for Quiz 3:

95

Enter The Student Id:

222

Enter score for Quiz 1:

90

Enter score for Quiz 2:

80

Enter score for Quiz 3:

85

Enter The Student Id:

333

Enter score for Quiz 1:

100

Enter score for Quiz 2:

100

Enter score for Quiz 3:

100

Enter The Student Id:

444

Enter score for Quiz 1:

90

Enter score for Quiz 2:

90

Enter score for Quiz 3:

90

ID 111 - Final Grade: 95.0

ID 222 - Final Grade: 85.0

ID 333 - Final Grade: 100.0

ID 444 - Final Grade: 90.0

Class Avergae: 92.5


Related Solutions

1.- In this assignment you will implement a simulation of the interaction of user programs with...
1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation on two different devices. User programs: User programs will communicate with DOIO (OS) to request an I/O operation. (This will simulate a system call) User programs will give to DOIO three parameters: User id, device number (dev is a random number in the range 1 and 2 that represents device one or device two) and an address...
In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
This exercise allows a user to enter the values of two, 3x3 matrices and then select...
This exercise allows a user to enter the values of two, 3x3 matrices and then select from options including, addition, subtraction, matrix multiplication, and element by element multiplication. You should use numpy.matmul() for matrix multiplication (e.g. np.matmul(a, b) ). The program should computer the appropriate results and return the results, the transpose of the results, the mean of the rows for the results, and the mean of the columns for the results. When entering data you should check that each...
Use a for loop to ask a user to enter the grades of 5 courses. The...
Use a for loop to ask a user to enter the grades of 5 courses. The user should enter character values, e.g., A. Calculate the GPA of the user Hint: Convert the character values entered to numerals, e.g., A to 4 c programming help me please
Develop a rudimentary Java program that will allow anyone to enter any number of grades and...
Develop a rudimentary Java program that will allow anyone to enter any number of grades and then calculate grade point average. For reference, a grade point average is a weighted average of a set of grades based on the relative number of credits. For example, a 1 credit “A” (4.0) should count twice as much as a .5 credit “C” (3.0), and a 1.5 credit “A+”(4.33) should count three times as much as the “C” and 1.5 times as much...
Write a C++ program that : 1. Allow the user to enter the size of the...
Write a C++ program that : 1. Allow the user to enter the size of the matrix such as N. N must be an integer that is >= 2 and < 11. 2. Create an vector of size N x N. 3. Call a function to do the following : Populate the vector with N2 distinct random numbers. Display the created array. 4. Call a function to determines whether the numbers in n x n vector satisfy the perfect matrix...
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
Forms often allow a user to enter an integer. Write a program that takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or any string with a non-integer character, the output is: no PYTHON 3
Forms often allow a user to enter an integer. Write a programthat takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT