Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Software Engineering Expert

Application: 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.

For this Application:

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 Animal with 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 fast is false or true, respectively.

• public String sound() returns the empty string.

Create two classes, Mammal and Bird, each of which extends Animal.

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

In the Bird class, override the movement method to return either "I walk on two legs." or "I fly." depending on the setting of the fast parameter. Use the @Override annotation.

Create additional classes to represent specific kinds of animals (each extends either Mammal or Bird). In each class, set the kind variable and override the sound() method. For example, you might create a Duck class, setting the kind to "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 in the Animal class-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 newInstance method 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 equals method in the Animal class. 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 newInstance method with an unrecognized (or misspelled) kind of animal.

Write a print method in your Animal class. 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 AnimalStuff containing a main method. In this class, define an
ArrayList of Animal.

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

ArrayList myList = new ArrayList();

Although a normal array has a fixed size which you specify, an ArrayList does not and can grow as elements are added to it. You can find more information about ArrayList in the Java API.

An ArrayList 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 null to 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 Scanner object:

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:

double fpNumber = scanner.nextDouble();

Include screenshots of your 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.

Software Engineering, Computer Science

  • Category:- Software Engineering
  • Reference No.:- M92183867
  • Price:- $65

Priced at Now at $65, Verified Solution

Have any Question?


Related Questions in Software Engineering

Write review on this article with apa formatgovernment

Write review on this article with APA format. Government surveillance is a major issue in the United States and globally. Surveillance refers to any collection and processing of personal data, whether, identifiable or no ...

Research projectin the course we have covered various

RESEARCH PROJECT In the course, we have covered various security and privacy issues that arise in the cyberspace field. We have learned to identify these risks and have discussed the current approaches and developments f ...

In this assignment you will answer the following review

In this assignment, you will answer the following review questions from the reading materials of the module/week. 1. "What are the key components of a typical P2P application? Describe their functions." 2. "What are the ...

Instructions - onion routingin this assignment you will

INSTRUCTIONS - ONION ROUTING In this assignment, you will answer the following questions related to Onion Routing and Tor. 1. Describe the infrastructure of Onion Routing and explain how it works for providing anonymity ...

In this assignment you will answer the following questions

In this assignment, you will answer the following questions related to Android platform and Android security design. 1. Describe Android architecture in detail by explaining the four conceptual layers. 2. Describe Androi ...

Overviewyou are required to modify and logically extend

Overview You are required to modify and logically extend the functionality of a provided code base to implement a game. This requires you to modify the code base as well as create documentation and implement various user ...

Proposaldesign of an efficient gps tracking system tag for

Proposal Design of an efficient GPS Tracking System (tag) for monitoring small species IMPLEMENTING EMBEDDED SYSTEMS USING SYSML Task Using PapyrusSysML Software (Downloadable online - Evaluation Copy- Latest Version) Mo ...

Assignment part 1objectives to learn to identify the

Assignment Part 1 Objectives: To learn to identify the relevant use cases for a given application, describe the use cases and develop an object-oriented domain model. Problem Statement - Standing Orders Management System ...

Reply to this article with apa referencehate crimes

Reply to this article with APA reference. Hate crimes According to Merriam-Webster, hate crime is any of various crimes (such as assault or defacement of property) when motivated by hostility to the victim as a member of ...

Write reply to this article with references with apa

Write reply to this article with references with APA bibliography. Hate Crimes Over the past couple of years, hate crimes have been on the rise in America's largest cities. Studies show that there were sharp spikes in th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As