A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Quiz program in Javascript (Help!!!)

  1. #1
    Junior Member
    Join Date
    Sep 2016
    Posts
    1

    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("Welcomeisney’s Dwarf tester!");
    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1n-O");
    System.out.println("2epy");
    System.out.println("3etara");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1thro");
    System.out.println("2hful");
    System.out.println("3ra");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1rf");
    System.out.println("2");
    System.out.println("3ald Duck");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1key Mouse");
    System.out.println("2ezy");
    System.out.println("3nie Mouse");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1fy");
    System.out.println("2py");
    System.out.println("3thcliff");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1y");
    System.out.println("2mpy");
    System.out.println("3ey");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    System.out.println("\nPleasect the correct dwarf…");
    System.out.println("1ie");
    System.out.println("2ey");
    System.out.println("3ooge McDuck");

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

    //Switch

    switch(input){
    case 1:
    System.out.println("Wrongction");
    break;
    case 2:
    System.out.println("Hiyou picked the correct one");
    break;
    case 3:
    System.out.println("Wrongction");
    break;
    default:
    System.out.println("Invalidction");
    break;
    }

    if(input > 1){
    System.out.println("Goingit");
    if(input > 2){
    System.out.println("Almoste");
    if(input > 3){
    System.out.println("You it");
    }
    }
    }

    }

    }

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

    Thanks for any help.


  2. #2
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    This is *FLASH*Kit

    Java != JavaScript

    Do your own homework
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  3. #3
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    But he said 'please' Oh wait, he did not.

    Here is my code
    Pasting to ideone, I get
    Main.java:3: error: class Disney is public, should be declared in a file named Disney.java
    public class Disney {
    ^
    1 error
    who is this? a word of friendly advice: FFS stop using AS2

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    If I change Disney to Main I get
    Welcomeisney’s Dwarf tester!

    Pleasect the correct dwarf…
    1n-O
    2epy
    3etara
    Sigh. But this is just not inspiring to continue.
    who is this? a word of friendly advice: FFS stop using AS2

  5. #5
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    northcodes right this is flavascript no jerver scuript

  6. #6
    Member
    Join Date
    Oct 2016
    Posts
    54
    maybe he want java instead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center