Assignment 7

Due Thursday, May 3 at 1:20pm on Canvas


Assignment 7.1: What's Your Dragon Name? (10pts)


Green Dragon v2 by sandara

image source


  • Create a new Java project named Dragon with a new class named Dragon.java.
  • The purpose of this program will be to give the user a "dragon name."
  • A person's dragon name can be generated using the following algorithm:
The first two letters of your last name
+ last two letters of your first name
+ the first two letters of your mother's name
+ the last letter of your father's name
  • At the top your program, declare 5 string variables:
String firstName;
//declare a string variable for the last name called lastName
String motherName;
//declare a string variable for the father's name called fatherName
String dragonName;
  • Greet the user by printing the following message to the console:

System.out.println("Want to learn your \"dragon name?\"\n");

  • Note the use of the escape sequence above to allow the " to display as part of the message.
  • Next, prompt the user for this information
Please enter your first and last name:
  • Next, prompt the user for his or her mother's name, read the name in using a input.next() statement, and store the input as the motherName variable:

Please enter your mother's first name:

  • Follow the same pattern for the father's name.

Please enter your father's first name:

  • Finally, you will want to calculate the user's dragon name and display it to the user using the above formula.
  • Hint: You will need to use the String charAt method and the String length to calculate this name.
dragonName = "" + lastName.charAt(0) + ?????? + firstName.charAt(firstName.length()-2)+ ?????????;
  • Note the "" above, which is known as the empty String. The "" converts the series of chars to one big String so that they can be stored in the String variable.
  • Finally: Display the result to the user with the following output:

Your "dragon name" is: "<dragon name>"

  • Note the use of the " above. How can you get them to display when you print this message to the console?
  • Also, the Dragon Name should be in all capitals (to make it more fierce).
  • When you are finished, submit your Dragon.java program to Canvas.

The output of your program should look like this (except user input will vary):

Want to learn your "dragon name?"
Please enter your first and last name: Jennifer Parrish
Please enter your mother's first name: Cassandra
Please enter your father's first name: Stewart
    Your "dragon name" is: "PAERCAT"

Assignment 7.2: Pass or Fail? (10 pts)

  • Write a program to read in a user's test score and report back either "Pass!" or "Fail :(".
  • For this assignment, we will consider a passing score to be a value that is 60 or above, and a failing score to be below 60.
  • Name your file Pass.java.
  • The program should work identically to the code below and should use both an if and an else for full credit.

Enter your score: 60
Pass!

Alternately,

Enter your score: 100
Pass!

Alternately,

Enter your score: 59
Fail :(

Assignment 7.3: 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, submit it to Canvas