Question
Could really use some help. Thank you!!!!! // Enum type for food enum FoodType { BONE, SALMON, GRASS } public class Farm_Client { // Constants
Could really use some help. Thank you!!!!!
// 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
// 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
{
// Create new stall (ArrayList) of animals
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
{
// Create new stall (ArrayList) of animals containing a Dog, Cat & Cow, each with a requirement of 5 servings
ArrayList
newStallArrangement.add(new Dog(5));
newStallArrangement.add(new Cat(5));
newStallArrangement.add(new Cow(5));
return newStallArrangement;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started