Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have all of the subclasses done. I'm looking for help with the output code. The last two pics show what the output should look

I have all of the subclasses done. I'm looking for help with the output code. The last two pics show what the output should look like. All relevant code is listed below. The spot I need help with is bolded below (under second test case) and should utilize an ArrayList. Let me know if you need any addition information. Thanks for any help you can give!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

public static void main(String[] args)

{

if (args.length > 0)

r.setSeed(Long.parseLong(args[0]));

// Decimal format class for printing out any prices

DecimalFormat df = new DecimalFormat("$0.00");

for (int i = 0; i

{

// An ArrayList of animals in the stalls

ArrayList stalls;

// This test case will be executed during FIRST iteration;

if (i == 0)

{

System.out.println("----------CASE 1: generateDogCatCow5ServingArrangement() Output----------");

stalls = generateDogCatCow5ServingArrangement();

}

else

{

int numAnimals = 10;

// This test case will be executed during SECOND iteration;

// It is used to generate a random test case

System.out.println("-------------CASE 2: generateRandomStallArrangement() Output-------------");

stalls = generateRandomStallArrangement(numAnimals);

}

// Insert code here which causes Old MacDonald (this client code) to

// visit each of the stalls. Old MacDonald should speak to each animal to determine

// what type of food to feed it. All along the way, he keeps track of what types

// of animals and how much of each type of food he is using.

// End of test

System.out.println("E-I-E-I-O! ");

}

}

/////////////////////////////////////////////////////////////////////////////////

// DO NOT EDIT

// This method generates a stall with numAnimals which are generated randomly.

// In addition, the number of feedings required per animal are set randomly as

// a number between 1 and 10.

/////////////////////////////////////////////////////////////////////////////////

private static ArrayList generateRandomStallArrangement(int numAnimals)

{

// Create new stall (ArrayList) of animals

ArrayList newStallArrangement = new ArrayList();

// Generate numAnimals new animals

for (int i = 0; i

{

int randAnimal = r.nextInt(3); // (Dog = 0, Cat = 1, Dog = 2)

int numFeedings = r.nextInt(10)+1; // 1-10 feedings required per animal

if (randAnimal == 0)

newStallArrangement.add(new Dog(numFeedings));

else if (randAnimal == 1)

newStallArrangement.add(new Cat(numFeedings));

else

newStallArrangement.add(new Cow(numFeedings));

}

return newStallArrangement;

}

/////////////////////////////////////////////////////////////////////////////////

// DO NOT EDIT

// This method generates a stall with a dog, cat and cow, which each need five

// servings of food.

/////////////////////////////////////////////////////////////////////////////////

private static ArrayList generateDogCatCow5ServingArrangement()

{

// Create new stall (ArrayList) of animals containing a Dog, Cat & Cow, each with a requirement of 5 servings

ArrayList newStallArrangement = new ArrayList();

newStallArrangement.add(new Dog(5));

newStallArrangement.add(new Cat(5));

newStallArrangement.add(new Cow(5));

return newStallArrangement;

}

}

Requirements The main objective in this project is to gain experience with and demonstrate an ability to use inheritance and polymorphism. Your project MUST contain the following 5 classes (yes, you will be turning in 5 files, but they are pretty simple) which adhere to the following requirements: NOTE: Templates for each of the classes can be found online. All classes should remain in the default package, like you've been doing (do NOT separate the client and animals into different packages or change any package names) Class 1: Animal This is the animal super class. It MUST contain the following instance variables: Instance Variable Description protected int numberOfFeedings; A protected variable (can be accessed directly by subclasses) which indicates how many feedings the animal has had private int numberOfRequiredFeedings; A private variable (only the animal supelass can directly access) which indicates how many feedings the animal needs to no longer be hun In addition, the animal super class MUST have the following methods Method Header Description Animal(int feedingsRequired) public void feed (FoodType ft) public String speak() Animal constructor. Sets numberOfRequiredFeedings to feedingsRequired and sets numberOfFeedings to 0 These methods are mostly left unimplemented by the super class and should always be overridden. Print out an error message in case it is called. (Try using System.err.printlnO) Returns TRUE if animal has received a number of feedings less than its required number of feedings and FALSE otherwise public boolean isStillHungry()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago