Help please!! Create final variables that store a predefined username and passwo
ID: 3542699 • Letter: H
Question
Help please!!
Create final variables that store a predefined username and password (you can choose any values you want). Ask the user to enter their username and password. Check whether the username matches the username stored in your program. The username is not case sensitive. Check that the password matches the password stored in your program. The password is case sensitive. Print a message to the user whether access is granted or tell them what they did wrong i.e., if the username is wrong print "Wrong username" if the password is wrong "Wrong password". Use: equals and equalslgnoreCase from the String class for comparing Strings. I'm assuming that the username is Nikolajanevski and the password is CS110_Fall2013 User Input:: John WVU_footbal Output: Wrong username: User input: Nikolajanevski cs110_Fall2013 Output: Wrong password User Input: nikolajanevski CS110_Fall2013 Output: Access granted Ask the user to enter an email. Check that the email address entered by the user contains an also check that it doesn't contain whitespaces. User input: njanevsk@mix.wvu.edu Output: Valid email.Explanation / Answer
import java.util.Scanner;
public class UserName {
public static void main(String args[]){
final String username = "NikolaJanevski";
final String password = "CS110_Fall2013";
//username=username.toLowerCase();
String temp;
String temppass;
System.out.println("enter user name ");
Scanner in = new Scanner(System.in);
temp=in.nextLine();
System.out.println("enter password ");
temppass=in.nextLine();
//temp=temp.toLowerCase();
if(temp.equalsIgnoreCase(username)&&temppass.equals(password)){System.out.println("access granted ");}
else {if(!temp.equalsIgnoreCase(username)) System.out.println("wrong user name ");
if (!temppass.equals(password))System.out.println("wrong pass word ");}
}
}
import java.util.Scanner;
public class mailcheck {
public static void main(String args[]){
final String email;
System.out.println("enter email ");
Scanner in = new Scanner(System.in);
email=in.nextLine();
String checkat[]=email.split("@");
String checkspace[]=email.split(" ");
if(checkat.length==2 && checkspace.length==1) System.out.println("valid email");
else System.out.println("invalid email");
}}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.