Please i need some help with this assigment in Java! Java Programming (Assignmen
ID: 3777994 • Letter: P
Question
Please i need some help with this assigment in Java!
Java Programming
(Assignment 2 - Selection)
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).
Submission
Submit the assignment in the assignments area in blackboard where you retrieved this assignment originally. You must submit a screenshot of the output with the following test cases.
Test case 1: Test the code with all dwarfs selected correctly
Test case 2: Test the code with only 4 dwarfs selected correctly.
If you have issues with your code, print it out and submit the hard copy in class.
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
Explanation / Answer
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(" Pleasect the correct dwarf…");
System.out.println("1n-O");
System.out.println("2epy");
System.out.println("3etara");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1thro");
System.out.println("2hful");
System.out.println("3ra");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1rf");
System.out.println("2");
System.out.println("3ald Duck");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1key Mouse");
System.out.println("2ezy");
System.out.println("3nie Mouse");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1fy");
System.out.println("2py");
System.out.println("3thcliff");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1y");
System.out.println("2mpy");
System.out.println("3ey");
input = keyboard.nextInt();
keyboard.nextLine();
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(" Pleasect the correct dwarf…");
System.out.println("1ie");
System.out.println("2ey");
System.out.println("3ooge McDuck");
input = keyboard.nextInt();
keyboard.nextLine();
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");
}
}
}
}
}