Question: The Problem Statement In this lab section, you are going to learn how to use loop statements. You are going to write an application that

The Problem Statement

In this lab section, you are going to learn how to use loop statements. You are going to write an application that has two classes. Each of these classes may have multiple methods. One method may call another method within the same class.

This application will calculate the average score for a test taken by the students. It will ask user to input the a number of entries. For each entry, the user will input a test score (see Test Case 1 for detailed input values). Then the application will calculate the average score and output the result. You need to use the following test data when you do a screen capture.

Test Case 1

Input:

Welcome to ICS 141 Lab 2.

Number of entries: 3

Score1: 70

Score2: 90

Score3: 100

Output:

The average score for your inputs is:

// you figure out

The Design

This is a relatively simple application. Thus we are going to use two classes to implement this application. The worker class is named GradeAverage and the application class is named TestGradeAverage. The member information of the two classes is:

TestGradeAverage

main()

GradeAverage

double: averageScore

GradeAverage() // constructor

static int readInt()

void calculateGradeAverage()

double getGradeAverage()

The relationship of the two classes is: TestGradeAverage uses GradeAverage. The readInt() method is a static method. This method reads an integer from the standard input (keyboard).

SCORE YOUR POINTS BY DOING THE FOLLOWING

According to the information given above, draw a class diagram in the space below (using UML notation) (4 pts).

Programming work

In this section, you are asked to implement the above design and do some screen captures of the outputs. You are given partial code and you need to finish the missing code according to the requirements.

Specifically, you are given the following code:

class GradeAverage

Application class TestGradeAverage

And you need to supply the missing code for the following classes methods:

calculateGradeAverade() in GradeAverage

getGradeAverage() in GradeAverage

The following is the partial code for this application:

import javax.swing.*;

public class GradeAverage {

private double averageScore;

public GradeAverage() {

averageScore = 0;

}

private static int readInt(String prompt) {

String numStr = JOptionPane.showInputDialog(prompt);

return Integer.parseInt(numStr);

}

public void calculateGradeAverage() {

int numberEntries = readInt(Number of entries: );

int score;

// supply the body of this method

// This method uses for-loop to receive

// n integers from the user by calling

// readInt() n times. Here, n equals to the

// numberRntries. This method also calculates

// and sets the instance variable averageScore

// to the appropriate value.

}

public double getGradeAverage() {

// supply the body of this method

// This method returns the instance variable

// averageScore.

}

}

public class TestGradeAverage {

public static void main(String[] args) {

GradeAverage gradeAverage = new GradeAverage();

System.out.println(Welcome to ICS 141 Lab 2.);

gradeAverage.calculateGradeAverage();

System.out.println(The average score for your inputs is: + gradeAverage.getGradeAverage());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!