This Problem Set Is Due By 11:59 PM on September 29, 2013

  1. Check Date String (5 points)

    Write a program that reads a string from the keyboard and test whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid.

    The input date should be in the format mm/dd/yyyy. A valid month value mm must be from 01 to 12.

    The day value dd must be from 01 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29 days. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.

    Name this program CheckDateString

    Extra Credit (5 points)

    Write your program so it can handle 2 different types of input. The first is the format mm/dd/yyyy, same as above. The second input date format should be Month dd, yyyy, as in September 28, 2012.

  2. Exam Scores (5 points)

    Write a program that prompts the user for a list of exam scores each in the range 0 to 100. Your program will display the total number of scores entered and the number of grades in each letter-grade category as follows: 90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and 0 to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop reading scores, so do not use it in the calculations.) For example, if the input is:

    	98 87 86 85 85 78 73 72 72 72 70 66 63 50 -1
          

    The output would be

    	Total number of grades = 14
    	Number of A's = 1
    	Number of B's = 4
    	Number of C's = 6
    	Number of D's = 2
    	Number of F's = 1
          

    Name this program ExamScores

  3. Asterisks Triangle (5 points)

    Write a program that asks the user to enter the size of a triangle (an interger from 1 to 50). Display the triangle by writing lines as asterisks. The first line will have one asterisk, the next line will have 2 asterisks, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user. One the next line, write one less asterisk and continue by decreasing the number of asterisks by one for each successive line until only one asterisk is displayed. For example if the user enters 5, the output would be:

    	*
    	**
    	***
    	****
    	*****
    	****
    	***
    	**
    	*
          

    Hint: Use nested for loops; the outside loop controls the number of lines to write, and the inside loop controls the number of asterisks to display on the line.

    Name this program AsterisksTriangle

  4. Chocolate Bars (5 points)

    Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. We can redeem six coupons for one chocolate bar from the machine. This means that once you have started buying chocolate bars from the machine, you always have some coupons.

    We would like to know how many chocolate bars can be eaten if we start with N dollars and we always redeem coupons if we have enough for an additional chocolate bar.

    For example, with $6 we could consume 7 chocolate bars. After purchasing 6 chocolate bars, we have 6 coupons which we can redeem for an additional chocolate bar. This would leave us with one extra coupon from the 7th chocolate bar. For $11, we could have consumed 13 chocolate bars and still have one coupon left. For $12, we could have consumed 14 chocolate bars and still have two coupons left.

    Write a program that inputs a value N and outputs how many chocolate bars we can eat and how many coupons we would have left over. Use a loop that continues to redeem coupons as long as there are enough to redeem at least one chocolate bar.

    Name this program ChocolateBars

Please submit the completed assignment on Blackboard by attaching all your .java files. Make sure to attach all your programs to each submission.