Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Need this in java with 3 methods) Objectives: To test the class using unit testing frameworks Task: Provide Unit test class StudentTest with three test

(Need this in java with 3 methods)

Objectives: To test the class using unit testing frameworks

Task: Provide Unit test class StudentTest with three test methods, each of which tests a different method of the Student class attached with the assignment

Student Class:

public class Student { private double[] scores; private int scoresSize;

/** Constructs a student with no scores and a maximum number of scores. @capacity the maximum number of scores for this student */ public Student(int capacity) { scores = new double[capacity]; scoresSize = 0; }

/** Adds a score for this student. @param score the score to add @return true if the score was added, false if there was no room to add the score */ public boolean addScore(double score) { if (scoresSize < scores.length) { scores[scoresSize] = score; scoresSize++; return true; } else { return false; } }

/** Gets the position of the minimum score. @return the position of the smallest element of values, or -1 if there are no scores. */ public int minimumPosition() { if (scoresSize == 0) { return -1; } int smallestPosition = 0; for (int i = 1; i < scoresSize; i++) { if (scores[i] < scores[smallestPosition]) { smallestPosition = i; } } return smallestPosition; }

/** Computes the sum of the scores @return the total score */ public double sum() { double total = 0; for (int i = 0; i < scoresSize; i++) { total = total + scores[i]; } return total; }

/** Removes a score at a given position. @param pos the position of the score to remove */ public void removeScore(int pos) { // Remove the element at this position--see Section 7.3.6 scores[pos] = scores[scoresSize - 1]; scoresSize--; } }

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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions