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

A Slightly Larger Class With 3 Data Items - The SeaHawksTracker Class This class

ID: 3674849 • Letter: A

Question

A Slightly Larger Class With 3 Data Items - The SeaHawksTracker Class

This class is to be used to track the performance of the Seahawks as they experience multiple SuperBowls in their outstanding career. Note that all SuperBowls are not the same, and so we’ll need to store the scores for each of the three times the SeaHawks have been to the SuperBowl in three distinct variables defined inside our SuperBowl class. This is similar to the Point2D class, but instead of the variables “x” and “y” we’ll need a third variable – if we were making a Point3D class, we’d call this variable “z”. Here, well name the variables so they are self-documenting, and so we’ll need names that reflect their intended use here, such as “firstScore”, “secondScore” and “thirdScore”. This class will not only be able to print out the 3 scores by calling a superbowl report method (called toString()), but you will arrange the three values in order by making some helper functions to determine the minimum() and maximum() of the three scores. I’ve included a main to help you test your SeaHawkTracker class, which contains 3 data items and a number of methods defined below. Note that you are not allowed to use Math.max() or Math.min(), and also not allowed to call Arrays.sort() or use any external classes here at all – that is to say, you must build this all from scratch. Chapter 4 discusses basic class design, so you may want to read that if concepts here don’t make sense.

--Data Items--

a. Define three integers as fields with the names “firstScore”, “secondScore” and “thirdScore”

--Methods--

a. Define 3 getter methods for firstScore, secondScore and thirdScore.

b. Define 3 helper methods for determining…

--The minimum of three integers, called min(a,b,c)

--The maximum of three integers, called max(a,b,c)

--The middle of three integers, called mid(a,b,c)

c. One method to report on the games played called toString()

Sample Main

public static void main(String[] args) {

     SeaHawksTracker stats = new SeaHawksTracker();

     stats.setFirstScore(22);

     stats.setSecondScore(11);

     stats.setThirdScore(27);

         

     System.out.println("---------Min, Mid, & Max----------");

     System.out.println("The largest is:" + stats.max(3,5,1));

     System.out.println("The middle is:" + stats.mid(3,5,1));

     System.out.println("The smallest is:" + stats.min(3,5,1));

         

     System.out.println(" ---------Report of Scores--------");

     System.out.println(stats.toString());   

}

Sample Output for the SeaHawksTracker Class!!

---------Min, Mid, & Max----------

The largest is:5

The middle is:3

The smallest is:1

---------Report of Scores--------

The first score was:22

The second score was:11

The third score was:27

The least of the SeaHawks' scores was:11

The middle of the SeaHawks' scores was:22

The greatest of the SeaHawks' score was:27

Getting Started

Create a new class in your Editor, and call it “SeaHawksTracker”. We’ll want to build this new class in steps rather than all at once, so we’ll start with the familiar getters/setters and then move on to the helper methods we need (min, mid, max) that we’ve seen in other homeworks or labs, and then try something new in the toString() function, which will build a string of the scores in ascending order. Note that the toString() function needs to call the min(), mid() and max() function to get full credit.

If this is BlueJ, notice how it provides examples of data and methods for you.

Define some data items inside the class definition but outside of any method so it is a field.

You’ll need 3 distinct integer variables to track the three different superbowl scores that the SeaHawks have earned.

Define your methodsJust like you’ve defined “getters” and “setters” for data items in previous classes for x and for y, you’ll need 3 getters and 3 setters for each of the scores defined in this class.

public int getFirstScore() { //finish this

public void setFirstScore(int sc)

//similar getter for the second score

//similar setter for the second score

//similar getter for the third score

//similar setter for the third score

You’ll need a min() and max() method that can determine the smallest and largest of three distinct numbers, similar to exercises you’ve done in previous labs and homeworks.

public int min(int a, int b, int c) //return the smallest of a,b, and c

public int max(int a, int b, int c) //return the largest of a,b, and c

Next, you’ll need a function that determines the middle element given three integers, called min(). Note that you can build mid() multiple different ways, but the approach that reuses methods you’ve already written is probably the best.

public int mid(int a, int b, int c) { //return the middle of a,b, and c

The last function you’ll be creating is called toString(), and it’s job is to return a string printout of the three variables (firstScore, secondScore, or thirdScore) in ascending order (use of the min(), mid() and max() functions you built previously).

Note that the toString() function needs to call the min(), mid() and max() function to get full credit.

Explanation / Answer

SeaHawksTracker.java

public class SeaHawksTracker {

private int firstScore;

private int secondScore;

private int thirdScore;

  

   public int getFirstScore()

   {

       return firstScore;

   }

  

   public int getSecondScore()

   {

       return secondScore;

   }

  

   public int getThirdScore()

   {

       return thirdScore;

   }

  

   public void setFirstScore(int score)

   {

       firstScore=score;

   }

  

   public void setSecondScore(int score)

   {

       secondScore=score;

   }

  

   public void setThirdScore(int score)

   {

       thirdScore=score;

   }

  

public int max(int a,int b,int c)

   {

       if(a>b)

       {

           return a>c?a:c;

       }

       else if(b>c)

       {

           return b;

       }

       return c;

   }

  

public int min(int a,int b,int c)

   {

       if(a<b)

       {

           return a<c?a:c;

       }

       else if(b<c)

       {

           return b;

       }

       return c;

   }

  

public int mid(int a,int b,int c)

   {

       int max=max(a,b,c);

       int min=min(a,b,c);

      

       if(a==max || a==min)

       {

           if(b==max||b==min)

           {

               return c;

           }

           else

           {

               return b;

           }

       }

       else

       {

           return a;

       }

   }

  

   public String toString()

   {

       String s="The first score was:"+getFirstScore()

                   +" The second score was:"+getSecondScore()

                   +" The third score was:"+getThirdScore()

                  +" The least of the SeaHawks scores was:"+min(firstScore,secondScore,thirdScore)

                  +" The middle of the SeaHawks' scores was:"+mid(firstScore,secondScore,thirdScore)

                  +" The greatest of the SeaHawks' score was:"+max(firstScore,secondScore,thirdScore);

       return s;

   }

}

sample output

---------Min, Mid, & Max----------

The largest is:5

The middle is:3

The smallest is:1

---------Report of Scores--------

The first score was:22

The second score was:11

The third score was:27

The least of the SeaHawks scores was:11

The middle of the SeaHawks' scores was:22

The greatest of the SeaHawks' score was:27