JMU logo

PA2: Better 9-1-1 Design (Methods)

Due: Friday, Sep 23 at 11:59 PM

Objectives

Coordinates picture

Instructions

Your Coord911.java program has been a tremendous success, and more lives than ever are being saved! To improve decision making, the dispatchers have asked you to make the following improvements:

Since the program is starting to get long, you will need to improve your PA1 submission by organizing it into multiple methods. (If you don't have a working PA1 solution, please see the instructor during office hours.) Make a copy of your PA1 source file and name it Coord911B.java. Don't forget to rename the class to Coord911B for it to compile, and while you're at it, update the @version tag. Then add the following methods to your program (above main). A major part of this assignment will be to write method documentation comments with @param and @return tags where applicable.

Both input methods display the given prompt and read a single number or line from the keyboard, returning the applicable data type. In addition, inputNumber consumes the rest of the line (i.e., the \n character). The printCoord method prints one line of the table using a format similar to PA1. See the provided test files below for more details. Note you will call printCoord three times.

Since PA2 now deals with longitude and latitude, the distances you compute will be measured in degrees. In addition, your code will need to handle coordinates in any direction from the origin: RMH Medical Center (longitude = -78.855275, latitude = 38.405139). You must declare those specific coordinates as constants in your printCoordmethod. Use Math.abs to find the absolute difference between the origin and the emergency location.

You will still have a main method as before, but it will primarily call the other methods to do most (but not all) of the work. In particular, main should NOT use the Scanner at all. As before, many variables (but not all) will be declared in main. Make sure you do not duplicate any effort between your main method and the supporting methods.

One Caveat

To divide input across multiple methods, you will need to create a single Scanner that is shared across the entire class. Copy/paste the following line directly beneath the class declaration (i.e., make it the first line inside the class):

private static Scanner input = new Scanner(System.in);

The private keyword means the variable is visible only to this class. The static keyword means the variable will be shared by all instances of the class. (We'll learn more about these concepts later in the semester.) Make sure you delete all other declaration and initialization statements for your Scanner from PA1. Otherwise, you may end up interfering with the private static variable input.

As in the previous assignment, there is no need to handle invalid user input (e.g., the user typing in a string when you're expecting a double).

Submission

Before uploading your Coord911B.java file to Webcat, be sure to complete the following steps carefully.

Your submission will be graded using the following criteria:

Requirement

Points

Quiz

10

Javadoc comments

10

Input methods

20

Print methods

20

Passes diff testing

20

Passes Checkstyle

20

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139/149, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.  You should make an acknowledgements statement in your program in the class JavaDoc to say that either you received no outside help with this assignment and this work is your own or what help you received - aka Prof Chao helped me with the PrintCoord method, or TA Casey helped me with the inputNumber method


Contact chaoaj[at]jmu.edu for more information about this page or Twitter: @chaoaj