weight = 19
Overview
For this lab, you will revise your Lab 8 solution
by introducing arrays of Dog
s in the DogWalkingService
class.
Assignment
The previous version of the DogWalkingService
class you implemented
was limited in that you could only walk three dogs. Things have been
going great, and you've decided to open a business and handle more
than three dogs.
The following diagram shows the revised API that you are to implement. Detail on each change is given below.
Dog |
-name: String {readOnly} -prefersFastWalks: boolean {readOnly} -solidProductionRate: int {readOnly} -totalWalks: int -totalTimesPeed: int -totalTimesPooped: int +DOG_NAMES: String[] = {"Spot", "Spotless", "Yippee", ...} {readOnly} |
+Dog() +Dog(name: String) +Dog(name: String, prefersFastWalks: boolean, solidProductionRate: int) +getName(): String +walk(lengthInMinutes: int, isFast: boolean): boolean +getNumberOfWalks(): int +getTotalTimesPeed(): int +getTotalTimesPooped(): int +toString(): String -makePluralIfAppropriate(quantity: int, word: String): String |
Changes to Dog
You will need to make the following changes to your Dog
class:
- Add a class constant that is an array of at least ten potential dog names.
- Add a no-arg constructor that will select a name for the dog at random from the array of dog names.
- Add a
makePluralIfAppropriate()
method that can be used to ensure that thetoString()
method makes use of the correct pluralization of words. For example, instead of "Spot is a slow walker who peed 48 times and pooped 1 times.", it should produce "Spot is a slow walker who peed 48 times and pooped 1 time."
DogWalkingService |
-dogs: Dog[] {readOnly} -numberOfDogs: int -successCount: int -numberOfWalks: int -totalMinutes: int |
+DogWalkingService(capacity: int) +enrollDog(dog: Dog): boolean +removeDog(index: int): Dog +getSummary(): String +walk2Dogs(minutes: int): boolean +walk2Dogs(minutes: int, isFast: boolean): boolean +walkAllDogs(minutes: int): boolean +walkAllDogs(minutes: int, isFast: boolean): boolean +getNumberOfWalks(): int +getTotalMinutesWalked(): int +getNumberOfSuccessfulWalks(): int +getDogs(): Dog[] +getNumberOfDogs(): int +getSpacesLeft(): int |
Changes to DogWalkingService
The dogs
array is used to keep track of all the dogs managed by the dog walking service.
The dogs should be added to the array from left to right. For example, if there are two
dogs being managed by the service, they should be stored in index 0 and 1 of the dogs
array.
You will need to make the following changes to your DogWalkingService
class:
- Remove the instances to individual
dog1
,dog2
, anddog3
and replace them with an array ofdogs
. - Add an attribute to keep track of the number of dogs enrolled. Note that the service should start with no dogs. The
enrollDog()
method must be used to add dogs to the service. - Replace the old constructor with one that accepts a capacity that will determine the length of the
dogs
array. - Add methods to enroll and remove a dog from the service.
enrollDog(Dog dog)
should adddog
todogs
, unless there are no spaces left. The method returnstrue
if and only if the dog was added to the dog walking service.removeDog(int index)
should remove the dog at the specified index and shift all dogs after index one spot to the left.
- Add a method to get all of the dogs enrolled in the service.
- Add a method to get how many dogs are currently enrolled.
- Add a method to get how many additional dogs can be enrolled before the service reaches capacity.
- Update the remaining methods to work with the array of
dogs
instead ofdog1
,dog2
, anddog3
.
Program
You must design the Lab9
class that is a program that:
- Asks the user how many dogs they would like to walk.
- Creates a
DogWalkingService
object that can support 25% more dogs than the user would like to walk. - Adds randomly named dogs to the
DogWalkingService
instance until there are as many dogs as the user wants to walk enrolled in the walking service. - Asks the user how many walks they would like to take today.
- Conducts the walks.
- Displays a summary of the results.
Acknowledgement
This laboratory assignment was developed by Dr. Chris Taylor.