Write a short program in the main to generate the following

Write a short program in the main to generate the following dialogue: CA. Administrator: CAWindowslsystem32Mcmd.exe Adata 201701 csc110A labs lab3 iava Lab hat\'s your name Uictoria. Hi, Victoria! Enter a natural number: 75 75 is an odd number. Now explore the methods in the String class, declare two String objects String student1 V0 0123456\" String student2 new String (\"V00234567\"); Check if the two objects are equal, play with some of the methods: length(), equals0, compare To0, charAt0, equalsIgnoreCase0, What does operator do when you compare two objects? Write a program and ask the user to type a password as least 8 characters long and including at least a digit, an upper case letter and a lower case letter. Tell the user it is a good password if all three requirements are met, if not, tell the user why

Solution

A. The Java Program to generate the dialog box is as follows ,

import javax.swing.JOptionPane;

public class Main {
public static void main(String[] argv) throws Exception {

JOptionPane.showMessageDialog(null, \"C:/data/201701/csc110/labs/lab3>java Lab3\ \"
+ \"What\'s your name? Victoria\ \"
+ \"Hi, Victoria!\ \"
+ \"Enter a natural number:75\ \"
+ \"75 is an odd number\ \");

}
}

B. The two string classes are declared as follows,

C. There are three methods of comparing strings in java,

They are , equals() method , compareTo() method and by using \" == \" operator .

In the below program the two methods equals() and equalsIgnoreCase() are given,

The Program below gives the example for charAt() method,

The Java Program below gives the example for length() method,

The \" == \" operator compares the object references between the given two objects or strings.

D. The Java program to validate a password is given as ,

class PasswordValidator
{
public PasswordValidator()
{
super();
}

public static void main(String[] args)
{
PasswordValidator passwordValidator = new PasswordValidator();
  
String userName;
userName = \" ABC \";
String passWord = \" java \";
System.out.println(\"Input : UserName \"+userName+\" PassWord -> \"+passWord);
  
passwordValidator.passwordValidation(userName,passWord);
System.out.println();
passWord = \" Java10* \";
System.out.println(\"Input : UserName \"+userName+\" PassWord -> \"+passWord);
passwordValidator.passwordValidation(userName,passWord);
}

/*
* Password should contain more than 8 characters in length.
* Password should contain at least one upper case and one lower case alphabet.
* Password should contain at least one digit.
*/

public void passwordValidation(String userName, String password)
{
boolean valid = true;
if (password.length() > 15 || password.length() < 8)
{
System.out.println(\"Password should be less than 15 and more than 8 characters in length.\");
valid = false;
}
if (password.indexOf(userName) > -1)
{
System.out.println(\"Password Should not be same as user name\");
valid = false;
}
String upperCaseChars = \"(.*[A-Z].*)\";
if (!password.matches(upperCaseChars ))
{
System.out.println(\"Password should contain atleast one upper case alphabet\");
valid = false;
}
String lowerCaseChars = \"(.*[a-z].*)\";
if (!password.matches(lowerCaseChars ))
{
System.out.println(\"Password should contain atleast one lower case alphabet\");
valid = false;
}
String numbers = \"(.*[0-9].*)\";
if (!password.matches(numbers ))
{
System.out.println(\"Password should contain atleast one digit.\");
valid = false;
}
  
if (valid)
{
System.out.println(\"Password is valid.\");
}
}
}

 Write a short program in the main to generate the following dialogue: CA. Administrator: CAWindowslsystem32Mcmd.exe Adata 201701 csc110A labs lab3 iava Lab hat
 Write a short program in the main to generate the following dialogue: CA. Administrator: CAWindowslsystem32Mcmd.exe Adata 201701 csc110A labs lab3 iava Lab hat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site