Question

x= Suppose you are building a program for teaching kids math. Write a java program the does the following: 1. Ask the user i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code for the required program is given below.

Main.java

/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;

public class Main
{
public static final int PASSWORD_LENGTH = 8;
  
public static boolean is_Valid_Password(String password) {

if (password.length() < PASSWORD_LENGTH) return false;

int charCount = 0;
int numCount = 0;
for (int i = 0; i < password.length(); i++) {

char ch = password.charAt(i);

if (is_Numeric(ch)) numCount++;
else if (is_Letter(ch)) charCount++;
else return false;
}

if((charCount + numCount ) >= 8)
return true;
else
return false;
}

public static boolean is_Letter(char ch) {
ch = Character.toUpperCase(ch);
return (ch >= 'A' && ch <= 'Z');
}
public static boolean is_Numeric(char ch) {
return (ch >= '0' && ch <= '9');
}

  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String signin;
       Random rand = new Random();
       int n1,n2,sum,userAns;
       System.out.print("Do you want to sign up ?");
       signin = sc.nextLine();
       if(signin.equalsIgnoreCase("no"))
       {
       System.exit(0);
       }
       else
       if(signin.equalsIgnoreCase("yes"))
       {
       String user,pass;
       System.out.print("Enter a user name : ");
       user = sc.nextLine();
       System.out.print("Enter a Valid Password : ");
       pass = sc.nextLine();
      
       if (is_Valid_Password(pass)) {
System.out.println("Your Password has been saved");
for(int i=0;i<5;i++){
n1 = rand.nextInt(100);
n2 = rand.nextInt(100);
sum = n1 + n2;
System.out.print(""+ n1 + " + "+ n2 + " = ");
userAns = sc.nextInt();
if(sum == userAns)
{
System.out.println("Correct !");
}
else
{
System.out.println("Wrong ! The Correct answer is " + sum);
}
}
} else {
System.out.println("Your Password is not valid");
}
      
       }
  
   System.out.println("Well Done See you next Time");
   }
}

Output

Do you want to sign up ?yes Enter a user name : Vaibhav Enter a Valid Password : cookies007 Your Password has been saved 0 +

Add a comment
Know the answer?
Add Answer to:
x= Suppose you are building a program for teaching kids' math. Write a java program the...
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
  • Write a C++ program to allow an user to enter username and password, and then compare...

    Write a C++ program to allow an user to enter username and password, and then compare the entered values with the values which stored in a file called login.txt. Display an message "Login successful" if the values are matched, otherwise display "Login fail!. This program allow the user to have three times of tries, if exceeded the number of times, display a message "Number of times is exceeded, please contact administrator (Assume, the stored username is "INTI-IU and password is...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • Write a Python (3) program to simulate** a buffer overflow (this is a new script, not...

    Write a Python (3) program to simulate** a buffer overflow (this is a new script, not part of the intranet assignment), then implement input validation to prevent it. There are two parts to this assignment: 1) The program should display a welcome message and prompt the user for a username. Create a simulated buffer overflow condition by allowing a user to input more data than the size of the allocated memory (causing the program to crash). 2) Implement input validation...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Write a java application that is including a three-question multiple choice quiz about Java programming language....

    Write a java application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to 4). Also, ask user to type 0 to exit the test. [Assume that a user enters only integers 1,2,3,4, or 0]. Firstly, display a message that this quiz includes three questions about the Java programming language and display that each question has four possible answers. If the answer is correct for the given question,...

  • need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user...

    need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...

  • FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java....

    FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java. Include these steps: Write an application that provides the criteria for a strong password, and accepts a user's password from an input dialog box. If the entered password is less than six characters, more than 10 characters, or does not contain at least one uppercase letter and one digit, prompt the user to enter again. When the user's entry meets all the password requirements,...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

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