Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Word Game Write a program that plays a word game with the user. The program shou

ID: 3935421 • Letter: W

Question

Word Game

Write a program that plays a word game with the user. The program should ask the user to enter the following:

*His or her name

*His or her age

*The name of a city

*The name of a college

*A profession

*A type of animal

*A pet’s name

After the user has entered these items, the program should display the following story, inserting the user’s input into the appropriate locations:

There once was a person named NAME who lived in CITY. At the age of AGE, NAME went to college at COLLEGE. NAME graduated and went to work as a PROFESSION. Then, NAME adopted a(n) ANIMAL named PETNAME. They both lived happily ever after!

Explanation / Answer

WordGame.java


import java.util.Scanner;

public class WordGame
{ public static void main(String[]args)
{
//declaration of variables
String name;
int age;
String city;
String college;
String profession;
String animal;
String petName;
Scanner keyboard=new Scanner(System.in);
System.out.print("Enter your name:"); name=keyboard.nextLine();
System.out.print("Enter name of your city:"); city=keyboard.nextLine();
System.out.print("Enter your age:");
age=Integer.parseInt(keyboard.nextLine());
System.out.print("Enter name of your college:"); college=keyboard.nextLine();
System.out.print("Enter your profession: "); profession=keyboard.nextLine();
System.out.print("Enter a type of animal?:"); animal=keyboard.nextLine();
System.out.print("Enter name a petName: "); petName=keyboard.nextLine();
System.out.print("There once was a person named "+name+" who lived in "+city+".");
System.out.print("At the age of "+age+", "+name+" went to college at "+college+".");
System.out.print(name+" graduated and went to work as a "+profession+".");
System.out.print("Then, "+name+" adopted an "+animal+" named "+petName);
System.out.print("They both lived happily ever after! "); } }

Output:

Enter your name:Suresh Murapaka
Enter name of your city:Visakhapatnam
Enter your age:30
Enter name of your college:Avanthi
Enter your profession: Software Eenginner
Enter a type of animal?:mammals
Enter name a petName: Gali
There once was a person named Suresh Murapaka who lived in Visakhapatnam.At the age of 30, Suresh Murapaka went to college at Avanthi.Suresh Murapaka graduated and went to work as a Software Eenginner.Then, Suresh Murapaka adopted an mammals named GaliThey both lived happily ever after!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote