Create a program using the principles of inheritance

Assignment Help JAVA Programming
Reference no: EM131199595

Animal characteristics

In today's fast-paced world, it is important for programmers to think about potential future changes that impact their programs. One way that software developers can address this concern is by designing programs that are easy to upgrade and are adaptable to new technologies. In this Application, you work toward this goal by writing a program that uses the concept of inheritance to allow for later additions.

Create a program using the principles of inheritance based on the following scenario:

Scenario: The teachers of a local school need a program to teach their students the basics about animals and their characteristics. The teachers want the program to contain a database of animals, from which the teachers can choose animals to add to a list. The list will be displayed on the students' monitors so they can study the animals and their characteristics. Right now, the teachers want a program that handles only mammals and birds, but in the future they may want to add other types of animals. The teachers also expect the program to run smoothly and be thoroughly tested to handle extraneous input.

Create a program that fulfills the specifications outlined in the scenario above. Use the concept of inheritance to allow for later additions to the program. Also use the TDD concepts from Unit 1 to test the program as you go.

Follow the steps below to create the program:

Create a class Animalwith these variables:

- public String kind;
- public String integument;

Add these methods:

- public String movement(boolean fast)returns one of the two strings "I walk on four legs."or"I run on four legs."depending on whether fastis falseor true, respectively.
- public String sound()returns the empty string.

Create two classes, Mammaland Bird, each of which extends Animal.

In the constructor for Mammal, set the variable integumentto the string "hair". Do not declare the variable again; it has already been declared in Animal. Similarly, in the constructor for Bird, set integumentto the string "feathers".

In the Birdclass, override the movementmethod to return either "I walk on two legs."or"I fly."depending on the setting of the fastparameter. Use the @Overrideannotation.

Create additional classes to represent specific kinds of animals (each extends either Mammalor Bird). In each class, set the kindvariable and override the sound()method. For example, you might create a Duckclass, setting the kindto "duck"and overriding the sound()method to return the string "‘quack'" (in single quotes).

Note: Remember to test the methods as you go. Use the principles of TDD that you examined in Unit 1. The methods you write in this program are simple and only return strings, so they are relatively easy to test.

Users should be able to create animals of any kind you have defined (duck, cow, etc.), but you should also prevent the user from creating a "plain" animal, because there's no such thing. Every animal has to be a specific kind. Do this by writing a factory method inthe Animalclass-that is, a method to create objects of various animal kinds. Here's how:

- First, prevent users from creating a "plain" animal by writing a no-argument constructor for Animal, but making it private.
- Second, write a method Animal newInstance(String kind)that takes the desired kind of animal (such as "duck"), calls the constructor for that particular kind of animal, and returns the result. If given an unrecognized string, the method should not crash; it should return null.

Your test of the newInstancemethod must verify that the objects it creates are equal to objects created by calling the appropriate constructor (for instance, new Duck()) directly. Testing equality (that is, calling assertEquals) requires an equalsmethod in the Animalclass. There are five different characteristics that should be equal for two animals to be equal-their kinds, their integuments, their slow and fast movements, and the sounds they make. You don't need to test for every kind of animal you define, but you should test at least one kind of bird and one kind of mammal. Also, don't forget to test the newInstancemethod with an unrecognized (or misspelled) kind of animal.

Write a printmethod in your Animalclass. When called, it should print out all the information about "this" animal, for instance:

I am a duck.
I have feathers.
When I go slowly, I walk on two legs.
When I go fast, I fly.
The sound I make is ‘quack'.

Note that the sound of the animal has single quotes around it when you see it displayed in the output of your program. The sound method returns a string which contains a single quote, the sound, and then another single quote.

Write a class called AnimalStuffcontaining a mainmethod. In this class, define an ArrayListof Animal.

In case you are not familiar with ArrayList, you need to import java.util.ArrayListand your declaration should look something like

ArrayList<Animal>myList = new ArrayList<Animal>();
Although a normal array has a fixed size which you specify, an ArrayListdoes not and can grow as elements are added to it. You can find more information about ArrayListin the Java API.

An ArrayList<Animal>can hold a mixture of all kinds of animals.

Finally, in your main class, write a loop asking the user which of three things to do: Add an animal of a chosen type to the list, print(every animal in) the list, or quit the program. If the user asks for an animal your program doesn't recognize, don't add nullto the list, but do inform the user of the problem.

Use a Scanner(import java.util.Scanner) to read input from the user. First, create a Scannerobject:

Scanner scanner = new Scanner(System.in);

Then, to read a word typed in by the user, you can use the following:

String word = scanner.next();

To read in an entire line, use:

String line = scanner.nextLine();

To read in an integer, use:

int number = scanner.nextInt();

To read in a floating-point number, say:

doublefpNumber = scanner.nextDouble();

Please give detail comments and Include screenshots of the program running as part of your submission. Show five valid animals being added and two invalid animals trying to be added. Also show screenshots of the printed list after each animal is added. Include screenshots of your program being tested with JUnit.

Save your NetBeans Project and screen shots of the working program as a ".zip" file

Verified Expert

This assignment describe the use of the arraylist and the creation of the type of the animal as per the kind of animal provided. This code also handled unrecognized animals also. Junit test caess are also provided to verify the functionality of the code attached. It also contains the screenshot of the output as well as of the Junit test cases.

Reference no: EM131199595

Questions Cloud

Summarize threats from the external environmental scan : Your SWOT analysis should summarize the opportunities and threats from the external environmental scan with the strengths and weaknesses from your organizational assessment or internal environmental scan.
Typical profile of a venture champion : What is the typical profile of a venture champion?  What do we know about them?  What makes the successful?
Some of apple biggest successes and failures : Case Analysis  Apple Computer: Research how Apple managed to reinvent itself over the years. Answer the following questions: What were some of Apple's biggest successes and failures? Describe why.
Find the output response for each of the systems : Find the output response, c (t), for each of the systems shown below.-  Also find the time constant, rise time, and settling time for each case.
Create a program using the principles of inheritance : Create a program using the principles of inheritance - The teachers of a local school need a program to teach their students the basics about animals and their characteristics. The teachers want the program to contain a database of animals, from wh..
Relation to the hierarchy of service styles : Common variables and characteristics of food and beverage service systems are explained in relation to the hierarchy of service styles?
Write a document of six pages that addresses the given tasks : Find a case study that discusses procurement, and then discuss and analyze the procurement cycle. Using the library, Internet, and your course materials, write a document of 5-6 pages that addresses the above tasks.
Two relationships between elements-subsystems and system : Glades County is a region on the Gulf Coast with a... Glades County is a region on the Gulf Coast with a population of 600,000. About 90 percent of the population is located in and near the city of Sitkus. The main attractions of the area are its cle..
Design capacity of screw pumps : In selecting screw pumps in polder scheme projects, what are the factors that affect the design capacity of screw pumps?

Reviews

len1199595

9/9/2016 2:24:33 AM

Please give detailed comments and Include screenshots of the program running as part of your submission. Show five valid animals being added and two invalid animals trying to be added. Also show screenshots of the printed list after each animal is added. Include screenshots of your program being tested with JUnit.

Write a Review

JAVA Programming Questions & Answers

  Develop class which implements interface

Let the ADT called SquareMatrix. (The matrix can be represented by 2-D array of ints w/ n rows and n columns.) Write specification for ADT as Java interface. Develop the class which implements interface.

  Write a program that specializes in solving the equations

Write a program that specializes in solving the equations Ax=b by Doolittle's decomposition method, where a is the HIbber matrix of arbitrary size nxn and

  Calculate the kilometers

Write a program called MilesToKilometers that converts miles to kilometers. Read the miles value from t he user as a double point value. Calculate the kilometers

  Design a program that extends the definition of the class

Design a program that extends the definition of the class JFrame to display a window on the screen. Name your class PropertyTax1, title your window "Calculation of Property Taxes," set the window's width to 400 pixels and height to 300 pixels, and te..

  What should a comment at the class level contain

How do you identify a comment so the Javadoc tool will recognize it and what should a comment at the class level contain?

  Flowchart create a flowchart that prompts

Flowchart Create a flowchart that prompts and gets input for the current grade. If the grade is 90 or above print "A". If the grade is 80-89 then print "B". If the grade is 70-79 then print "C".

  Explain the inventory program to include an add button

Modify the Inventory Program to include an add button, a delete button, and a modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock

  Create a new project in bluej by clicking on the menu option

Create a new project in BlueJ by clicking on the menu option Project > New project. This will create a folder with the project name (see below). All BlueJ project-related files for this project will be stored in this folder. Create new classes by ..

  Create a testrectangle class that tests both constructors

An overloaded constructor that takes integer width and height arguments, uses a separate method to check whether the width and height fall within the range between 0 and 30, and throws an exception if out of range.

  Create application in java programming

Write method multiple that determines, for a pair of integers, whether the second integer is a multiple of the first.

  Create an abstract class named element

Part 1: Create an abstract class named Element that holds properties of elements, including their symbol, atomic number, and atomic weight. Include a constructor that requires values for all three properties and a get method for each value.

  Write a java program that creates three threads

The reader-writer problem can be stated as given: A shared memory location can be concurrently read by any number of tasks, but when a task must write to the shared memory location, it must have exclusive access.

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