Show how inheritance relation will be reflected in java code

Assignment Help Management Information Sys
Reference no: EM131018354

Inheritance

One of the topics covered this week is "Inheritance". The chapter shows the Person/Employee example, what are some other examples that could use Inheritance? Read section 12.3-12.4 and come up with your own example of inheritance. Do not copy the examples from the textbook or other sources. Explain your example in a paragraph or two, longer if you need to. After you do that, you must show how the inheritance relation will be reflected in Java code. In other words, you are not required to write a complete set of classes and their contents, but at the minimum you must show the inheritance relation between the various classes that make up your example.

Directions

The files must be called cLnFnUnitS.java> (driver program) LnFnAnimal.java

LnFnFox.java (which extends LnFnAnimal) LnFnChicken.java (which extends LnFnAnimal)

The files must be called as specified above, (LnFn = Your Last Name Your First Name. For example the Instructor will create GuillermoTonsmannFox.java and others similarly.)

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.

Only submit the Java files needed to make the program run. Do not submit the .class files or any other files.

Basic Requirements and Driver class

Use this class hierarchy: Fox and Chicken are children classes of the Animal class. A Fox

• Will kill 1 chicken a day
• Does not reproduce

A Chicken

• Have a chance to reproduce as long as conditions are met
• Reproduction only happens when chickens are over 1 and 1 of each sex is present

The simulation control inside the main method on LnFnUnit5 will do the following:

