Reference no: EM132217553
Zoo Abstract Inheritance Lab
Objective: Students should be able to declare an abstract class. Students should be able to create more subclasses for the class. They should be able to create an array of class objects. They should be able to write a tester program to display all the functionality of their program.
It's good programming style to keep the amount of code to a minimum and to reuse existing code as much as possible. Code that is economical is easy to maintain. The concept of inheritance does just that: it illustrates a way to make code both economical and extendable.
When creating a model using inheritance, you start by defining a more general class with common instance variables and methods. The more specific classes are told to "extend" the general class. The general class then becomes the superclass and the others become the subclasses. The subclasses automatically inherit the instance variables and methods from the superclass.
The result is called the inheritance hierarchy; a simple such hierarchy is shown here. In this case, the Animal class is the superclass. It has two subclasses, Cow and Camel. (This doesn't work in reverse. A subclass can extend only one class.)
Let's model this animal hierarchy.
Write an Animal Class. This will be the superclass.
This class should be declared as abstract because we don't want to be able to create an instance of this class.
This class will have 2 attributes: a name and a sound.
Write a constructor that takes 2 parameters: name and sound.
Write accessor methods only for each attribute.
Write a toString method that prints out the attributes in the form: Spot says woof.
Write a class called Cow. A cow is an animal.
This class will not have any additional instance variables.
Define a constructor that has a name and sound as a parameter.
All methods will be inherited. You do not need to write any additional methods.
Write a class called Camel.
A camel will add an instance variable for the number of humps.
Provide a constructor that accepts 3 parameters: name, sound, and number of humps.
Write an accessor method to get the number of humps.
Override the toString method to display a message in the format: The camel bertha says spit and has 2 humps
Define your own subclass. Your subclass should be unique so be creative.
Write a class called ZooTester.java. Create an array of 5 animals and print out each animal. Be sure to test any additional methods you write.
Consider the largest positive number that could be stored
: The XYZ Computer Company made a commercially-unsuccessful computer which used 9-bit memory words. It used the 2's complement system.
|
Discuss kotters theory of change management
: HI 6005 Management and Organisations in a Global Environment - Discuss Kotter's theory of Change Management - Discuss Force-Field Analysis: giving examples
|
What information do you you need to calculate the asumptions
: Prepare a excel spreadsheet that you can use to explain your analysis of the retail listing 10660 SW 40th St, Miami, Florida, 33165.
|
Why is it good news that the disease is rare
: Why is it good news that the disease is rare? What are the chances that you actually have the disease?
|
Write an accessor method to get the number of humps
: Provide a constructor that accepts 3 parameters: name, sound, and number of humps. Write an accessor method to get the number of humps.
|
Determine the price of the bonds using given data
: When Patey Pontoons issued 8% bonds on January 1, 2018, with a face amount of $860,000, the market yield for bonds of similar risk and maturity was 11%.
|
A best guess at the number of lines of source code
: A graphic table with tasks of the full system duration will be based on your assumptions from (1) above and task dependencies.
|
Develop a tool for visualization and editing of bezier curve
: Appropriate data structures to store the curve properties (number of control points, set of control points, etc.).
|
Why would bp personnel think they could get away
: Why would BP personnel think they could get away with bribing an employee in the Russian anti-bribery prosecutor's office? If a company decides to bribe.
|