Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Any help would be appreciated! Thanks, in advance! Here's what I have so far in my main class. There should be 5 total classes (Main

Any help would be appreciated! Thanks, in advance!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Here's what I have so far in my main class. There should be 5 total classes (Main class, Animal superclass, and classes for dog, cat and cow)

// Enum type for food

enum FoodType { BONE, SALMON, GRASS }

public class Farm_Client

{

// Constants for food costs

final static double grassCost = 1.0;

final static double boneCost = 3.0;

final static double salmonCost = 5.0;

// Random number generator

private static Random r = new Random();

public static void main(String[] args)

{

// For autograding purposes - setting seed (read in from command line)

// so random always generates same numbers

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;

// It is used to reproduce the output in the Project writeup

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

}

// TODO: Insert your 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;

}

}

Description Unfortunately, Old MacDonald has begun to lose his vision! However, he still has a keen sense of hearing and would like to keep working on the farm. Every few days, he gets called in to feed the animals at a new farm. Old MacDonald must visit each stall in the barn, call out at the animal in the stall, and discern what type of animal he hears. Then, when he identifies the animal as a cat, dog or cow, he'll feed that animal its favorite food until it is no longer hungry. Old MacDonald knows that cats especially like salmon, dogs love a good bone to chew on, and cows enjoy fresh grass. Each feeding costs money (salmon-S5, bone-S3, grass-S1) and an animal can require multiple feedings. Thus, Old MacDonald will leave a bill for the farm keeper at the end of his visit

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 J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago