Lab 01
What is your Zodiac?
Objective:
Write a program that determines a person’s astrological
zodiac sign based on their birthday.
Lab Solution
Requirements:
- Functionality. (80pts)
- No Syntax, Major Run-Time, or Major Logic Errors. (80pts*)
- *Code that cannot be compiled due to syntax errors is
nonfunctional code and will receive no points for this entire section.
- *Code that cannot be executed or tested due to major
run-time or logic errors is nonfunctional code and will receive no
points for this entire section.
- User Inputs a Date as two separate whole number values.
(10pts)
- The user must be prompted to enter the month followed by
the day.
- Both of these must be the numeric values representing
the month and day, and this detail must be explained to the user.
- All must apply for full credit.
- Check the Month. (15pts)
- A valid month is between 1 and 12.
- If the user enters a numeric value that is outside of
that range, they must be informed that it is invalid.
- It is not required to check for non-numeric values (such
as a character or String) for this problem.
- All must apply for full credit.
- Check the Day. (15pts)
- This depends on the month.
- April, June, September, and November have between 1 and 30
days.
- Assume February has 29 days.
- All other months have between 1 and 31 days.
- If the user enters a numeric value that is outside of those
ranges, they must be informed that it is invalid.
- It is not required to check for non-numeric values
(such as a character or String) for this problem.
- All must apply for full credit.
- Determine the user’s Zodiac Sign and print the results.
(40pts)
- Zodiac Signs are based on their dates,
- Aries = March 21 to April 19
- Taurus = April 20 to May 20
- Gemini = May 21 to June 20
- Cancer = June 21 to July 22
- Leo = July 23 to August 22
- Virgo = August 23 to September 22
- Libra = September 23 to October 22
- Scorpio = October 23 to November 21
- Sagittarius = November 22 to December 21
- Capricorn = December 22 to January 19
- Aquarius = January 20 to February 18
- Pisces = February 19 to March 20
- Their results must be printed.
- All must apply for full credit.
- Coding Style. (10pts)
- Readable Code
- Meaningful identifiers for data and methods.
- Proper indentation that clearly identifies statements
within the body of a class, a method, a branching statement, a loop
statement, etc.
- All the above must apply for full credit.
- Comments. (10pts)
- Your name in the file. (5pts)
- At least 5 meaningful comments in addition to your name.
These must describe the function of the code it is near. (5pts)
Example Dialog:
What is your zodiac? Enter your birthday -- Month followed by
Day as numbers.
5 2
You are a Taurus!
Another Example Dialog:
What is your zodiac? Enter your birthday -- Month followed by
Day as numbers.
-6 22
Invalid Month!
Another Example Dialog:
What is your zodiac? Enter your birthday -- Month followed by
Day as numbers.
12 -12
Invalid Day!
Another Example Dialog:
What is your zodiac? Enter your birthday -- Month followed by
Day as numbers.
9 31
Invalid Day!
Solution Tests:
- Is your name written as a comment in all source files?
- Does the solution compile (no syntax errors)?
- Given the input, 5 followed by 2 does the program print
out “Taurus”?
- Given the input, 1 followed by 28 does the program print
out “Aquarius”?
- Given the input, -6 followed by 22 does the program print
out “Invalid Month”?
- Given the input, 12 followed by -12 does the program print
out “Invalid Day”?
- Given the input, 9 followed by 31 does the program print
out “Invalid Day”?
Lab Report
- Create a section named “Problem” and describe this lab’s
problem in your own words. (10pts).
- Create a section named “Solution Description” and describe
how the code solves the problem in your own words. (10pts).
- Create a section named “Problems Encountered” and describe
the various syntax, run-time, and logic errors that were encountered while
implementing the solution. (10pts).
- Create a flow-chart based on your lab solution. Make sure
to put decisions in diamonds, statements in boxes, and draw arrows showing
the flow of the program. Also, arrows coming from decisions must have the “TRUE”
and “FALSE” branches clearly labeled. (10pts)
- Write an equivalent Boolean expression for,
!(a<=b)||!(b>c)
which applies the NOT-operator (!)
to the appropriate operators. Assume that a, b, and c are integers. (10pts)
- Given the following code snippet, what will the program
print to the console? (10pts)
- The following code snippet appears to have a logic error. The
code should print out “Yes”, but it keeps printing out “No”. What is the
cause of the logic error and how can it be fixed? (10pts)
- The following code snippet is supposed to convert a given
temperature in degrees Fahrenheit to degrees Celsius. Does this work as
intended? If it does, then what should the program print out if the user
provides 98 degrees. If it does not, then describe the errors and how to
fix it. (10pts)
- The following code snippet contains a syntax error.
Describe what is causing the syntax error and how it can be fixed. (10pts)
- Given this code snippet, what will print to the console?
(10pts)
NOTE: Questions related to Code Snippets only
pertain to the code that is given, and it can be assumed that all the unseen, surrounding
code works. It may also be assumed that the snippet itself is in a correct location.
Unless otherwise stated in the question, the code within the snippet is assumed
to be error-free.
Finally:
Upload the source code (.JAVA File Extension) and written
lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.