CS 111 - Introduction to Computer Science
Homework #5


Due: Friday 2/24 at the beginning of class
Extended Due Date (due to submission system problem): Friday 3/3 at the beginning of class

1. Pentagon Area:  Text Programming Exercise 4.1.  Call your program PentagonArea.java.  Remember to end your last print statement with a newline.

2. Gettysburg Student Username:  Implement a program Username.java that prompts the user with "Please enter a first name, last name, and 1-2 digit positive integer separated by spaces: ", reads two Strings and an integer respectively, and then prints the Gettysburg student username according to the following rules:

You may assume that all names contain no spaces, hyphens, or any character other than an English alphabetic character of either case.  You may not assume that all input is lowercase.

Example Transcript (input underlined):


Please enter a first name, last name, and 1-2 digit positive integer separated by spaces: Kyle Fun 1
funky01

Please enter a first name, last name, and 1-2 digit positive integer separated by spaces: Eric Answorth 42
answer42

Please enter a first name, last name, and 1-2 digit positive integer separated by spaces: Melissa Mailander 11
mailme11

3. Chuck-a-luck: Implement a program ChuckALuck.java that implements a simple "Single Die Bet" form of the game Chuck-a-luck.  A bettor places a stake (i.e. amount of money bet) on a die roll (1-6) and rolls three dice.  If none of those three show the die roll the stake was bet on, the bettor loses their stake.  However, if n of the dice rolled equal the die roll of the stake, then the banker pays the bettor n to 1, i.e. the bettor gets back their stake plus n times their stake.  (Thus, a bettor who places a stake on 1 and rolls 3,1,4 will get back 2 times their stake back.  However, if the roll was instead 1,1,1, then the bettor would get back 4 times their stake.)

Input:

 Output:

Example transcripts (input underlined):


Place your bet on a number 1-6: 0
Invalid bet.	

Place your bet on a number 1-6: 3
Roll: 1,6,6 --> You lose your stake.

Place your bet on a number 1-6: 4
Roll: 4,3,4 --> The banker pays you 2 to 1!