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

Dear Experts. Please help on this with comments. Thanks. Question: Plays a game

ID: 3774321 • Letter: D

Question

Dear Experts.

Please help on this with comments. Thanks.

Question:

Plays a game of 2 queries

Write a Java program which plays a simple game of 2 queries. The first query should be "City, Country or Continent?" Then, the second query should be "is it bigger than a China?" Then, display one of six possible responses, depending on their answers. Can choose what answers to give for each of the six possibilities. Here’s a suggestion:

size type

City

Country

Continent

smaller than China

Shanghai

Japan

Australia

bigger than Beijing

Karachi

US

Europe

Out put should be :

size type

City

Country

Continent

smaller than China

Shanghai

Japan

Australia

bigger than Beijing

Karachi

US

Europe

Explanation / Answer

import java.util.*;


class CityGuessGame
{

public static void main(String s[])
{
String[][] places= new String[][]{ {"Shanghai", "Japan", "Australisa"},
{"Karachi", "US", "Europe"}
  
};
int place=0, r=0;
String[] city= {"Shanghai", "Karachi"};
String[] country= {"Japan", "US"};
String[] continent= {"Australia", "Europe"};
  
String c, b;
Scanner sc = new Scanner(System.in);
  
System.out.println("Two Queries! Think of a place, I will try to guess it");
System.out.println(" Query 1: Is it City, COuntry or COntinent");
c=sc.nextLine();
System.out.println(" Query 2: Is it bigger than Beijing");
b=sc.nextLine();
  
if(c.equalsIgnoreCase("city"))
place=0;
else if(c.equalsIgnoreCase("country"))
place=1;
else if(c.equalsIgnoreCase("continent"))
place=2;
else
{
System.out.println("Invalid Entry");
System.exit(0);
  
}
  
if(b.equalsIgnoreCase("yes"))
r=1;


System.out.println("My guess is that you are thinking of a "+places[r][place]+". I would ask you if I'm right, but I don't actually care.");   

  
  
}
}

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