mercredi 20 février 2019

I am writing a Java program that is meant to play a version of 20 questions with the user based on their input

To do this I am using a lot of nested if/else statements.

I have three main branches (living animal, living plant, non-living thing) and each of these have multiple branches. Making it something like 60 different decisions.

I am having a lot of trouble getting it to cooperate, and control all the if/else statements. I don't have much code for it yet because of having to restart so much but currently I am at:

System.out.println("Think of Something");

   System.out.println("Is it a living animal, living plant, or non-living thing? ");

 String  user = get.nextLine();

  if(user.equals("living animal"));

{ //starts animal tree

System.out.println("Does it have feathers, fur, or neither?");

  String user2 = get.nextLine();

  if (user2.equals("feathers"));

  {

  System.out.println("is it bigger than a soccer ball?");

  }


  }

  else if (user2.equals("fur"));

  {

System.out.println("is it domesticated?");

} // end animal tree

else if (user.equals("living plant"));

{// start plant tree

System.out.println("is it a tree?");

}

}// end method } //end program

Aucun commentaire:

Enregistrer un commentaire