CSCE 155

Fall 2005

 

Homework Assignment 6:  The Victory Is Foreseen!

 

Assigned:  November 7, 2005

Due:  November 21, 2005

 

Note: This assignment is to be completed individually - collaboration is strictly prohibited.

Points100 points

 

Objectives

 

The objectives of this homework assignment:

  1. Familiarize with the concept of Inheritance
    1. Understand the relation between Super and Sub Classes
    2. Define reusable classes based on inheritance
    3. Appreciate the usefulness of inheritance
  2. Familiarize with the concept of Polymorphism
    1. Appreciate the usefulness of polymorphism
  1. Familiarize with the use of protected modifier
  2. Understand basic GUI objects
  3. Write a GUI application
    1. Identify the GUI objects that are necessary for the application
    2. Organize the positions and functions of these GUI objects for the application
    3. Design the application such that the user interface is sensible and user-friendly
  1. Master good programming style and design.
  2. Master code documentation, compilation, and execution
  3. Expose to Java syntax, programming styles, and Java classes

 

 Problem Description

 

The big battle is finally over. The death star has been destroyed and the rebel bases have been saved by young Jedi Luke Skywalker. However, the war is not over yet. Right before the death star was destroyed, Darth Vader is still at large. The spies have bought in news that Darth Vader is regrouping the empire’s storm troopers to attack the rebel forces. This final attack will be the end of the rebel colonies. So, it is imperative that the rebel forces regroup and prepare for the final attack.

 

During the big battle, many of the ships of the rebel forces were destroyed. Some of them also were damaged.  To reassess the current situation, Princess Leia has asked you to modify your program (Homework Assignment #5) to compute the readiness of each remaining ship in the fleet.  This time around, your program is required to take into account that for different types of ships, there are different ways of assessing a ship’s readiness.

1.  Once again, to create the simulation your program should contain two basic classes. First you should have a class ShipLog.java to hold all the information about a ship. Second, to generate the random instances of the ships you should have a class Simulator.java.  (Note: You already have these programs from Homework Assignment #5.)

 

2.      The maintenance log of each plane/ship contains at least the following information:

            (1) an ID number which is an integer (from 1-10000)

            (2) the mileage on the ship, which is a double (from 1-1000000)

            (3) the number of mechanical faults, which is an integer (1 to 100)

            (4) the number of electrical faults, which is an integer (1 to 100).

 

3.  From this basic ShipLog.java base class you will have to create three different subclasses AWing.java, BWing.java, and XWing.java for storing three different types of fighter planes. These subclasses will contain the basic information from the ShipLog.java class and also additional information specific to each type. Each of your subclasses will also have a method to assess the current situation of the starship.  Ships that are not A-Wing, B-Wing, or X-Wing will use the default method in the parent ShipLog.java class to compute their respective readiness. In general, a ship’s assessment result i.e., Readiness Index is proportional to the current rating of its attributes and inversely proportional to its mileage and to the total number faults it has.

 

The following table shows the additional information needed for each type of ships.

 

Ship

Attribute

Range

Readiness Index

A-Wing

Propulsion (p)

0-400

Maneuverability Rating (m)

0-10

Hull Integrity (h)

0-100

B-Wing

Defense Shield (d)

0-100

Gyroscope Rating (g)

0-210

Hull Integrity (h)

0-200

X-Wing

Astromech Droid Rating (a)

0-10

Hyperdrive Rating (h)

0-500

Stabilizer Rating (s)

0-1000

Maneuverability Rating (m)

0-10

 

  Note, total faults = total number of electrical faults + total number of mechanical faults

  Here you can assume that total faults > 0.

 

3.   The Simulator class also should have the GUI interface that allows the user to enter the number of random instances of ships he/she wish to generate. This GUI interface should also contain a Simulate button, a Clear button and an Exit button. When the user clicks the Simulate button, the program should generate the specified number (1-50) of random instances of both types of ships and store them in one single array. (Note:  This is similar to Homework Assignment #5.)  (Note:  That means you will have to randomly generate four types of ships: A-Wing, B-Wing, X-Wing, and undetermined.)

 

4.  The generated ShipLog objects will have random attribute values and each of the attributes of the generated ShipLog objects should be random and within the specified range (use java.util.random class). Also, do not seed the random number more than once. Your generated random numbers should be spaced far apart and must not have the same value.

 

5.   Then your program will calculate the mean, median, standard deviation of the readiness indices of all the generated ships.

 

Text Box: “Now, a Java master, you will be.”  -- Yoda6.   To view the results, your GUI should have three buttons, View A-Wings, View B-Wings, and View X-Wings. When the user clicks any one of the buttons, a pop up frame will display the details of all the generated ships. This window will contain all attribute values of each ship.  The GUI should also have a Show Overall Stat button which will show the overall statistics of the generated ships to the user in another pop up window.

 

Note that you must make use of Inheritance and Polymorphism in your program. 

 

Challenge - Extra Credit (10 points)

 

For extra credit, you are required to design a flight simulator which will simulate a hypothetical battle among the randomly generated ships.  Add a button to the main program which says Simulate Battle. When the user clicks this button, your program will randomly choose two ships from the array and compare their readiness indices. This comparison simulates the battle between the two ships. After the comparison, the ship with a higher readiness index will win. Note, each ship will fight one battle only. So, after simulating the battle between two ships these two will not be chosen again. After you have exhausted the whole array, your program will print the statistics in a pop up frame. The result frame will have the following information:

 

 

 

 

 

Ship 1

(name-id)

Ship 2

(name-id)

Ship 1’s

position

in the

main array

Ship 2’s

position

in the

main array

Readiness

Index

of Ship 1

Readiness

Index

of Ship 2

Winner

A-Wing-1233

B-Wing-3323

33

2

0.58

0.67

B-Wing-3323

 

Submission Procedure

 

This assignment is due on November 21, 2005 at the start of class.  It is highly recommended that you read the grading policy and grading guidelines on the course website for a complete explanation of how the assignments will be graded. Remember, your program should follow good programming style, include plenty of comments, and perform all of the functionality outlined above. Also, in the welcome message of your program, state whether you are implementing the extra credit functionality.

 

After completing the assignment, you must “handin” the following files on-line:

 

1.     Source files: ShipLog.java Simulator.java Awing.java BWing.java XWing.java

2.     Compiled files: ShipLOg.class Simulator.class Awing.class

             BWing.class XWing.class

3.   Screen snapshots of all your GUI windows

4.      Readme file: README.TXT

 

In addition, you must submit a stapled paper copy of your source code (and README file).  Both of these steps must be done by the start of the class on the day the assignment is due.

 

Appendix 

 1. Average of n values is defined as

 3.      Median: in ordered data set, median occurs at  (the lower median) and  (the upper median). You can just use the lower median for your homework.

4.      Standard deviation: σ , where xi is the value of a particular instance, n is the number of instances.