Dear Experts Please help on this with comments Thanks Questi

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

Solution

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.\");   

  
  
}
}

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 fi
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 fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site