Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help with programming a simple Java quiz?

I made a simple quiz in Java a while ago, but I have a little problem. Here is the code:

import java.util.Scanner;

public class ert {

public static void main(String[] args){

Scanner ian = new Scanner(System.in);

double aone;

double atwo;

double athree;

int bacon;

int cheese;

int lettuce;

int answer;

System.out.println("The Cool Test");

System.out.println("Answer 1 for yes and 2 for no.");

System.out.println("Question 1- Are you good at sports?");

aone = ian.nextDouble();

if(aone == 1)

bacon = 1;

else

bacon = 0;

System.out.println("Question 2- Are you good with computers?");

atwo = ian.nextDouble();

if(atwo == 1)

cheese = 1;

else

cheese = 0;

System.out.println("Question 3- Do you like Minecraft?");

athree = ian.nextDouble();

if(athree == 1)

lettuce = 1;

else

lettuce = 0;

answer = bacon + cheese + lettuce;

if(answer < 1){

System.out.println("You are super lame.");

}

if(answer == 1){

System.out.println("You are lame");

}

if(answer == 2){

System.out.println("You are kinda cool");

}

if(answer == 3){

System.out.println("You are cool. Nice job bro.");

}

}

}

It works fine as is, but how can I change this so the user inputs a 'yes' or 'no answer instead of '1' or '2'?

Thanks

3 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Even better:

    String ans = ian.next();

    if (ans.equalsIgnoreCase("yes")) { .....

  • 1 decade ago

    Lol, nice quiz.

    aone = ian.next();

    aone = aone.toLowerCase();

    if(aone.equals("yes"))

    ........something like this.

    Hope that helps.

    =D

  • 1 decade ago

    use this code:

    if(aone.equals(yes))

    this is used in comparing strings

Still have questions? Get your answers by asking now.