JMU logo

PA1: 9-1-1 Coordinates (Basic I/O)

Map with coordinates

Due: Friday, Sep 9 at 11:59 PM

Objectives

Getting Started

9-1-1 calls are answered across the United States by dispatchers and assisted by a variety of computer systems. Some of these systems are sophisticated enough to include automatic detection of the location of the caller, and others are as simple as recording in the system the basic details of the call as entered by the dispatcher. The information is then sent out to any ambulance, fire, or hospital personnel that may be involved in addressing the emergency.

You will be modeling a very simple system that will allow the dispatcher to enter the caller's first and last name, their preferred name, the code the dispatcher determines for the identifying the emergency, and the caller's x-coordinate and y-coordinate relative to the location of the first responders. For this exercise, we will assume that the first responders for all emergencies are at the local rescue squad and that they only respond to calls to the North and East of them, allowing only for positive coordinates. You will be responsible for writing a program to enter the data collected by the dispatcher, compute the "helicopter" distance and the "by land" distance, and then display all of the information in a specific format as shown.

If you would like to see more details on emergency response, see this wikipedia page. Current systems are much more sophisticated than what we are asking you to implement here. If you are interested in seeing some research on algorithms for locating ambulances and determining response times, check out this paper from 2015. Don't worry if you don't understand everything, but note that these researchers are claiming that they can reduce travel-time to emergency requests by almost 30%. That saves lives – pretty cool!

See the example input and output below for the general idea. Create a new source file named Coord911.java and implement the entire program in the main method. Provide a meaningful Javadoc comment, including @author and @version tags, and remove unnecessary comments such as "add your code here." Write concise inline comments (using //) for each major section of the assignment described below (e.g., gathering input, doing calculations, displaying output). You should have these comments in place before writing any code!

Reading Input

Your program will need to read and store a variety of information while displaying the prompts as shown in the following example:

Enter caller's first name: 
Pat
Enter caller's last name: 
Burgess
Enter caller's "preferred" name: 
Pattie
Enter caller's street address: 
470 Linda Lane
Enter emergency code: 
fire02
Enter caller's age: 
48
Enter caller x-coordinate: 
4
Enter caller y-coordinate: 
10.5

Specifically:

  1. Read the caller's first name and last name separately. Remember that some names have spaces in them.
  2. Read the caller's preferred name (or nickname), and then separately read the caller's street address.
  3. Read details of the emergency that the dispatcher identified. (For this assignment, people will never have more than one emergency.)
  4. Each emergency has an alphanumeric code, i.e., a single word with a reasonable number of letters and digits.
  5. Read in the caller's age. This will always be a whole number.
  6. Read the x-coordinate. This is the distance to the east that a caller is from the rescue squad. It can be a decimal value or a whole number, is measured in kilometers, and is always positive.
  7. Read the y-coordinate. This is the distance to the north that a caller is from the rescue squad. It can be a decimal value or a whole number, is measured in kilometers, and is always positive.

To get started, declare variables with meaningful names and types. Initialize a Scanner to handle the input, and use System.out.print to display each prompt exactly as shown. There is no need to handle invalid user input in this assignment.

Writing Output

Use the collected data to display a caller alert that matches the following example exactly as shown. Put a tab character (but no other spaces) between each column of the code table.

Pat Burgess
Date: 09/09/16
Age: 48
Nickname: Pattie
Street Address: 470 Linda Lane

CODE    X       Y
----    -       -
fire02  4.0     10.5

By Land Distance: 14.5
Helicopter Distance: 11.236102527122116

Specifically:

  1. Display the caller name (first name followed by last name).
  2. Display the assignment deadline in mm/dd/yy format.
  3. Display the age of the caller.
  4. Display the preferred name of the caller.
  5. Display the street address of the caller's location.
  6. Display the details of the emergency code and location the dispatcher entered, separated by tabs.
  7. Calculate and display the "by land" distance:
    x-coord + y-coord
  8. Calculate and display the "helicopter" distance:
    square root of (x-coord squared + y-coord squared)
  9. Print a blank line before and after the entire alert.

Note that you may see strange results like 59.900000000000006 instead of 59.90. We will learn in the next assignment how to deal with this problem. For now, you must simply print all values as-is. (Don't try to round, truncate, or format them to two decimal places.)

Submission

Before uploading your Coord911.java file to Webcat(this will be used to grade the checkstyle porition automatically, and/or Canvas[you may upload here if you cannot get a webcat submission to work, but will lose points], be sure to complete the following steps carefully.

  1. Run Checkstyle and eliminate ALL warnings about your code. Review and update comments as needed.

  2. Make sure all variables are declared at the beginning of the main method, before any other statements.

Your submission will be graded using the following criteria:

Requirement Points
Javadoc and comments 15
Variable names / types 15
Prompts and data input 20
Accurate calculations 10
Output and formatting 10
Passes Checkstyle 20
Quiz PA1-A 10

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.


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