You must create a very simple farm simulation. The simulation will run in a loop and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You must create a very simple farm simulation. The simulation will run in a loop and call a method that indicates the passage of time. YOU MUST USE A GENERIC CONTAINER such as ArrayList. The Generic it has must be some form of the base class ANIMAL such as: ArrayList farm = new ArrayList < Animal >(); 1. Create an Animal Class that will be the base class for all your animals: All animals have some level of hunger from 0-24. 2. When an animal is instantiated, it should randomly pick some number of hunger units between 0 and 24. (in the constructor) 3. Since it is a small farm all animals have their own name. 4. All animals must be able to be fed (decrease their hunger units by 5 when they are fed). 5. Animals must increase their hunger as time goes on: create a method that increases their hunger by 1 unit of hunger. 6. In the loop example below tick() is used since the method relates to the virtual passing of time. While in this case all that happens is the hunger level increases other simulators might have much more complex effects. public static void main(String[] args) { ArrayList farm = new ArrayList (); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak()); System.out.println(animal); Feeding 1 cluck cluck cluck cluck Yellow the Chicken is Very Hungry woof woof woof Teddy the Dog is Hungry moo moo Jackie the Cow is Peckish cluck cluck Dolly the Chicken is Peckish moo Jenny the Cow is Full woof Fido the Dog is Full 7. When printed an animal should indicate. The animal's name, the type of the animal and the animal's hunger level: "Ely the cow is very hungry". 8. If we are never going to instantiate an Animal directly what type of class could we make it? Explain. Put your answer in the comments at the bottom of your report. Note: It is possible that when you run the simulation it will loop infinitely*. Can you explain why? Put your answer in the comments at the bottom of your report * For larger sets of animals this would almost always happen. You could put this in the constructor: hungerUnits = hungerUnits-(hungerUnits%5); What does this do? Why does this stop infinite loops? Hunger Level Chart Hunger Units 0-4 5-9 10-14 15-19 20-24 Hunger Level Name Full Peckish Hungry Very Hungry Starving Hunger Level 0 1 2 3 4 Feeding 2 cluck cluck cluck Yellow the Chicken is Hungry woof woof Teddy the Dog is Peckish moo Jenny the Cow is Full moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full 9. Create 5 subclasses of farmyard animals: a. Each animal should also speak based on what type of animal it is and how much they speak should change with their hunger level. A cow might "moo" b. The calculation for the times speaking will be different for each subclass c. The calculation for the first five animal subclasses should be: i. First Animal Class: (Hunger Level + 1) * 2 i. Second Animal Class: (Hunger Level + 1) ii. Third Animal Class: ((Hunger Level / 2) + 1) * 2 iv. Fourth Animal Class: (Hunger Level * 3) v. Fifth Animal Class: Hunger Level + 2 10. Create a class with a main method a. that instantiates 2 of each or your animals and put them in an ArrayList. Sort the animals by their hunger level (most hungry to least hungry). b. Allow each animal to speak, print it out and then feed it if it is not full. Continue this process until all of them are full. Feeding 3 cluck cluck Yellow the Chicken is Peckish woof woof Teddy the Dog is Peckish moo moo Jenny the Cow is Peckish moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full 11. Implement a sleeping feature. All animals have a 10 percent chance of falling asleep when they are fed. Side Effects of sleeping: 1. Animals that are asleep do not decrease their hunger units when fed. 2. Animals that are asleep "Snore" when then speak instead of their normal vocalization. 3. Animals wake up if their Hunger Level changes Feeding 4 cluck cluck Yellow the Chicken is Peckish moo moo Jackie the Cow is Peckish cluck Dolly the Chicken is Full woof Fido the Dog is Full woof Teddy the Dog is Full moo Jenny the Cow is Full You must create a very simple farm simulation. The simulation will run in a loop and call a method that indicates the passage of time. YOU MUST USE A GENERIC CONTAINER such as ArrayList. The Generic it has must be some form of the base class ANIMAL such as: ArrayList farm = new ArrayList < Animal >(); 1. Create an Animal Class that will be the base class for all your animals: All animals have some level of hunger from 0-24. 2. When an animal is instantiated, it should randomly pick some number of hunger units between 0 and 24. (in the constructor) 3. Since it is a small farm all animals have their own name. 4. All animals must be able to be fed (decrease their hunger units by 5 when they are fed). 5. Animals must increase their hunger as time goes on: create a method that increases their hunger by 1 unit of hunger. 6. In the loop example below tick() is used since the method relates to the virtual passing of time. While in this case all that happens is the hunger level increases other simulators might have much more complex effects. public static void main(String[] args) { ArrayList farm = new ArrayList (); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak()); System.out.println(animal); You must create a very simple farm simulation. The simulation will run in a loop and call a method that indicates the passage of time. YOU MUST USE A GENERIC CONTAINER such as ArrayList. The Generic it has must be some form of the base class ANIMAL such as: ArrayList farm = new ArrayList < Animal >(); 1. Create an Animal Class that will be the base class for all your animals: All animals have some level of hunger from 0-24. 2. When an animal is instantiated, it should randomly pick some number of hunger units between 0 and 24. (in the constructor) 3. Since it is a small farm all animals have their own name. 4. All animals must be able to be fed (decrease their hunger units by 5 when they are fed). 5. Animals must increase their hunger as time goes on: create a method that increases their hunger by 1 unit of hunger. 6. In the loop example below tick() is used since the method relates to the virtual passing of time. While in this case all that happens is the hunger level increases other simulators might have much more complex effects. public static void main(String[] args) { ArrayList farm = new ArrayList (); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak()); System.out.println(animal); Feeding 1 cluck cluck cluck cluck Yellow the Chicken is Very Hungry woof woof woof Teddy the Dog is Hungry moo moo Jackie the Cow is Peckish cluck cluck Dolly the Chicken is Peckish moo Jenny the Cow is Full woof Fido the Dog is Full Feeding 1 cluck cluck cluck cluck Yellow the Chicken is Very Hungry woof woof woof Teddy the Dog is Hungry moo moo Jackie the Cow is Peckish cluck cluck Dolly the Chicken is Peckish moo Jenny the Cow is Full woof Fido the Dog is Full 7. When printed an animal should indicate. The animal's name, the type of the animal and the animal's hunger level: "Ely the cow is very hungry". 8. If we are never going to instantiate an Animal directly what type of class could we make it? Explain. Put your answer in the comments at the bottom of your report. Note: It is possible that when you run the simulation it will loop infinitely*. Can you explain why? Put your answer in the comments at the bottom of your report * For larger sets of animals this would almost always happen. You could put this in the constructor: hungerUnits = hungerUnits-(hungerUnits%5); What does this do? Why does this stop infinite loops? Hunger Level Chart Hunger Units 0-4 5-9 10-14 15-19 20-24 Hunger Level Name Full Peckish Hungry Very Hungry Starving Hunger Level 0 1 2 3 4 7. When printed an animal should indicate. The animal's name, the type of the animal and the animal's hunger level: "Ely the cow is very hungry". 8. If we are never going to instantiate an Animal directly what type of class could we make it? Explain. Put your answer in the comments at the bottom of your report. Note: It is possible that when you run the simulation it will loop infinitely*. Can you explain why? Put your answer in the comments at the bottom of your report * For larger sets of animals this would almost always happen. You could put this in the constructor: hungerUnits = hungerUnits-(hungerUnits%5); What does this do? Why does this stop infinite loops? Hunger Level Chart Hunger Units 0-4 5-9 10-14 15-19 20-24 Hunger Level Name Full Peckish Hungry Very Hungry Starving Hunger Level 0 1 2 3 4 Feeding 2 cluck cluck cluck Yellow the Chicken is Hungry woof woof Teddy the Dog is Peckish moo Jenny the Cow is Full moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full Feeding 2 cluck cluck cluck Yellow the Chicken is Hungry woof woof Teddy the Dog is Peckish moo Jenny the Cow is Full moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full 9. Create 5 subclasses of farmyard animals: a. Each animal should also speak based on what type of animal it is and how much they speak should change with their hunger level. A cow might "moo" b. The calculation for the times speaking will be different for each subclass c. The calculation for the first five animal subclasses should be: i. First Animal Class: (Hunger Level + 1) * 2 i. Second Animal Class: (Hunger Level + 1) ii. Third Animal Class: ((Hunger Level / 2) + 1) * 2 iv. Fourth Animal Class: (Hunger Level * 3) v. Fifth Animal Class: Hunger Level + 2 10. Create a class with a main method a. that instantiates 2 of each or your animals and put them in an ArrayList. Sort the animals by their hunger level (most hungry to least hungry). b. Allow each animal to speak, print it out and then feed it if it is not full. Continue this process until all of them are full. 9. Create 5 subclasses of farmyard animals: a. Each animal should also speak based on what type of animal it is and how much they speak should change with their hunger level. A cow might "moo" b. The calculation for the times speaking will be different for each subclass c. The calculation for the first five animal subclasses should be: i. First Animal Class: (Hunger Level + 1) * 2 i. Second Animal Class: (Hunger Level + 1) ii. Third Animal Class: ((Hunger Level / 2) + 1) * 2 iv. Fourth Animal Class: (Hunger Level * 3) v. Fifth Animal Class: Hunger Level + 2 10. Create a class with a main method a. that instantiates 2 of each or your animals and put them in an ArrayList. Sort the animals by their hunger level (most hungry to least hungry). b. Allow each animal to speak, print it out and then feed it if it is not full. Continue this process until all of them are full. Feeding 3 cluck cluck Yellow the Chicken is Peckish woof woof Teddy the Dog is Peckish moo moo Jenny the Cow is Peckish moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full Feeding 3 cluck cluck Yellow the Chicken is Peckish woof woof Teddy the Dog is Peckish moo moo Jenny the Cow is Peckish moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full 11. Implement a sleeping feature. All animals have a 10 percent chance of falling asleep when they are fed. Side Effects of sleeping: 1. Animals that are asleep do not decrease their hunger units when fed. 2. Animals that are asleep "Snore" when then speak instead of their normal vocalization. 3. Animals wake up if their Hunger Level changes 11. Implement a sleeping feature. All animals have a 10 percent chance of falling asleep when they are fed. Side Effects of sleeping: 1. Animals that are asleep do not decrease their hunger units when fed. 2. Animals that are asleep "Snore" when then speak instead of their normal vocalization. 3. Animals wake up if their Hunger Level changes Feeding 4 cluck cluck Yellow the Chicken is Peckish moo moo Jackie the Cow is Peckish cluck Dolly the Chicken is Full woof Fido the Dog is Full woof Teddy the Dog is Full moo Jenny the Cow is Full Feeding 4 cluck cluck Yellow the Chicken is Peckish moo moo Jackie the Cow is Peckish cluck Dolly the Chicken is Full woof Fido the Dog is Full woof Teddy the Dog is Full moo Jenny the Cow is Full
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Deuterium ( ) is an attractive fuel for fusion reactions because it is abundant in the oceans, where about 0.015% of the hydrogen atoms in the water (H 2 O) are deuterium atoms. (a) How many...
-
Identify three goods for which your demand is (a) Elastic and (b) Inelastic. What accounts for the differences in elasticity?
-
Give the remainder after N terms of a convergent alternating series.
-
Mind & Motion entered into a real estate purchase contract (REPC) with Celtic Bank to buy a large piece of the banks foreclosed property. Although the county had approved plans to construct...
-
The Southwick Company has the following balance sheet ($000): Financial Ratios Current ratio ........ 1.92 Quick ratio ....... 1.08 Debt-to-equity ratio ...... 0.79 Evaluate the impact of each of the...
-
Formulate your answer based on the information below. The intensity of care delivered dropped from a budgeted case mix of 0 . 9 0 to an actual case mix of 0 . 8 5 . What dollar effect did this have...
-
Prepare the retained earnings statement by dragging and dropping the appropriate accounts into their correct sections. Revenue Service Revenue Expenses Kleene Window Washing Inc. Income Statement For...
-
Write a paper on Evaluation of media portrayals of people with psychological disorders.
-
Safety is everybody's job and responsibility. Identify four (4) ways you can contribute to a safe workplace and remain current in relation to workplace systems, equipment and processes?
-
A local commercial bank purchased a Commercial Crime Coverage Form with Inside the Premises--Theft of Money and Securities Coverage. There is a limit of $250,000 and a deductible of $10,000. A...
-
Mary receives a base salary of $2,500 on the 1st of each month. She claims S-0. On May 1st, she received $2,500. On May 15, she received a $500 bonus. On May 29, she receives a second bonus of...
-
McAllister University, a private, nonprofit university, receives a letter from an alumnus who pledges $1,500,000 to be used for accounting research, 95% of which is expected to be collected based on...
-
Goals Project 2 Practice using loops and conditional structures Practice the use of strings
-
Write a summary about a star other than our Sun. Indicate its basic properties and where it currently is in its life cycle.
-
If the annual fixed costs are 54,000 dinars, the occupation expense represents 20%, the contribution margin is 25%, and the unit selling price is 40 dinars. Required: Calculate the closing point of...
-
The expense of opening a secret offshore bank account is an example of the excess burden of US income taxes. Indicate whether each statement is true or false, and justify your answer.
-
Preventative care refers to care taken to prevent future diseases rather than to treat current ones. Compared with ER care, preventative care is rarely urgent, and benefits can be difficult to...
-
At firms that do not provide health insurance, the wages of obese workers are lower than the wages of non-obese workers with similar levels of productivity. Indicate whether each statement is true or...
-
Goods are products a business sells like a. haircuts. b. conveyer belts. c. car insurance. d. health care.
-
Which of the following are the factors of production? a. Labor, natural resources, capital, entrepreneurs, technology, and intellectual property b. Labor, capital, entrepreneurs, motivation, and good...
-
Which of the following is a current sociocultural trend? a. A decrease in the overall U.S. population b. An increase in the population of Americans ages 30 to 45 years old c. A decrease in the U.S....
Study smarter with the SolutionInn App