In: Computer Science
Java
Project Requirements:
1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers.
2.The program must perform the following:
a.Uses a Scanner object to ask the user: (The program asks for no other information)
i.Full Name (First and Last name only) - stores this Full Name in one String object variable.
ii.Age – must be read in as an int.
iii.Profession or expected profession
iv.Name of favorite pet
v.Cost of their first vehicle – must be read in as a double.
b.All input data must be stored in their own variable prior to printing out.
c.Display a paragraph of the programmer’s choosing that contains the following
i.The user’s full name, first name, and last name in separate places in the paragraph, such as James Gosling founded Sun Microsystems. James was a child prodigy. The Gosling family is very proud of James.
ii.The user’s age.
iii.The user’s profession in all uppercase regardless of the case the profession was entered.
iv.The user’s favorite pet’s name in all lower case regardless of the case the name was entered.
v.The total cost of the user’s first vehicle in a rounded two decimal places including the dollar signs. The total cost must include the inputted cost plus a 7.5% sales tax. The sales tax rate is stored as a constant in the program.
vi.A statement in parenthesis stating the total number of characters in the paragraph such as (The above story contained 345 characters)
d.Include javadoc class comment following Project Comment Template on the content page.
3.The project requires one files to be turned in - WordGame.java (the source code of your Word Game programming.
wordgame.java
import java.util.Scanner;
import java.io.*;
public class wordgame
{
public static void main(String[] args)
{
String
fullname,proffesion,fav_pet;
int age;
double f_v_cost,tax;
tax = 7.5;
Scanner scanner = new Scanner(System.in);
System.out.println( "Enter fullname (first and last
name only): ");
fullname = scanner.nextLine();
System.out.println( "Enter age:
");
age = scanner.nextInt();
System.out.println( "Enter proffesion: ");
proffesion = scanner.next();
System.out.println("Enter name of
favourite pet: ");
fav_pet = scanner.next();
System.out.println( "Enter Cost of
their first vehicle: ");
f_v_cost = scanner.nextDouble();
String[] parts = fullname.split(" ");
String fname = parts[0];
String lastname = parts[1];
System.out.println(fullname + "
works as " + proffesion + ". " + fname + " was a child prodigy. The
" + lastname + " family is very proud of "+fname+".");
// String ss =;
System.out.println("Current age of
" + fname + " is " + age + "." + " His favourite pet is " +
fav_pet.toUpperCase() + ".");
double tmp = Math.round((f_v_cost +
f_v_cost* tax/100.0) * 100.0) / 100.0;
System.out.println("Cost of his
first vehicle is $ " + tmp + ".");
}
}
Sample Output:
Enter fullname (first and last name only):
Joe Root
Enter age:
25
Enter proffesion:
Cricketer
Enter name of favourite pet:
Dog
Enter Cost of their first vehicle:
100000
Joe Root works as Cricketer. Joe was a child prodigy. The Root
family is very proud of Joe.
Current age of Joe is 25. His favourite pet is DOG.
Cost of his first vehicle is $ 107500.0.