Skip to content

Commit 4f972d9

Browse files
Word Game
1 parent 53d082f commit 4f972d9

File tree

1 file changed

+69
-0
lines changed
  • Programming-Challenges/Fundamentals/src/com/challenges

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Write a program that plays a word game with the user. The program should ask the user to enter the following:
3+
4+
• His or her name
5+
• His or her age
6+
• The name of a city
7+
• The name of a college
8+
• A profession
9+
• A type of animal
10+
• A pet’s name
11+
12+
After the user has entered these items, the program should display the following story,
13+
inserting the user’s input into the appropriate locations:
14+
15+
There once was a person named NAME who lived in CITY.
16+
At the age of AGE, NAME went to college at COLLEGE.
17+
NAME graduated and went to work as a PROFESSION.
18+
Then, NAME adopted a(n) ANIMAL named PET_NAME.
19+
They both lived happily ever after!
20+
*/
21+
22+
package com.challenges;
23+
24+
import java.util.Scanner;
25+
26+
public class WordGame {
27+
public static void main(String [] args) {
28+
29+
// Declare Variables
30+
String name;
31+
int age;
32+
String city;
33+
String college;
34+
String profession;
35+
String animal;
36+
String petName;
37+
38+
Scanner scanner = new Scanner(System.in);
39+
40+
System.out.println("Please Enter your name: ");
41+
name = scanner.nextLine();
42+
43+
System.out.println("Please enter your age: ");
44+
age = scanner.nextInt();
45+
46+
scanner.nextLine(); // To encounter the line break that is left by scanner.nextInt()
47+
48+
System.out.println("Please enter the name of a city: ");
49+
city = scanner.nextLine();
50+
51+
System.out.println("Please enter the name of a college: ");
52+
college = scanner.nextLine();
53+
54+
System.out.println("Please enter a profession: ");
55+
profession = scanner.nextLine();
56+
57+
System.out.println("Please enter a type of animal: ");
58+
animal = scanner.nextLine();
59+
60+
System.out.println("Please enter the name of a pet: ");
61+
petName = scanner.nextLine();
62+
63+
System.out.println("There once was a person named " + name + " who lived in " + city + ".");
64+
System.out.println("At the age of " + age + ", " + name + " went to college at " + college + ".");
65+
System.out.println(name + " graduated and went to work as a " + profession + ".");
66+
System.out.println("Then, " + name + " adopted a(n) " + animal + " named " + petName + ".");
67+
System.out.println("They both lived happily ever after!");
68+
}
69+
}

0 commit comments

Comments
 (0)