Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93113386
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Computer Engineering

A 2-year treasury security currently earns 197 percent over

A 2-year Treasury security currently earns 1.97 percent. Over the next two years, the real risk-free rate is expected to be 1.00 percent per year and the inflation premium is expected to be 0.60 percent per year. Calcula ...

Biodiversity refers to the variety of living organisms

Biodiversity refers to the variety of living organisms found within an ecosystem. In your description, evaluate the role of humans in the current biodiversity loss situation and increased species extinction rate. In addi ...

Q2 what layer uses encryptiondecryptiona what is

Q2. What layer uses encryption/decryption? a. What is encryption? Q3. What addressing system is used at Data Link layer? a. How long is the address? Is it Physical or logical? b. Is it unique or not unique?

Scheme questionthe following program can be used to

Scheme Question The following program can be used to determine if a given interpreter is using applicative-order evaluations or normal-order evaluation: (define (p)(p)) (define (test x y) (if (= x 0) 0 y)) (test 0 (p)) ( ...

Which sentence would work better as a thesis statement for

Which sentence would work better as a thesis statement for a three-to-five-page college paper? Remember that a thesis should be a central idea that requires supporting evidence; it should be of adequate scope for essay's ...

Youve entered a contract to purchase a new house and the

You've entered a contract to purchase a new house, and the closing is scheduled for next week. It's typical for some last-minute bargaining to occur at the closing table, where sellers often try to tack on extra fees. Yo ...

Systems analysis project personal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Construct a frequency distribution for the number of

Construct a frequency distribution for the number of different residences occu-pied by graduating seniors during their college career, namely 1, 4, 2, 3, 3, 1, 6, 7, 4, 3, 3, 9, 2, 4, 2, 2, 3, 2, 3, 4, 4, 2, 3, 3, 5

Are there manufacturers and retailers who have taken steps

Are there manufacturers and retailers who have taken steps to reduce their pollution impact, both air quality and industrial pollution, while maintaining a viable place in the market?

Question suppose you have created a program that creates

Question : Suppose you have created a program that creates instances of different types of cars. Now you are creating a program that keeps track of different types of cars. Choose the abstract classes and concrete classe ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As