• Simulation will continue as long as chicken population is greater than 1 and less than or equal 10 (if 1 or less, mating can't happen. If > 10, chickens will overrun the fox)

Driver main method should be as shown below: (replacing comment with missing output piece and replacing LnFn with your initials. Add prologue and additional comments to explain functionality.)

import java.util.ArrayList;
public class LnFnUnit5 {
public static void main(String args) { for(int count=0; count<10; count++) { LnFnFox foxy = new LnFnFox();
ArrayList< LnFnChicken > chickens = new ArrayList<LnFnChicken>();

chickens.clear();

chickens.add(new LnFnChicken()); chickens.add(new LnFnChicken 0);

chickens.add(new LnFnChicken 0); chickens.get(0).setSex(true);
chickens.get(1).setSex(false);
chickens.get(2).setSex(false);
while (chickens.size() >1 && chickens.size() < 10) { for (LnFnChicken c:chickens) c.grow();
foxy.grow();
LnFnChicken.mate(chickens); foxy.eat(chickens);
}
//INCLUDE CODE FOR OUTPUT HERE. }II end of for
} // end of main
} // end of class

The program will output one of the following messages:

Chickens win - Chicken Population: 14

(if chicken population is greater than or equal to 10, t/c/4 is an integer value) OR

Fox wins - Fox Weight (in chickens): #14.144

(if chicken population is less than 10, *kg* is a double value, 2 decimal places)

Because the output will be inside the main for loop, the output will be repeated 10 times. See sample output below.

Remember to use get and set methods in all classes whenever you want to obtain (get) or change (set) any of the attributes of your objects.

LnFnAnimaljava class

The Animal class will have the following attributes:

• name

age (an integer number that represents the days of age)

weight (a double number that represents a weight in pounds)

maleSex (a boolean variable that is true, if the Animal is male, false otherwise)

All attributes should be private and each one should have public appropriate accessor (get) and mutator (set) methods.

A default constructor will initialize the age of every Animal to 1 day.

The Animal class should also have a method named grow with no parameters that increases the age of the Animal by one.

LnFnFox.java class

LnFnFox constructor: (default constructor)

It sets the fox's age to a random number between 400 to 900 days.

It sets the fox's weight to a random number between 30 to 60 pounds. It randomly sets the fox's sex.

The Fox class will include the method named eat to do the following: eat method: It receives an Arraylist of Chicken objects as argument.

It randomly removes a chicken from the population 70% of the time and increases fox weight by the chosen chicken weight. It only increases the fox's weight if the chicken is removed/eaten.

LnFnChicken.java class

LnFnChicken constructor: (default constructor)

It sets the chicken's age to 1 day and the chicken's weight to 1 pound.

It randomly sets the chicken's sex.

The Chicken class will include the following methods:

grow method:

It overrides the grow method from the Animal class to increase the chicken's age by 1 and the chcicken's weight by 1% of its current weight.
mate method: An static method that receives an Arraylist of Chicken objects as argument.

It randomly chooses 2 Chicken objects from the Arraylist and if conditions are correct, it proceeds with mating.
Successful mating conditions are:

- 1 male and 1 female chicken

- Both chickens older than 1 day

§ If successful mating occurs, create a random number (between 0 to 4 ) of new Chicken objects, and append them to the Arraylist received as argument.

Reference no: EM131018354

Questions Cloud

How a standard such as the ois model assists networks : The developers of the OSI model envisioned a detailed specification of interfaces. Instead, it has become a common reference model that is used by developers to standardize interfaces. Give your opinion on what you believe would happen to networks..
A company has an average inventory : A company has an average inventory on hand of $75,000 and its average days in inventory is 36.5 days. What is the cost of goods sold?$1,680,000$750,000$876,000$1,752,000
Adoption of a different inventory method : A lack of disclosure about guaranteed payments that were mentioned in the MD&A of the annual report.Maintenance costs are capitalized and then depreciated.
As a spectator at a professional baseball game : Plaintiff, Barry Cohen, complaining that he, as a spectator at a professional baseball game, was injured by a ball thrown by pitcher, sought in a battery count and in a negligence count to recover damages from the pitcher and his employer. On Septemb..
Show how inheritance relation will be reflected in java code : One of the topics covered this week is "Inheritance". The chapter shows the Person/Employee example, what are some other examples that could use Inheritance? Read section 12.3-12.4 and come up with your own example of inheritance. Do not copy the ..
What is the depreciation expense for year 2 : On January 1, a machine with a useful life of five years and a residual value of $40,000 was purchased for $120,000. What is the depreciation expense for year 2 under the double-declining-balance method of depreciation?
Identifying an organization''s mission : The strategic management 6-step process starts with identifying an organization's mission and the next step is to analyze the external and internal organizational environments to perform a SWOT (Strengths, Weaknesses, Opportunities and Threats) analy..
Explain how zappos has implemented social : Explain how zappos has implemented social responsibility programs into its business
Compare a public network to a private network : Explain the various privacy rights that businesses on the Web are lawfully obligated to adhere to. Describe some of the gray areas in enforcing these laws on the Internet.

Reviews

Write a Review

Management Information Sys Questions & Answers

  Student query information systemsthink of your ideal

student query information systemsthink of your ideal company. it can be anything you want but you must assume the

  What are the characteristics of a failed information systems

What are the characteristics of a failed information systems project? Describe the alternatives for sourcing a new information system. What are the benefits of the different approaches to sourcing a new system?

  Analyze the key information management

Prepare a PowerPoint presentation where you describe and analyze the key information management and quantitative techniques/statistics that you recommend for the new plant

  Explain about network architecture department

Network Architecture Department - The Network Architecture department must be focused on the networking technology required to support other organizational departments

  What do you think is the likelihood of the risk occurring

DTGOV uses Microsoft Office 2010 as its office productivity suite and Microsoft Exchange 2010 for email. What do you think is the likelihood of the risk occurring

  Explain remote user authentication

Explain Remote User Authentication and What are the 3 generations of firewalls, explain the evolution of them from Generation 1 to 2 to 3.

  Develop an introduction to the security policy outline

Develop an introduction to the security policy outline - answer of the given assignment.

  What data is being collected when a product is scanned

In a supermarket scanner system, what data is being collected when a product is scanned

  Project quality and compliance

Project Quality and Compliance

  Dail-up technologyis dial-up a dying technology if so how

dail-up technologyis dial-up a dying technology? if so how will companies like aol survive? if not what do you envision

  What internet business model would be appropriate

What Internet business model would be appropriate for the company to follow in creating a Web site and why?

  Methods of information systems conversion

Implementation Methods of Information Systems Conversion - Describe the four implementation methods (parallel, plunge, pilot, & phased) of information system conversions.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd