CS139 Algorithm Development

Software Requirements Specification

Programming Assignment 2

Stars and Planets

Due Monday, October 5th by 11:00pm


Introduction

Purpose: This program is designed to display the relative order of stars to the earth and planets to the sun.

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites

You have covered the material in Chapter 3 and 5 of Gaddis.  

Background

The closest star to earth is the Sun.  The next 9 stars in relative order are
Proxima Centauri – 4.22
Alpha Centauri A – 4.37
Alpha Centauri B – 4.37
Barnard's Star – 5.96
Wolf 359 – 7.78
Sirius A – 8.58
Sirius B- 8.58
Luyten-8 A – 8.73
Luyten-8 B – 8.73
Source: http://www.universetoday.com/guide-to-space/earth/what-is-the-closest-star-to-earth/

The relative order of the planets from the Sun are
Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
(Pluto is no longer considered a planet)
Source: http://www.enchantedlearning.com/subjects/astronomy/planets/

Example

If you wanted to know the 2nd closes star to earth the answer would be Proxima Centauri.  The 4th planet from the Sun is Mars.

Program Behavior

Your application must be named Stars

Your application must do these things:

  1. Your program will prompt for and read two input values.  They are:
    1. The type of information you would like to know, Stars(S) or Planets(P) as a String.
    2. The position of the star or planet relative to the earth or Sun respectively.
  2. Your application must deal with any incorrect input from the user.
  3. Your application must output information requested.

 Output

  1. Output the heading, "The CS Star Chart\n\n"
  2. Output the prompt, "Do you want information on Stars(S) or Planets(P)? "
  3. Output the newline character after reading the input value and before the next prompt. Note: your input will be on the same line as the prompt.
  4. Test the input to be of the form "Stars" or "S" (ignore case) or "Planets" or "P".  See Error Handling if the value is not either of these.
  5. If they have entered "Stars" or "S", prompt with,"Type in a number between 1 and 10, and I will tell you the name of the star. "
    1. Ouput the new line character after reading in the value.
    2. If the the value entered is not an int or is not in the range of 1 through 10, see Error Handling.
    3. If the value entered is an int in the range of 1 through 10, display "\nThe name of the star that is the " + XXXX + YYYY + " closest to the earth is " + ZZZZ + "." where XXXX is the integer entered, and YYYY corresponds to the ordinal suffix (st, nd, rd, th for 1st, 2nd, 3rd, 4th, etc), and ZZZZ is the name of the star.
  6. If they have entered "Planets" or "P", prompt with "Type in a number between 1 and 8, and I will tell you the name of the planet. "
    1. Output a new line character after reading in the input value. 
    2. If the value entered is not an int or is not in the range of 1 through 8, see Error Handling
    3. If the value entered is an int in the range of 1 through 8, display "\nThe name of the planet that is the " + XXXX + YYYY + " closest to the sun is " + ZZZZ + "." where XXXX is the integer entered, and YYYY corresponds to the ordinal suffix (st, nd, rd, th for 1st, 2nd, 3rd, 4th, etc), and ZZZZ is the name of the planet.

Error Handling

  1. If the input from the user in response to the first prompt is not "Stars" or "S" or "Planets" or "P" output (WWWW + " is improper input!! - run the program again." where WWWW is what the user input.  You should exit the program.  (System.exit(1) will exit the program).
  2. If a bad value is entered when an integer is expected, output the message "ZZZZ + " is not a number.  I will use 1." and set the number to 1.
  3. If the number for "Stars" is not in the correct range of 1 - 10, display "That number is not between 1 and 10. I will use 2." and set the the number to 2.
  4. If the number for "Planets" is not in the correct range of 1 - 8, display "That number is not between 1 and 8. I will use 3." and set the number to 3. 

Sample output


The CS Star Chart

Do you want information on Stars(S) or Planets(P)? Stars

Type in a number between 1 and 10, and I will tell you the name of the star. 5


The name of the star that is the 5th closest to the earth is Barnard's Star.

The CS Star Chart

Do you want information on Stars(S) or Planets(P)? sTArs

Type in a number between 1 and 10, and I will tell you the name of the star. 5


The name of the star that is the 5th closest to the earth is Barnard's Star.
The CS Star Chart

Do you want information on Stars(S) or Planets(P)? s

Type in a number between 1 and 10, and I will tell you the name of the star. q

q is not a number.  I will use 1.

The name of the star that is the 1st closest to the earth is Sun.

The CS Star Chart

Do you want information on Stars(S) or Planets(P)? x

x is improper input!! - run the program again.

Additional Program Requirements

  1. You must use variables for the values of the input parameters.
  2. You must use constants for the default values that get assigned.
  3. Your program must conform to standard Java programming standards and the additional standards for this class. See the Style Guide for your class.
  4. You should have attach to your submission report, results of at least three test runs.  You may cut and paste from JGrasp or your editor of choice.  You could also cut and paste from a command line environment if that is what you are using.

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by any student to another student. Authorized help is limited to your textbook, the TAs for any CS139 or CS239 section, and the professor for your section. See collaboration policy.

Grading

        For submissions after:

HINTS