Method to the gradebook class

Assignment Help Basic Computer Science
Reference no: EM132125920

JUnit Test Lab

You will be creating a JUnit Test Class for Gradebook.java, that has been provided for you.  

  1. Add a getScoreSize() method to the Gradebook class which returns scoresSize;
  2. Add a toString() method to the Gradebook class that returns a string with each score in scores separated by a space.

Create the Test Class GradebookTest.

  1. Select the setUp and tearDown method.
  2. Select all of the methods of Gradebook, except for the constructor to create tests for.
  3. In the setUp method of GradebookTest, create at least two objects of Gradebook of size 5. Call the addScore method for each of the Gradebook classes at least twice (but no more than 5 times).
  4. In the teardown method of GradebookTest, set the two objects of Gradebook to null;
  5. Create test for the methods of Gradebook:
  6. addScore
  7. Use the toString method to compare the contents of what is in the scores array vs. what is expected to be in the scores array

assertTrue( . . .)

  1. Compare the scoreSize to the expected number of scores entered.

assertEquals(. . .)

  1. sum
  2. Compare what is returned by sum() to the expected sum of the scores entered.
  3. minimum
  4. Compare what is returned by minimum() to the expected minimum of the scores entered.
  5. finalScore
  6. Compare what is returned by finalScore() to the expected finalscore of the scores entered.

The finalScore is the sum of the scores, with the lowest score dropped if there are at least two scores, or 0 if there are no scores.

Upload the following in a .zip file:

  1. GradeBook.java
  2. GradeBookTest.java

Example:

As a private member of GradeBookTest:

GradeBook g1;

In setup:

g1 = new GradeBook(5);

g1.addScore(50);

g1.addScore(75);

In teardown:

g1 = null;

in testSum():

assertEquals(125, g1.sum(), .0001);

in testMinimum():

assertEquals(50, g1.minimum(), .001);

in addScoreTest();

assertTrue(g1.toString().equals("50.0 75.0 ");

assertEquals(2,g1.getScoreSize());

gi.addScore(89);

assertTrue(g1.toString().equals("50.0 75.0 89.0 ");

assertEquals(3,g1.getScoreSize());

import java.util.ArrayList;

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

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

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

   /**
      Computes the sum of the scores in this gradebook.
      @return the sum of the scores
   */
   public double sum()
   {
      double total = 0;
      for (int i = 0; i < scoresSize; i++)
      {
         total = total + scores[i];
      }
      return total;
   }
      
   /**
      Gets the minimum score in this gradebook.
      @return the minimum score, or 0 if there are no scores.
   */
   public double minimum()
   {
      if (scoresSize == 0) return 0;
      double smallest = scores[0];
      for (int i = 1; i < scoresSize; i++)
      {
         if (scores[i] < smallest)
         {
            smallest = scores[i];
         }
      }
      return smallest;
   }

   /**
      Gets the final score for this gradebook.
      @return the sum of the scores, with the lowest score dropped if 
      there are at least two scores, or 0 if there are no scores.
   */
   public double finalScore() 
   {
      if (scoresSize == 0)
         return 0;
      else if (scoresSize == 1)
         return scores[0];
      else
         return sum() - minimum();
   }
}

Reference no: EM132125920

Questions Cloud

Properties and characteristics of transmission control : Explain the properties and characteristics of Transmission Control Protocol/Internet Protocol (TCP/IP).
Navigate to the classifications section of the document : Navigate to the Classifications section of the document. Select the five paragraphs listing the subtypes. Apply the open round bullet list style to the text
What is the average mips rate of the machine : a) Knowing how many clock cycles per instruction, and how long those clock cycles take, what is the average MIPS rate of the machine?
Why is threadless so successful : What competitive advantages do they have over comparable design firms using traditional strategies for product design?
Method to the gradebook class : You will be creating a JUnit Test Class for Gradebook.java, that has been provided for you.
Traditional interactive system : Scheduling algorithms are again becoming more important as we look at operating system that run on mobile devices.
Formula without using a function : In cell G7, enter a formula without using a function that divides Joan's total bonus (cell E7) by her base salary (cell B7).
The different aspects of the firms comprehensive strategy : The CEO of the firm you selected has hired your team to help address the changes the firm must make to remain competitive now and in the years ahead.
Discuss ways in which technology has changed : When you respond to others, discuss ways in which technology has changed your outlook on your career of choice.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What is the project payback period

An investment project costs $100,000. ll is expected to have an annual net cash flow of $40,000 for 5 years. What is the project's payback period?

  Determine the plaintext m from a given ciphertext

Show that it is not necessary to factor n in order to determine the plaintext m from a given ciphertext c, the public key e, and the modulus n.

  Design interface for government for identifying terrorists

As part of the design team on a major government defense project, it is time to create your first mock-up of this terrorist identification and tracking user interface.

  Why is this model predictable or unpredictable

Run the model again. Repeat this process. As you keep manipulating the parameters, do you eventually get to the point where you can predict the behavior of the model with new parameters? Explain your answer. Why is this model predictable or unpred..

  Important criteria for selecting internetwork devices

List and describe four most important criteria for selecting internetwork devices (do not list four types of network devices).

  What are the various types of malware

What are the various types of malware? How do worms differ from viruses? Do Trojan horses carry viruses or worms? ( 160 word minimum, give example of atleast one worm and virus and differences)

  Maximum number of times that an arraylist capacity increased

Suppose that when the capacity of an ArrayList is increased, it is always doubled. If an ArrayList stores N items, and started with an initial capacity of 1.

  What is the quantization error in volts

An AID converter has an input range of ±8 V. 1f the input is 7.5 V, what is the quantization error in volts and as a percent of input voltage if the converter has 8 bits, 12 bits, and 16 bits.

  Find the price and p-e ratio of the firm

a. Find the price and P/E ratio of the firm. (Do not round intermediate calculations. Round your answers to 2 decimal places.) b. Find the price and P/E ratio of the firm, if the plowback ratio is reduced to .10? (Do not round intermediate calculat..

  What do you consider the two most important software innovat

identify and describe what you believe to be the two most important hardware innovations.

  Did variable selection algorithms find the best regression

(Extra credit). Write a script that will perform all possible regressions. Did the variable selection algorithms find the best regression?

  M uses the average and maximum error of the two values. c.

A Atmega128 is being used to monitor humidity inside test chamber 03. The device uses two sensors to have some fault tolerance.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd