Objective of this Program: (1) To learn about having programs decide what to do depending upon the data by using the if...then...else construct and (2) to start using some of the Java API's, by using the String class.
The program is to prompt the user (both computer science and drug dealers refer to their clients as "users") for the date of the month and whether they want the next day or the previous day. E.g., the user would see:
Enter todays date(1-30):and after responding, the user would see:
Do you want the next or previous day:
The program should output the next day's or previous day's date: e.g, for the input of:
Enter todays date(1-30): 7 Do you want the next or previous day: next Tomorrow is the 8th.For the response of 'previous', one would see:
Yesterday was the 6th.
You should also check for erroneous input. Specifically, three possible bad inputs:
(1) the data is not between 1 and 30, inclusive
(2) one is asked the preceding date of the 1st
(3) one is asked the next day of the 30th
If bad input is given, then each of them should have an appropriate message telling of the bad input, e.g.,
Enter todays date(1-30): 36gets the response:
Please enter a date between 1 and 30.and the program would terminate. You terminate a program by the statement of System.exit(0);. It should be part of the 'then' clause statement.
However, the following input sequence of:
Enter todays date(1-30): 30 Do you want the next or previous day: nextwould generate:
There is no date after the 30th.A simliar response is given for a response of "previous" when the current date is a 1.
You do not have to verify whether one correctly types in 'next' or 'previous' correctly. I.e., if the user incorrectly types in the response, you are not responsible for what happens.
Note:To compare if the input is a next or a previous, you should look at the section on "Comparing Strings" on pages 223-220 of the text.
Note:The input should be done with the Scanner class.
Note that you first do the regular assignment first. Then in different project, you should do the extra-credit.
There are different places on the COL to post the regular and extra-credit assignments.
You should post your project as a 'zip' file on the COL website. Also indicate how many hours you worked on the program in the Readme.txt file. If you did the extra-credit, then post that project as a 'zip" file in the appropriate place on the COL website.
Homepage of CTI School
back to 211
homepage