CSCE 155

Fall 2005

 

Homework Assignment 3:  Operation RECON DEATH STAR

 

Assigned:  September 26, 2005

Due:  October 10, 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 different types of input and output sources in Java
    1. Reading from input files
    2. Writing to output files
  2. Familiarize with re-using code
    1. Creating a similar class from an existing class
    2. Creating a new class utilizing object-oriented concepts such as data abstraction and encapsulation
  1. Familiarize with code documentation, compilation, and execution
  2. Expose to Java syntax, programming styles, and Java classes

Problem Description

Princess Leia has just received a message (via the R2D2’s control panel) from a spy that the Dark Side is now building a deadly weapon named Death Star (see picture).  The spy has informed her that this weapon has catastrophic powers and can destroy whole planets.  Princess Leia knows that it is only a matter of time the Empire would pinpoint the rebel base and destroy it using Death Star.  The only way to counter the looming attack is to identify and exploit a weakness in Death Star’s structure. To find out more about Death Star, Princess Leia is planning a reconnaissance mission.

To find the actual location of the structural weakness of Death Star, Princess Leia has decided to deploy a reconnaissance mission.  For this mission she needs to find the best recon ship in her command.  The problem is that she needs to choose the best ship for this mission from a list of many ships.  One way is to go through the lengthy maintenance logs of the ships and choose the best one.  But manually doing this is too cumbersome.  Thus, per Tatooine Pilot Safety and Testing Council’s recommendation, you have been, once again, tasked to complete a program that will go through the maintenance log and find the best reconnaissance ship.   

The maintenance bay log file has the following format.  Each line represents the maintenance bay log of a ship with the following values: (1) an ID number which is an integer, (2) the serial number of the ship, which is a string, (3) the type of the ship, which is also a string, (4) the location that the ship currently docks, which is a string, (5) the mileage on the ship, which is a double, (6) the number of mechanical faults, which is an integer, (7) the number of electrical faults, which is an integer, (8) energy consumption rate, in mega-wattage, which is a double, (9) a Boolean value that indicates whether the ship is ready to fly, and (10) an option to test either the navigation or the weapon systems of the ship (1 or 2).

Sample input file

1 Sr986655 A-WING Hanger-T 136.7 2 5 13700.5 No 1

2 TA192-XP T-WING Port-Naboo 102.0 12 4 16908.0 Yes 2

3 Apollo-13 A-WING Houston-SC 17.0 3 3 435.7 Yes 2

4 Sr934839 X-WING Tatooine-Factory 0.8 10 5 8910.5 No 1

...

...

...

 

A sample maintenance bay log file will be provided for you to test your program (please download this from the course website).

 

Specifically, your program has to provide the following for Princess Leia:

 

1.     When run, the program will first prompt the user for the name of the log file that will be used as the input to the program. 

 

2.      When the filename is entered the program will check if that file exists or not and if it is readable by the program or not.  If the file does not exist and or not readable by the program, it should display an error message and exit.

 

3.     Then the program will open the file and go through each record at a time. While going through the records, the program looks for a starship which is of type A-WING that is ready to fly, with the chosen system (either navigation (1) or weapon (2)) tested, and has the least value of the following recon-index:

 

            recon-index =  #mechanical faults + #electrical faults +

(mileage / MAX_MILEAGE) +

(energy consumption rate / MAX_ENERGY_CONSUMPTION_RATE )

 

where MAX_MILEAGE is a constant 670.00, and MAX_ENERGY_CONSUMPTION_RATE is also a constant 25000.00.

 

You may assume that at least one such ship exists in the log.

 

After identifying the best recon ship, the program must test the navigation or weapon systems of the ship (using the programs that you have completed in HW#1) according to the option specified in the 10th value of the ship’s log and print out the test results.

 

4.  The following is a sample output:

 

Welcome to the Google Search for Best Recon Ship in the Galaxy Far Far Away …

Please supply the name of the log file:  Something.txt

Report for Best Recon Ship Search:

 

Starship #:                   Apollo-13

Type:                         A-WING

Location:                     Houston-SC

Mileage:                      17.0 lightyears

# of Mechanical Faults:       3

# of Electrical Faults:       3

Energy Consumption Rate:      435.7 Megawatt/lightyear

Ready to Fly:                 Yes

Component Test:               2 (Weapon)

Testing the Weapons System...

       Primary Weapon: Four Laser Canons

       Secondary Weapon: Two Proton Torpedo Launchers

       Firing Primary Weapon: !!!!!!!!!!!!!!!!!

       Primary Weapon working

       Firing Secondary Weapon: *********

       Secondary Weapon working

Weapons System is in working condition

Weapons System Test Concluded

 

Text Box:   “Learn the I/O classes, you must.”  − YodaYour program should account for user’s mistakes (e.g. wrong file name, missing file, file name given is actually a directory, etc.). Furthermore, your program should not leave any files open once it is finished executing.  When your program opens a file for reading and writing, it should close that after the File I/O operation is completed.  Furthermore, since you are not really experienced with File I/O in Java, The Grandmaster of the Jedi Knight Council, Yoda, has also foreseen that you will need to check out the online Application Program Interface (API) for standard Java I/O classes of J2SE 1.5 at

http://java.sun.com/j2se/1.5.0/docs/api/. (See Yoda’s picture.)

 

To complete the above program, you must first write a Java class called “ShipLog.java”.  This class should describe what a log has and what one can do with it.  Basically, this will be the class that you need to instantiate to create an object to hold the data for a ship.   

 

You will also need to re-use what you have done in your assignment for the Tatooine Pilot Safety and Testing Council on a pre-flight testing system (Os.java, Navigation.java, and Weapon.java). 

You will also need to create a new application/main class called ReconShipSearch.java that will use Os.java (Hint: Think about the best way to do this.  Instantiating an Os object?).   You will also need to modify Os.java minimally such that it allows ReconShipSearch.java to run the weapon or navigation test sequence without having to interact with the user, since the system to be tested will already be supplied by the input file.

 

Supplied Solution Components

 

You may download the solution for Homework #1 Assignment and use the programs.  If you choose to do so, you are required to give proper credits to the author of the solution, both in your ReadMe file and in your programs.  You must acknowledge the author and specifically program files that you use.  You should also download the sample input file from the course web page. To work on the project, open the program in the Homework3 folder using JGrasp (or IDE of your choice). The documentation should be nice and clear, so that when other people read your program they can understand your program easily.

 

Challenge - Extra Credit (10 points)

 

Prompt the user for entering an output filename.  Then, write to the output file the following information:  (1) first, the above output (the best selected recon ship and the test results), and (2) second, the list of all the A-WING ships found in the input file.  The output file should be a text file.

 

Submission Procedure

 

This assignment is due on October 10th, 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 a 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: Navigation.java, Weapon.java, Os.java, ShipLog.java, ReconShipSearch.java

2.      Compiled files: Navigation.class, Weapon.class, Os.class, ShipLog.class, ReconShipSearch.class

3.   Screen snapshots of all your GUI or console interactions.

4.      Readme file: README.TXT (See HW1 for what should be included)

 

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.