Homework #5 – Due Thursday


Important Reminder:  Hopefully you have done this already, but be sure that you have done a good amount of practicing with methods before completing the assignment. If you try to learn methods by doing the assignment without previous practice, it will end up taking you much longer and you will not understand the material as well.


Because each problem in this assignment is done inside a method, this assignment requires you to create only ONE class.  


1.      Create a method called calculateTicketCost. Inside this method, use the Scanner class to prompt the user for their age. Then ask them if they are a student, and store this value as a String.  Your method should return the cost of a movie.  If they are 65 or over, the cost is 5 dollars. If they are a student, a ticket is also $5.  If they are both 65 or over and a student, they get an extra-cheap ticket at $2.  If they are 12 or below, tell them that the movie is PG-13 and they can not be admitted the cost is only $1. Otherwise, the regular cost for a ticket is $8. Your method can simply return an integer representing the cost of the ticket.


2.      Create a method called countSixes.  Using the random number generator from the last assignment, roll a die a hundred times. Count the number of times a 6 was rolled. Your method should return this number.


3.      TO BE ASSIGNED IN A FUTURE ASSIGNMENT – NOT due this Thursday!  Create a method called cardDraw. In the method, randomly generate a number between 1 and 52.  Numbers 1 through 13 should be 2 of hearts through Ace of hearts. 14 though 26 should be the 2 of diamonds through Ace of diamonds. Then go through  spades, and then through clubs. Your method should return a String representing the card that was drawn. So if your random number is a 1, you should return a string that says  2 of Hearts. If it is a 13, you should return 2 of Diamonds. If it is a 52 you should return Ace of Clubs. Etc…


4.      Modify the coin flip example from homework #4, and place in a method:  Create a method called flip100Coins. In this method, simply “flip a coin 100 times” and output the results. You do not have to count the number of heads and tails. This method does not return any values, it should simply output the results.


5.      Will require material from next lecture: Create a method called ‘findLowest’ that accepts 3 doubles and will return the lowest of those three doubles. For example, findLowest(22.4, -91.7, -17.4) will return -91.7.


6.      Bonus Question - 5 points: Overload the method in question number 2 to accept an integer that will determine how many times to roll the die. So for example countSixes(50) will roll it 50 times while countSixes(75) will roll it 75.


7.      Also have a main method in which you demonstrate invoking each of your methods.



Submit this entire assignment as a single source code file. You should only have one source code file since everything takes place inside methods.  You do NOT have to zip it.