Web Analytics Made Easy -
StatCounter Quiz program in Javascript (Help!!!) - CodingForum

Announcement

Collapse
No announcement yet.

Quiz program in Javascript (Help!!!)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quiz program in Javascript (Help!!!)

    I have this assignment to do and I'm stuck on what to do from here.

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    You will use your knowledge of Java programming to create a test program for the seven dwarfs. Let’s pretend that Disney has hired you to make a java program that will test the knowledge of its users. The program will print a positive statement if they are correct and a negative statement if they are wrong.

    Concepts Learned
    • If Statements
    • Nested If Statements
    • Operator Precedence
    • Logical Operators
    • Boolean Data Types
    • Switch Statements
    • Conditional Expressions
    • Formatting console output
    • GUI Confirmation Dialogs

    Spec

    These are valid seven dwarfs: Sleepy, Bashful, Doc, Sneezy, Happy, Grumpy, Dopey

    These are not valid Dwarfs: Lion-O, Cheetara, Panthro, Tigra, Snarf, Donald Duck, Mickey Mouse, Minnie Mouse, Goofy, Heathcliff, Huey, Dewey, Louie, Scrooge McDuck,

    Declare these variables:
    int counter = 7;
    boolean firstSelection = false;
    boolean secondSelection = false;
    boolean thirdSelection = false;
    boolean fourthSelection = false;
    boolean fiveSelection = false;
    boolean sixSelection = false;
    boolean sevenSelection = false;

    The program will begin with a print statement that says “Welcome to Disney’s Dwarf Tester”
    Then another print statement will follow. It will say” Please pick the correct dwarf: 1. Non-valid dwarf, 2. Valid dwarf, 3. Non-valid dwarf”. (Please use a valid dwarf and two non-valid dwarfs from the list above)
    The user will make their choice by entering an integer (1, 2 or 3)
    You will create a switch statement to handle the choice selection
    When the wrong case is selected then decrement the int variable called counter and print to the console “wrong selection”
    When the correct case is selected then change the corresponding boolean variable to true (ie.. firstSelection, secondSelection, etc) and print to the console “Hi Ho, you picked the correct one”
    The default case will print a statement to the console “invalid selection”

    Repeat this seven times until you covered all seven dwarfs.

    At the end, create an if-else statement. This statement will have short circuit &&’s that will test all of the Boolean variables. If true, print a statement to the console “You earned a gold star!”. Else, print a statement to the console “You only got “ +counter + “ correct”. (counter is the variable).

    Output

    Welcome to Disney’s Dwarf tester!

    Please select the correct dwarf…. 1. Dopey, 2. Scrooge, 3. Mickey

    2

    Wrong selection

    Please select the correct dwarf…. 1. Scrooge, 2. Bashful, 3. Minnie

    2

    Hi Ho, you picked the correct one

    Please select the correct dwarf…. 1. Chuck, 2. Daisy, 3. Happy

    3

    Hi Ho, you picked the correct one

    Please select the correct dwarf…. 1. Doc, 2. George, 3. Mickey

    2

    Wrong selection

    Please select the correct dwarf…. 1. Sleepy, 2. Scrooge, 3. Mickey

    2

    Wrong selection

    Please select the correct dwarf…. 1. Grumpy, 2. Scrooge, 3. Mickey

    2

    Wrong selection

    Please select the correct dwarf…. 1. Sneezy, 2. Scrooge, 3. Mickey

    2

    Wrong selection

    You only got 2 correct

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Here is my code:

    import java.util.Scanner;

    public class Disney {

    public static void main(String[] args) {
    int input;
    Scanner keyboard;

    keyboard = new Scanner(System.in);

    System.out.println("Welcome to Disney’s Dwarf tester!");
    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Lion-O");
    System.out.println("2. Sleepy");
    System.out.println("3. Cheetara");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Panthro");
    System.out.println("2. Bashful");
    System.out.println("3. Tigra");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Snarf");
    System.out.println("2. Doc");
    System.out.println("3. Donald Duck");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Mickey Mouse");
    System.out.println("2. Sneezy");
    System.out.println("3. Minnie Mouse");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Goofy");
    System.out.println("2. Happy");
    System.out.println("3. Heathcliff");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Huey");
    System.out.println("2. Grumpy");
    System.out.println("3. Dewey");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    System.out.println("\nPlease select the correct dwarf…");
    System.out.println("1. Louie");
    System.out.println("2. Dopey");
    System.out.println("3. Scrooge McDuck");

    input = keyboard.nextInt();
    keyboard.nextLine();

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrong selection");
    break;
    case 2:
    System.out.println("Hi Ho, you picked the correct one");
    break;
    case 3:
    System.out.println("Wrong selection");
    break;
    default:
    System.out.println("Invalid selection");
    break;
    }

    if(input > 1){
    System.out.println("Going for it");
    if(input > 2){
    System.out.println("Almost there");
    if(input > 3){
    System.out.println("You made it");
    }
    }
    }

    }

    }

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Thanks for any help.

  • #2
    Well, part of your problem is following directions.

    If you were asked to create the program in Javascript,
    but you created it in Java,
    the instructor would have no choice but to fail you.

    Java != Javascript

    Wrong forum for help with Java

    Comment

    Working...
    X