Use conditionals to sort through the morass of Bleegian bureaucracy
Textbook: 5.1 - 5.2
Concepts: conditionals; logical operators; switch
.
Bleeg is a small, remote planet cursed with a bloated governmental bureaucracy. In a recent attempt at reform, the myriad administrative offices and departments were combined into three massive agencies:
Its long history of excessive paperwork has strained Bleeg's natural resources. For this reason, citizens must present ID to pick up forms at any of the three departments. Additionally, before any white forms can be turned in, current pink and blue forms must also be completed in order to prove the applicant is a healthy, viable member of society (and so worth the expense of the various forms they will have to complete).
As if this were not enough hassle, each of the departments are open on different days. And the CMA will only give out forms on some days and accept returned forms on other days.
However, computers are just being introduced to Bleeg. Through a series of sordid events (it's a long story), you are currently serving time in the Bleegian programming pits. It has fallen to you to implement the first program meant to cut through the Bleegian bureaucracy: a program that will tell citizens which forms they can pick up or turn in on any given day.
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, 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.)
To further complicate matters, some Bleegian's prefer to number days from the end of the month, rather than the beginning. To prevent total confusion, dates in this "count-down" calendar are given as negative numbers. Therefore, Day -1 == Day 27, Day -2 == Day 26, Day -3 == Day 25, and so on. Luckily, both the standard and the count-down calendars coincide on Day 0.
Department days. Here are the details of the departments:
So that's all the background information you need. Here's what the Bleegian overseers say the program must actually do:
Remember, the Bleegian jute mills await you should you fail at this task!
Here is some sample output of a few runs. User input is shown in green. Note that I am running the program multiple times here, and that the first line of each run is my command prompt, which is not part of the program output.
D:\TA\grading\A08>java ZtomaszeA08 Please enter the current Bleegian day of the month: 30 Sorry, but 30 is not a valid day of the month. D:\TA\grading\A08>java ZtomaszeA08 Please enter the current Bleegian day of the month: 0 Today (Day 0) is Festival. You can pick up no forms today. You can drop off no forms today. D:\TA\grading\A08>java ZtomaszeA08 Please enter the current Bleegian day of the month: -8 Today (Day 20) is Saturday. You can pick up these forms: pink You can drop off these forms: pink white D:\TA\grading\A08>java ZtomaszeA08 Please enter the current Bleegian day of the month: 14 Today (Day 14) is Sunday. You can pick up these forms: pink blue You can drop off these forms: pink blue white D:\TA\grading\A08>java ZtomaszeA08 Please enter the current Bleegian day of the month: 3 Today (Day 3) is Wednesday. You can pick up these forms: white You can drop off these forms:
Submit your UsernameA08.java
file to Tamarin.
int
) from the user.
(Note: You can use a switch
structure for this assignment, if you want. But when I use the term "case" here, I'm speaking more generally as any logical branch of your code, which includes any if
, else
, or else if
body.)
Instead of a brute force approach, try to streamline your code. Be aware that most of the rules really just require you to figure out what the input is divisible by. 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, first read in the day of the month 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 the next step: translating any negative countdown date to the corresponding positive standard date. (Technically, all the rules are based on the standard calendar, so you should be doing all the comparisons with the standard calendar day anyway.) Now you only need to worry about 28 possible cases.
However, if you use % 7
to determine which day of the week it is, you only need 7 cases--one case for each day of the week you're translating to. This is a good place to use a switch
if you want to try it. (Remember that some Sundays are Festival though, so there's an extra test needed within that 0 case.)
At this point you should have printed all the output except the form availability. For this, you will need only a handful of if statements. Like determining the day, this can quickly be determined by using the % operator and looking at the value of the remainder. Exceptions to the rules often just require a logical operator and a second expression.
So, you should be able to streamline your code to something like this:
//get day from user if (day is in range) { //covert day to positive if it is negative (if) //determine day of the week from day of the month (switch or if/else ifs) //print first line of output: calendar day and day of the week. //print first half of "You can pick up:" line //use ifs to print which forms can be picked up this day //print first half of "You can drop off:" line //use ifs to print which forms can be dropped off this day }else { //print error message }
Of course part of this assignment is supposed to be designing a solution from the requirements. So, while I've given you most of a design here, you'll need to fill in the rest of the details on your own. And of course variations on this design or completely different designs are certainly acceptable.