Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Problem Statement In this lab section, you are going to learn how to use loo

ID: 3876559 • Letter: T

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 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());

                }

}

Explanation / Answer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
import javax.swing.*;

class GradeAverage {
private double averageScore;


public GradeAverage() {
averageScore = 0;
}

private static int readInt(String prompt) {
String numStr = JOptionPane.showInputDialog(prompt);
return Integer.parseInt(numStr);
}

void calculateGradeAverage() {
int numberEntries = readInt("Number of entries: ");
int score=0;
// 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.

for(int i=1;i<=numberEntries;i++)
score=score+readInt("Score"+i+": ");
averageScore = score*1.0/numberEntries;//calculating average score


}


double getGradeAverage() {
// supply the body of this method
// This method returns the instance variable
// averageScore.


return 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());
}
}

output:

run:
Welcome to ICS 141 Lab 2.
The average score for your inputs is: 86.66666666666667
BUILD SUCCESSFUL (total time: 19 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote