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

  Research the process of system development life cycle

Research the process of System Development Life Cycle. Discuss how and why an organization should apply SDLC process. If you work as IT staff in an organization

  How is the auditing of application system carried out

How is the auditing of application system carried out? What are the four (4) most important specific functions of configuration management and why are they important

  Analyze the key functions a chief information officer

Analyze the key functions a Chief Information Officer (CIO) performs to define, develop, implement, and support ongoing security countermeasures

  Supply chain and purchasing processexplain the role of a

supply chain and purchasing processexplain the role of a buyer in an organizations supply chain and purchasing process.

  Write research paper about open source initiative

Write research paper about open source initiative

  Online shopping experience from dell and ford

What is the difference between the two buying experience and what are the roadblocks that make the direct model difficult to implement at Ford

  What delivery method is most effective for speakers

What delivery method is most effective for speakers? Why should speakers deliver the first sentence from memory? What five issues should be resolved before a team can collaborate productively?

  What sort of add-on vocabularies can you purchase

Research the Web for automatic speech recognition (ASR) systems. What sort of add-on vocabularies can you purchase? How comfortable would you feel speaking the contents of a term paper as opposed to typing it

  The use of a decision support systemwould using a decision

the use of a decision support systemwould using a decision support system in a business guarantee a better decision?

  Cash provided by collection from customers

During 2014, stewart company reported revenues on an accrual basis of $70,000. accounts receivable decreased during the year from $35,000 at the beginning to $24,000 at the end. how much cash was provided by collection from customers during the ye..

  Describe characteristics of an internal accounting system

Describe the objectives and characteristics of an internal accounting system and Include an explanation of the importance of this information to the company.

  How itil framework minimize the impact of change

ITIL stands for the Information Technology Infrastructure Library. ITIL is the international de facto management framework describing "good practices" for IT Service Management.

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