Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is about Java! please help this. thank you! Objective: To successfully be able to apply the programming concepts, you have learned from previous lectures

this is about Java! please help this. thank you! image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Objective: To successfully be able to apply the programming concepts, you have learned from previous lectures and labs in this class up to this point, in writing a code (program) that runs with no errors and gives the correct output. Skills needed: Knowledge of programming concepts from previous lectures and labs in this class up to this point. Needed the most are: Inheritance, Interfaces, Abstract Classes, and Arraylists. Hands on Eclipse. Task: 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(); 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(); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak(); System.out.println(animal); 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-ChungerUnits%5): What does this do? Why does this stop infinite loops? Hunger Level Chart Hunger Units Hunger Level Name Hunger Level 0-4 Full 5-9 Peckish Hungry 10-14 15-19 20-24 Very Hungry Starving 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. 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 The Output from the simulator might look something like this: 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 2 cluck cluck cluck Yellow the Chicken is Hungry woof woof Teddy the Dog is Peckish moo Jenny the Cow is Full Jackie the Cow is Full duck Doly the Chicken is Full Fido the Dog is Ful Feeding 3 cluck cuck Yelow the Chicken is Peckish woof wool Teddy the Dog is Peckish moomoo Jenny the Cow is Peckish Jackie the Cow is Full Dolly the Chicken is woof Fido the Dog is Ful Feeding 4 cluck cuck Yellow the Chicken is Peckish moomoo Jackle the Cow is Peckish cluck Dolly the Chicken is wool Fido the Dog is Full Teddy the Dog is Full Jenny the Cow is Full Feeding 5 cluck dluck Dolly the Chicken is Peckish woof wool Fido the Dog is Packish woof Teddy the Dog is Full Jenny the Cow is Full cluck Yelow the Chicken is Ful Jackie the Cow is Full Feeding 5 cluck cluck Dolly the Chicken is Peckish woof woof Fido the Dog is Peckish woof Teddy the Dog is Full moo Jenny the Cow is Full cluck Yellow the Chicken is Full moo Jackie the Cow is Full Feeding 6 woof Teddy the Dog is Full moo Jenny the Cow is Full cluck Yellow the Chicken is Full moo Jackie the Cow is Full cluck Dolly the Chicken is Full woof Fido the Dog is Full Your programs and all further programs should have program description header that goes at the top of the file which gives information about the programmer and program. // Name: Bob Programmer // Section: A, B, or 5 // Program Name: Hello world // Description: A brief description of the program. What does the // program do not how it does it: for example, it uses loops)? Does // the program get input? What kind? What information is output // from the program and to where (screen or file) //// import

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

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions