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

  Licensing proprietary technology to foreign

licensing proprietary technology to foreign competitorsdiscuss this statement licensing proprietary technology to

  Develop an operational feasibility study

Develop an operational feasibility study. Evaluate whether the web site will enable Wow Munchies to gain market share. Describe what factors will affect the operational success of this web site

  Packets routers and ip addresses

Packets, Routers and Private vs Public IP Addresses - The solution shows packets, routers and IP addresses. In terms of security, private IP address is favored over public IP address. However, Public IP addresses is favored in terms of commercial b..

  Operations management - processes and supply chain

Identify processes that one can personally evaluate and impact within the relatively short duration of time, say about 6 weeks and Describe each process in terms.

  Types of forecasting

We have spent quite a bit of time studying the types of forecasting including producing some useful computer based models. For this individual project, find a "peer reviewed" article that involves the use of one or more forecasting techniques

  Organizational impacts of implementing the strategic plan

positive organizational impacts of implementing the strategic plan. Justify your response. and Specify the current situation of the company with regard to its technology and security aspects

  How are the companies in business protecting users

How are the companies in this business protecting their users from such assaults, and how can these companies improve the security of online classifieds?

  Describe the activities within the information systems area

Describe the integrative functions and activities within the information systems area, including the role of the CIO and technologies managed within the organization.

  Build a forecasting model

Build a forecasting model. Assume a linear regression forecasting model and build a model for each of the five games

  About globalized professionals

globalized professionals

  Pros and cons of social networking

Pros and Cons of Social Networking

  Summarize the importance of an administrative plan

Answer each question with at least 300 words. Assignment is a total of 900Words Apa format references required. Summarize the importance of an Administrative Plan. Summarize the importance of a Crisis Management Plan.

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