Assignment 7

Due Thursday, October 18 at 9:20am on Canvas


Assignment 7.1: What Be Yer Pirate Name? (10pts)

Image of a pirate woman
Just in time for Halloween, its time to write a program to generate Pirate names for you and your friends.
Then on Halloween, start plunderin' the high seas with yer new pirate name, matey. 'Arrr!
Open a new file in eclipse called Pirate.java
Place a block comment at the top of the program with your name and the name of the assignment.
Next, welcome the user and prompt for the user's first and last name, as shown below

Git yer pirate name or ye be walkin' the plank!
Enter yer first name: Jennifer
Enter yer last name: Parrish

Next, calculate the user's pirate name according to the below algorithm:
  1. firstLen = length of firstName
  2. if firstLen > 6 then firstLen = firstLen - 6
  3. lastLen = length of lastName
  4. if lastLen > 7 then lastLen = lastLen - 7
  5. choose title from "Length of First Name" table based on firstLen
  6. choose newLastName from "Length of Last Name" table based on lastLen
  7. lastChar = last character of the user's lastName (Hint: call both charAt and length methods)
  8. pirateName = title + firstName + " the ' + lastChar + arrr + newLastName + "

Length of First Name
Length Title
1 Crafty
2 Capt'n
3 Crusty
4 Legend
5 Shrewd
6 Stormy
Length of Last Name
Length New Last Name
1 Black
2 Crimson
3 Gold
4 Gray
5 Red
6 Scarlet
7 Silver
  • Note the use of the " " around part of the pirate name below. Those " " are important. Don't forget about escape characters! (Lesson 7)
  • When your program is working identically to the output shown below (except the user may give different input), then submit Pirate.java to Canvas
Example Output:

Git yer pirate name or ye be walkin' the plank!
Enter yer first name: Jennifer
Enter yer last name: Parrish
Yer Pirate name be: Capt'n Jennifer "the 'harrr Silver"
Git yer pirate name or ye be walkin' the plank!
Enter yer first name: Joey
Enter yer last name: Schmoe
Yer Pirate name be: Legend Joey "the 'earrr Scarlet"

Assignment 7.2: The Price is Right (10 pts)
  • Write a program that reads in a price as a String, and then outputs the price in dollars and cents.
  • Name your project PriceRight and create a class called PriceRight.java
  • For this program, you can assume that the user will enter in a price in either 10s or 100s of dollars. The price will never go above 999.99 or below 10.00.
  • Hint: read in the price as a String
  • Hint 2: Use the String methods (length and charAt) to calculate the length of the String and then break the String into dollars and cents.
  • Hint 3: You will need one if and one else statement to solve this problem
  • Your program should work identically to the example below:
Enter the price: 12.95
12 dollars and 95 cents.
  • Alternately:
Enter the price: 174.35
174 dollars and 35 cents.
  • When your program gives the same output as above (except the user may give different input), submit it to Canvas