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: 3775121 • Letter: D

Question

Dear Experts.

Please help on this with comments. Thanks.

Question:

Plays a game of 3 queries

Write a Java program which plays a simple game of 3 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: Thanks always.

size type

City

Country

Continent

smaller than China

Shanghai

Japan

Australia

bigger than Beijing

Karachi

US

Europe

Largestpopulation

El Alto

Bolivia

South America

Note:

I received answer as below but I need to add one more information " Largest Pupulation" as per in table and also add separate query and answer such as "What is the largerst Ocean in the world?" answer is Pacific if wrong input should show "Inavlid". Please help modify in same coding and also please input comment to show the meaning for the each coding.

answer received as shows need modification as per ststed in table and note.

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

  
  
}
}

size type

City

Country

Continent

smaller than China

Shanghai

Japan

Australia

bigger than Beijing

Karachi

US

Europe

Largestpopulation

El Alto

Bolivia

South America

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","El Alto"};
       String[] country= {"Japan", "US","Bolivia"};
       String[] continent= {"Australia", "Europe","South America"};
      
       String c, b,p,o;
       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, Continent or Ocean");
       c=sc.nextLine();
       System.out.println(" Query 2: Is it bigger than Beijing");
       b=sc.nextLine();
       System.out.println(" Query 3: Largest Pupulation");
       p=sc.nextLine();
       System.out.println(" Query 4: What is the largerst Ocean in the world?");
       o=sc.nextLine();
  
       if(c.equalsIgnoreCase("city"))
           place=0;
       else if(c.equalsIgnoreCase("country"))
           place=1;
       else if(c.equalsIgnoreCase("continent"))
           place=2;
       else if(c.equalsIgnoreCase("ocean"))
           place=3;
       //  
       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.");   
       }else if(o.equalsIgnoreCase("pacific")){
           r=3;
           System.out.println("Your Guess is correct..!");
           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.");   
       }else if(p.equalsIgnoreCase("yes")){
           r=2;
           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