Important: When reading in a String using the Scanner class, be sure to use the method nextLine(). Your notes initially had a version that referred to a method called ‘next()’. For the time being, we will not make use of this method.
Remember to practice and experiment with the techniques we have discussed in class before worrying about the homework. If you get really comfortable with the basics, then any additional minor challenges on the homework should not be a major deal.
SUGGESTION: Do NOT try to do everything at once. For example in problem #1, first get the loop to work, and only then should you worry about the commas. For #3, focus on each case (e.g. Thursdays) and make sure it works. Then focus on the others. In other words, focus on one small bit of functionality, test it, and make sure that things are working properly. ONLY then should you begin working on the next bit of functionality.
You may do all three problems, one above the other in the same main method. Or, you may do each of them in a separate class (i.e. in separate files). For 5 bonus points, put each of these problems in its own method and invoke each method from main.
Problem #1 (10 points) - REQUIRES NEXT TUESDAY’S LECTURE…
for while loop, output from -30
to 30, in increments of 3, with a comma and space (not a newline) in between each number. Your output should look something like:
-30, -27, -24, … … … … 21, 24, 27, 30
Press any key to continue…
You will probably initially end up with a comma after the final number (the 30) - that comma must not be present. There are a few different ways of accomplishing this.
NB: If you have already done this problem and read ahead and used a for loop, that is great, there is no need to go back and redo the problem.
Problem #2 (15 points)
Ask the user how many hours they worked over the last week. Output their pay and possible bonus using the following logic:
· If hours are 40 or less, pay is $10
· Any hours over 40 makes $15 per hour. That is, the first 40 hours are $10 each, while all subsequent hours are $15.
· If they work 60 or more hours, give them a $100 bonus in addition to their total pay
For example, if someone worked 30 hours, they make $300.
If they worked 50 hours, they make 40*$10 (for the first 40 hours) + 10*$15 (for the next 10 hours). = $550
If they worked 70 hours, 40*$10 + 30*$15 + $100 bonus
Problem #3 (15 points)
Your pizza store has a special called “Two dollar Tuesdays” and another called “Three Dollar Thursdays”. Ask the user what day of the week it is. Then ask them how many slices of pizza they would like. If it is a Tuesday, charge them two dollars per slice. If Thursday, charge $3 per slice. Any other day, charge $4 slice. Output their total charge.
Example: If they say it is Saturday and they want 2 slices, your program will output: You owe $8. (Include the dollar sign and the period).