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

Write a BowlingGame class per the UML diagram attached. Then complete the Measur

ID: 669365 • Letter: W

Question

Write a BowlingGame class per the UML diagram attached.

Then complete the MeasurableDemo.java class as directed in the code comments.

EXTRA CREDIT: Modify BowlingGame to implement the Comparable interface and
illustrate its correct implementation by modifying the MeasurableDemo
to sort the array. (Printout array before and after call to sort.)

Here is the pseudocode:

https://myasucourses.asu.edu/bbcswebdav/pid-11612991-dt-content-rid-56258287_1/courses/2015Fall-W-ACO102-70446/UMLBowlingGameMeasurable.pdf

Here is the two bits of code that I was given

and

Explanation / Answer

MeasurableDemo.java

import java.util.Arrays;

/**
This program demonstrates the measurable interface for Bowling Games.
*/
public class MeasurableDemo
{
public static void main(String[] args)
{
   BowlingGame[] games = new BowlingGame[3];
   games[0] = new BowlingGame(85);
   games[1] = new BowlingGame(77);
   games[2] = new BowlingGame(94);
   System.out.println("Before Sorting: " + Arrays.asList(games));
   Arrays.sort(games);
   System.out.println("After Sorting: " + Arrays.asList(games));
System.out.printf("Average of these scores is %f", average(games));

}

/**
Computes the average of the measures of the given objects.
@param objects an array of Measurable objects
@return the average of the measures
*/
public static double average(Measurable[] objects)
{
if (objects.length == 0) { return 0; }
double sum = 0;
for (Measurable obj : objects)
{
sum = sum + obj.getMeasure();
}
return sum / objects.length;
}
}

_______________________________________________________________________________________

Measurable.java

/**
Describes any class whose objects can be measured.
*/
public interface Measurable
{
/**
Computes the measure of the object.
@return the measure
*/
double getMeasure();
}

________________________________________________________________________________________

BowlingGame.java

/**
* A BowlingGame has a score.
*/
/* TO DO modify the class to implement the interface Measurable */
public class BowlingGame implements Measurable, Comparable
{
   /**
   * Constructs a bowling game with a given score.
   *
   * @param initialBalance
   * the initial score
   */
   public BowlingGame(int initialScore)
   {
       score = initialScore;
   }
   /**
   * Gets the score of the bowling game
   *
   * @return the score
   */
   public int getScore()
   {
       return score;
   }
   /*** Hint: Provide the method body for the method defined in the interface */
   public double getMeasure()
   {
       return score;
   }
   private int score;
   @Override
   public int compareTo(Object o) {
       return score - ((BowlingGame)o).score;
   }
   public String toString(){
       return String.format("%d", score);
   }
}

____________________________________________________________________________________

Output:

Before Sorting: [85, 77, 94]
After Sorting: [77, 85, 94]
Average of these scores is 85.333333

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