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:
- Use decision statements effectively
- Input data from a keyboard.
- Do everything necessary to
create, debug, and run a java program.
- Use comments to delineate
each section of the program.
- Adhere to a Style Guide.
- READ
AND FOLLOW DIRECTIONS!!!!!
Deadlines
- Submit: October 5th, 2009
by
11:00pm.
- Report: October 6th, 2009
at
the beginning of class. A late penalty will apply for
each of the 2 deadlines. If the submit is late, the report is due the
next class or lab session day after successful submission.
Programs will not be accepted after 7 days late.
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:
- Your program will prompt for
and read two input values. They are:
- The type of information you would like to know, Stars(S) or
Planets(P) as a String.
- The position of the star or planet relative to the earth or Sun
respectively.
- Your application must deal with any incorrect input from the user.
- Your application must output information requested.
Output
- Output the heading, "The CS Star Chart\n\n"
- Output the prompt, "Do you want information on
Stars(S) or Planets(P)? "
- 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.
- 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.
- 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.
"
- Ouput the new line character after reading in the value.
- If the the value entered is not an int or is not in the range
of 1 through 10, see Error Handling.
- 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.
- 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. "
- Output a new line character after reading in the input
value.
- If the value entered is not an int or is not in the range of 1
through 8, see Error Handling.
- 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
- 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).
- 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.
- 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.
- 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
- You must use variables for
the values of the input parameters.
- You must use constants for
the default values that get assigned.
- Your program must conform to
standard Java programming standards and the additional standards for
this class. See the Style Guide for your class.
- 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
- Your program will be
evaluated both by its correctness and conformance to the required
elements.
- You will achieve a grade of
70 for a program that runs correctly
and produces exactly the required output in the required format.
- Documented examples - 10
points.
- The remainder (20 points)
will be
based on your conformance to the Style and other requirements of the
assignment. Review the Style
Guide before submitting your
program and the grade sheet which is produced by the submit system.
- All grades will be based on
100 points.
- You may submit any number of
times. The only one I will count is the one that corresponds to the
hardcopy report that you turn in.
- The hardcopy that you turn
in will be the formatted version that
I will check. Make sure it has no line wraps or other spacing
issues.
- Successfully submitted
programs that are late will be graded, then the late penalty is
assessed for each day late according to the following schedule.
For
submissions after:
- Oct. 6 - 5 points
- Oct. 7 - 15 points
- Oct. 8 - 25 points
- Oct. 9 - 35 points
- Oct. 10 - 45 points
- Oct. 11 - 100 points
HINTS
- Begin early.
Students run into trouble by waiting too long to start the
program.
- Understand the problem at
hand. Make sure that you follow
the requirements precisely. Don't add additional
"flourishes".
You will be downgraded.
- In the body of your main
method, outline your steps with comment lines for each part of the
project.
- Break the project up into smaller pieces. Solve one problem
first, like getting the program to recognizes Stars, S, s, sTars, as
valid and Q or other values as invalid. Test your program then
begin on the next problem.
- If you wish to use additional methods to break up your code, feel
free to do so.