Your first task is to create a method called CreateAccount. The method will ask
ID: 3682617 • Letter: Y
Question
Explanation / Answer
import java.util.Scanner;
/**
* @author srinu
*
*/
public class CreateAccount {
/**
* @param args
*/
public static void main(String[] args) {
// calling the method and printing the result
System.out.println(CreateAccount());
}
/**
*
* method to read user name and valid password and return the result
*
* @return
*/
public static String CreateAccount() {
// declaring the variables
Scanner scanner = null;
String userName = null;
int password = 0;
try {
// initializing the scanner
scanner = new Scanner(System.in);
// prompt the user to enter user name
System.out.print("Enter the User Name:");
// reading username from console
userName = scanner.next();
// infinite loop for reading valid password
do {
// prompt the user to enter password
System.out.print("Enter the Password:");
// reading password from console
password = scanner.nextInt();
// check the password is between 500 and 600
// if it is true break otherwise continue the loop to read the
// password
if (password > 500 && password < 600)
break;
else
System.out.println("Try Again!");
} while (true);
} catch (Exception e) {
// TOeDO: handle exception
} finally {
scanner.close();
}
// return the result
return userName + "," + password;
}
}
OUTPUT:
Enter the User Name:mary
Enter the Password:100
Try Again!
Enter the Password:200
Try Again!
Enter the Password:502
mary,502
NOTE:
code is well comented wich keeps the pseudocode at comments in the method,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.