Make a Project Involving Java Program

Health & Medical
Price: $20 USD

Question description

Part 2: Interfaces and Abstract Classes

You are to write an inheritance hierarchy that defines the behavior of birds. You will be given a program that runs an aviary simulation of a world with many birds flying around in it.

For this assignment you will be given supporting code that runs the simulation. You are just defining the individual birds that wander around this world. This program will probably be confusing at first because this is the first time where we are giving you a specific client program. Your code will not be in control of the whole application. Instead, you are defining a series of objects that become part of a larger system. For example, you might find that you want to have one of your birds make several moves all at once. You won’t be able to do that. Although this experience can be frustrating, it is a good introduction to the kind of programming we do with objects. A typical Java program involves many different interacting objects that are each a small part of a much larger system.

Each bird has a (x,y) position and a color, and each bird can fly. Different kinds of birds will fly in different ways and you are defining those differences. We are dividing this assignment into tasks to assist you with the design:

1. Your first task is to write an interface called Bird to represent different types of birds. The interface should have methods to do the following:

  1. Get the bird’ s color.

  2. Get the bird’ s (x,y) position as a Point.

  3. Tell a bird to fly. Each time a bird is told to fly, it will move its position once.

Your Bird interface should work with the Aviary client program we provide (you can download it from LA TTE). Based on the Aviary program you should figure out yourselves the correctnamesandreturntypesforyourBirdmethods. TheAviaryclientprogramisusingthe DrawingPanelclass that is also available on LATTE. All .java files we provide should be placed in the same folder with your own source files.

We are also providing an interface AviaryConstants (also available on LATTE) that includes two static constants needed from creating the simulation window for your flying birds. You will probably use one or both them in your own classes.

public interface AviaryConstants {
// the size of the Aviary, x and y coordinates run from 0 to 19


public static final int SIZE=20;

// the number of pixels corresponding on one x and y coordinate unit // i.e., you aviary areas has a size of 200x200 pixels
public static final int PIXELS=10;

2. If some of the methods of your interfaces are the same for all birds, you should implement an abstract class (e.g., AbstractBird) to hold the behavior that will be common to all bird classes. Also, if there are some fields common to all birds (e.g., color, etc) , you should place them in this abstract class. Please justify your choice in the readme.txt file.

You should explain in your readme file why you choose to have or not to have an abstract class.

3. Write a class called Cardinal that represents cardinals. A cardinal is red in color. The cardinal’s movement is vertical. Initially a cardinal is moving up. Each time the cardinal is told to fly, it will move its position one unit upward on the y-axis (remember that upward is negative – see Hint 2). If the cardinal hits the edge of the aviary (a y-coordinate of 0 or 19), it turns around and flies in the opposite direction. Remember that the size of your aviary is 20 and is stored as a static constant in the AviaryConstants interface.

4. Write a class called Hummingbird that represents hummingbirds. A hummingbird is magenta in color. Its movement is random: each time the hummingbird is told to fly, it will pick a new random (x,y) position in the range of (0,0) to (19,19).

For the random moves, you may use either a Random object or the Math.random() method to obtain pseudorandom values.

5. Write a class called Bluebird that represents bluebirds. A bluebird is blue in color. Its movement is in a zig-zag pattern. Initially the bluebird faces right. The bluebird moves in an alternative pattern of up-right, down-right, up-right, down-right, and so on until it hits the right edge of aviary (x-coordinate of 19), at which point it turns around. Subsequent calls to fly will cause the bird to move up-left, down-left, up-left, down-left, and so on until it hits the left edge of the aviary. In other words the Bluebird always alternates between up/down in the y-axis.

6. Write a class name Vulture that represents vultures. A vulture is black in color. Its movement is in a counter-clockwise circle pattern. Initially the vulture faces up. The first time it

flies it moves up by one, then it turns to face left. Its second move, it moves left by one and turns to face down. Its third move, it moves down and turns to face right. Its fourth move, it moves right by one and turns to face up. The pattern repeats in this fashion.

Hint 1: To represent the color of each bird you can use the Color class of the java.awt package. Each color (BLACK, RED, WHITE, YELLOW) has an explicit value which you can get it with the statement Color.<name of color>. E.g., Color.BLACK returns the value for black. You should look up the Color class on the Java API to see the full list of available colors and decide which one you need to use.

Hint 2: In graphics upwards direction is negative. This means that the origin point (0,0) is at the top-left corner of your screen and the y-coordinates increase as you move towards the bottom of your screen. So, if you want a point to move upward you have to reduce its y-coordinate.

Running your program: To test if your classes work you should run the Aviary class. You may change (for testing/debugging purposes) the client program but keep in mind that we will test your classes with the program we gave you, so you should make sure your classes work with our version. 

Tutor Answer

(Top Tutor) Daniel C.
School: UCLA
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1819 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors