Question

In this assignment, you will be creating a program that requires a secret code to “unlock.”...

In this assignment, you will be creating a program that requires a secret code to “unlock.” The program should first welcome the user and ask the user to input his/her name. Then the program will greet the user using the entered name.

In order to “crack the code,” the user must input three integer numbers which satisfy the following conditions:
The first number must be the number 3.
The second number can either be the number 1 or be between 33 and 100, inclusive.
The third number must be a positive number that is either evenly divisible by 3 or evenly divisible by 7

As the user enters each number, the program should immediately check whether or not the number satisfies its respective requirement(s) listed above. If the requirement(s) is satisfied, then a “Correct!” confirmation should be printed out. If the requirement(s) is NOT satisfied, then an error message should be printed out, and the user cannot input any more numbers. (i.e. if the user input 5 as the first number, then the user has failed to crack the code, and cannot guess the second or third number.)

Please refer to the sample outputs below for formatting. (Any output statements from the program must match the sample formatting exactly.)

Sample Run 1:

Welcome. What is your name?
Jane Doe
Hello Jane Doe. Try your best to crack the code!

PHASE 1
Enter a number:
3
Correct!

PHASE 2
Enter a number:
40
Correct!

PHASE 3
Enter a number:
6
Correct!
You have cracked the code! 

Sample Run 2:

Welcome. What is your name?
Jane Doe
Hello Jane Doe. Try your best to crack the code!

PHASE 1
Enter a number:
0
Sorry, that was incorrect!
Better luck next time!

Sample Run 3:

Welcome. What is your name?
John Doe
Hello John Doe. Try your best to crack the code!

PHASE 1
Enter a number:
3
Correct!

PHASE 2
Enter a number:
2
Sorry, that was incorrect!
Better luck next time!

NOTE: You MUST use the class name "Main" for this assignment.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package Chegg;

import java.util.Scanner;

public class Main {

public static void main(String args[]){

String name;

int phase1, phase2, phase3;

Scanner sc = new Scanner(System.in);

System.out.println("Welcome. What is your name?");

name = sc.nextLine();

System.out.println("Hello "+name+". Try your best to crack the code!");

System.out.println();

System.out.println("PHASE 1");

phase1 = sc.nextInt();

if(phase1 == 3)

System.out.println("Correct!");

else{

System.out.println("Sorry, that was incorrect!\nBetter luck next time!");

System.exit(0);

}

System.out.println();

System.out.println("PHASE 2");

phase2 = sc.nextInt();

if(phase2 == 1 || (phase2 >=33 && phase2 <=100))

System.out.println("Correct!");

else{

System.out.println("Sorry, that was incorrect!\nBetter luck next time!");

System.exit(0);

}

System.out.println();

System.out.println("PHASE 3");

phase3 = sc.nextInt();

if( phase3 > 0 && ( phase3 %3 == 0 || phase3 %7 == 0))

System.out.println("Correct!");

else{

System.out.println("Sorry, that was incorrect!\nBetter luck next time!");

System.exit(0);

}

System.out.println();

System.out.println("You have cracked the code! ");

}

}

Add a comment
Know the answer?
Add Answer to:
In this assignment, you will be creating a program that requires a secret code to “unlock.”...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a modular program using pseudo-code which prompts a user for their first name, followed by...

    Design a modular program using pseudo-code which prompts a user for their first name, followed by their last name; then displays a "Hello" salutation which concatenates their first name with their last name. Sample output (user input shown in red): Please enter your first name: John Please enter your last name: Smith Hello, John Smith! Your program must include a main module and one function; this function prompts the user for either their first name or last name, using a...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • 1. Write and debug a MIPS program that performs the following operations . Prompt for and...

    1. Write and debug a MIPS program that performs the following operations . Prompt for and input three integers "a", "b and "c" using syscalls (3 points) Print all numbers starting from "a" upto "b" (including, but not exceeding "b") at an increment equal to value of"c"(5 points) If ba, then no numbers are printed, and a message is printed to inform it to the user. (3 points) Print the number and average of the generated numbers printed. (3 points)...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • Python Programming Write a program that reads the dimension of a rectangle and prints its area....

    Python Programming Write a program that reads the dimension of a rectangle and prints its area. The program must handle errors such invalid input. If it encounters an error, it should ask the user to reenter the input. Sample run: Enter height:abc abc is not a vaid input. Try again. Enter height:10 Enter width:hello hello is not a vaid input. Try again. Enter width:world world is not a vaid input. Try again. Enter width:xyz xyz is not a vaid input....

  • code creating

    Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...

  • Create a program that will ask for the name, age, address, and favorite food of the...

    Create a program that will ask for the name, age, address, and favorite food of the user. After which, create a calculator with ADD, SUB, MULTI, and DIV. Then the program will display all the user have inputted in bash program ACTIVITY 4: Create a program that will ask for the name, age, address, and favorite food of the user. After which create a calculator with ADD, SUB, MULTI, and DIV. Then the program will display all the user have...

  • Exercise 1 A program was created that outputs the following unto the console: Hello! What is...

    Exercise 1 A program was created that outputs the following unto the console: Hello! What is your name: Hello, Jane Doe! Using this program, we can help you determine you pay for the week! Please enter the hours you worked this week: 20 Next, please enter your rate of pay: 10 Calculating… you will make $ 200 by the end of the week! Here is the code for that program (you should have written a close variant of this last...

  • c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called...

    c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called MinilabLoopLogic which does the following Asks the user to enter 2 integers (can be one prompt or two) Gets and stores the ints Explains that the program will generate all integers that are between the numbers and are divisible by a third integer . e Asks the user for the number they should be divisible by Gets and stores that int Since 0 will...

  • Modify your program from Assignment # 7 part b (see below for code) by creating an...

    Modify your program from Assignment # 7 part b (see below for code) by creating an interactive GUI application that displays the list of the orders read in from the file (create a data file using your CreateBankFile.java program which has a least 10 bank account records in it and include it with your submission) and the total number of bank accounts. When your program starts it will first read the records from the Bank Account file (AccountRecords.txt) and creates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT