Assignment 07

Task

Use conditionals to simulate the core precepts of Bleegian numerology.

Textbook: 5.1 - 5.2
Concepts: conditionals; logical operators; [switch].

Scenario

You have been captured by Bleegian space pirates.

Aside from its pirates, the planet Bleeg is also known for its bloated governmental bureaucracy, its cruel slavery trade, and the superstitiousness of its general population.

What is less well-known is that many sectors of Bleegian society--including even the feared space pirates--seek the prophetic advice of the Witch-Seers of Babelae before undertaking any significant new endeavor. Using the day of the year as a starting point, these Witch-Seers are able to accurately forecast whether that day will bring good fortune or ill. However, the services of the Witch-Seers of Babelae do not come cheap.

Recently, a rogue space-pirate vessel raided a remote Witch-Seer stronghold and managed to procure one of the sacred Tomes of Prophetic Numerology. When taken as a whole, the system it documents is quite complex. However, pirate scholars have determined that three numbers--4, 7, and 13--seem to serve as the core of the system. Using rules based on only these numbers, their initial tests have suggested that they can duplicate the predictions of the Witch-Seers with an 80% accuracy rate.

The space pirates would now like to distribute these rules to their entire fleet. Then they could still raid with confidence in their fortunes without having to pay the high fees of the Witch-Seers. However, to protect the rules from being stolen by others, as well as to limit misinterpretation by drunk or ignorant pirate captains, they have decided to find someone to encode the rules as a simple program.

When it is discovered that you--a lowly slave--can program, you are hauled up from the dark and fetid slavehold and set to work.

Good luck! If you're lucky and do a good job, you just might live long enough to plan an escape...

What you need to know

You are given the following information, most of which is necessary to complete your program.

Bleegian calendar. The Bleegian year of 364 days is divided into 13 months of exactly 28 days each. Bleegians start counting at 0, however. Therefore, the months are numbered: 0, 1, 2, ... 11, 12. Similarly, each month includes: Day 0, Day 1, Day 2, ... Day 26, Day 27.

Like us, Bleegians have a 7-day week. The days are, oddly, named the same as ours: Sunday, Monday, Tuesday, etc. Both the week and the month starts with Sunday. Because every month is exactly 4 weeks long, every Day 0 is always a Sunday, every Day 1 is a Monday, and so on.

While Day 0 of each month is technically a Sunday by these rules, it is a special holiday for all Bleegians. Therefore, it is always called Festival. (Day 7, Day 14, and Day 21 are all normal Sundays.)


The stolen numerological system makes predictions based on the day of the year--specifically, whether it is evenly divisible by certain numbers.

Lucky: Any day divisible by 7 is lucky (except see below: Unlucky, Indeterminate, Blessed, Momentous).

Unlucky: Any day divisible by 4 is unlucky. However, if it is also divisible by 7, then it is neither lucky nor unlucky [and so neither word should be printed that day]. Again, there are exceptions (see Indeterminate, Cursed, Momentous).

Indeterminate: Normally, a day divisible by 13 means the cosmos is in flux. A person moving forward with a strong will and clear mind can make their own luck that day. Therefore, their fate can not be determined before that day.

Blessed: A day divisible by both 7 and 13 is neither lucky nor indeterminate, but blessed instead.

Cursed: A day divisible by both 4 and 13 is neither unlucky nor indeterminate, but cursed instead.

Momentous: A day that is divisible by all three numbers--4, 7, and 13--occurs only once a year. It has none of the above labels. Instead, it is a time for change and new beginnings. It is momentous.

Neutral: If a day is none of the above, it is simply neutral.

Thus, every day should receive one, and only one, label.

[Toggle Highlighting]

The program requirements

So that's all the background information you need. Here's what the pirates say the program must actually do:

Sample Output

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 0
Enter a Bleegian month: 0
Day 0 of Month 0 = Day 0 of the year.
It is a Festival.
The day will be: momentous.

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 12
Enter a Bleegian month: 3
Day 12 of Month 3 = Day 96 of the year.
It is a Friday.
The day will be: unlucky.

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 30
Sorry, but 30 is not a valid day of the month.

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 7
Enter a Bleegian month: 3
Day 7 of Month 3 = Day 91 of the year.
It is a Sunday.
The day will be: blessed.

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 0
Enter a Bleegian month: 12
Day 0 of Month 12 = Day 336 of the year.
It is a Festival.
The day will be: neutral.

D:\TA\grading\A07>java ZtomaszeA07
For your fortune, enter a Bleegian day of the month: 15
Enter a Bleegian month: feb
Sorry, you must enter a number.

What to Submit

Submit your UsernameA07.java file to Tamarin.

Grading [7 points]

1 - Compiles
Your program compiles successfully (no errors)
0.5 - Input
You read in the Bleegian day of the week and the month (both ints) from the user.
1 - Error-checking
You report if the entered day or month is a String or out of range (and, if so, print no other output).
0.25 - Date
You print the inputted date in the form of "Day # of Month #"
1 - Conversion
You print the correct day of the year.
0.75 - Day of the week
You print the correct day of the week.
2.5 - Label
You correctly print the prophetic adjective (and only that adjective) for that day.

FAQs

Any hints about how to about this?
Break the problem into pieces and tackle them one at a time. Write the code for that piece, compile, run, and test. Once you've got it working, move on to the next piece. I recommend going in order of the requested output (though this is not required).

So, read in the day from the user. Make sure you error-check the input and print the appropriate error messages on bad input (either out of range or a String).

Only after you have the day input working should you go on to worry about the month.

From there, the code is largely a test of divisibility of the input. For example, you can you use % 7 to determine which day of the week it is from the day of the month. A switch could be handy here. (Remember that some Sundays are Festival though, so there will an extra test needed within that 0 case.)

At this point you should have printed all the output except the adjective. For this, you will need some combination of if statements. The requirements are listed in terms of when to print each label. However, it may be helpful to get out a piece of paper and sketch out the relationships in terms of what the day of the year is divisible by. That is, what are all the combinations (cases) of being divisible by 4, 7, and 13? Which label do you need to print in each case?

Since 336 can be evenly divided (without remainders) by 4 and 7, I expect my program to give me a blank value. However, it appears neutral in your answer.
As stated above, every day should receive one and only one label. Since Day 336 is divisible by both 4 and 7, it is neither Lucky nor Unlucky. (See the rules above, especially for Unlucky.) Since neither of those labels is printed, the day should be Neutral instead. (Note that you will likely still need a special case to handle this situation, so that you get the correct Neutral label, even if you already have a default/else case to handle Neutral days.)