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:

• The first 4 letters of the username are the lowercase first 4 letters of the last name.  If the last name is less than or equal to 4 letters in length, the entire last name is used.
• The next 2 letters of the username are the lowercase first 2 letters of the first name.  If the first name has only 1 letter, the entire first name is used.
• The final 2 digits of the username are the given 1-2 digit positive integer.  If the input integer has only one digit, a zero is added before that digit.

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

```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:

• The user enters an integer representing their single die number bet.  Integers 1-6 are valid entries.

Output:

• Initially, the user is prompted for their bet with "Place your bet on a number 1-6: ".
• If the user enters an integer that is not in the range 1-6, the program prints "Invalid bet." and does nothing more.
• Otherwise, the program prints "Roll: ", and a random number generator simulates three die rolls and prints them separated only by commas (and no spaces).
• The program prints " --> ".
• If the user's bet is not rolled, print "You lose your stake."
• Otherwise, if the user's bet is rolled n times, print "The banker pays you n to 1!" (substituting the number for n).
• Terminate output with a newline.

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!```