Assignment 7

Due Tuesday, February 6 at 11:20am on Canvas


Assignment 7.1: Suggesting Blog Titles (10 pts)

  • A blog is a website for commentary, discussion or information that is more or less regularly updated. To attract attention, blog entries often have sensational or provocative headlines.
  • For this assignment, we will write a program to produce suggested blog titles on a topic selected by the user.
  • The name of the source code file for this program must be blogtitles.java and all your code must be in this file.
  • Write a program that produces the following five (5) blog titles based on user input of a topic and number:
    • [number] Secrets That Experts Of [topic] Want You To Know!
    • [number] Reasons [topic] Will Change The Way You Think About Everything!
    • You Will Never Believe This Awesome Truth Behind [topic]
    • Here's What No One Tells You About [topic]
    • [number] Ways [topic] Can Help You Live To 100!
  • Ask the user for the following inputs (and no other input) in this order, as shown in the Sample Output below:
    1. Single word topic
    2. Integer number between 3 and 20
  • The words [topic] and [number] (shown in square brackets above for emphasis) must be replaced by the user input.
  • Sample Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. For the input shown you must get the same output. However, the output must change correctly if the inputs are different.
    Enter a single-word topic: Java
    Enter an integer number between 3 and 20: 10
    
    Suggested blog titles:
    10 Secrets That Experts Of Java Want You To Know!
    10 Reasons Java Will Change The Way You Think About Everything!
    You Will Never Believe This Awesome Truth Behind Java
    Here's What No One Tells You About Java
    10 Ways Java Can Help You Live To 100!
    

    In the above invocation of the program, the user entered "Java" (without the quotes) as the topic and "10" (without the quotes) as the number.

  • Note the the user should be able to enter any topic of their choice and any number of their choice and the program should adapt the output accordingly.
  • Hint: You will need to use the Scanner class and create a new Scanner to read user input in your program
  • You may add additional blog title suggestions after the above 5, but must print the above 5 blog titles at a minimum.


Assignment 7.2: 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.3: 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 :(