Main Class:
package pkg6;
import static java.lang.System.exit;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
Login l=new Login();
System.out.println("Enter Id: ");
String id = sc.nextLine();
System.out.println("Enter Password: ");
String pass = sc.nextLine();
if(l.compare(id, pass)==true)
{
System.out.println("Login Successful.
");
Menu m = new Menu();
m.showMenu();
int choice = sc.nextInt();
if(choice==1)
{
//do something
}
else if(choice==2)
{
//do something
}
else if(choice==3)
{
//do something
}
else if(choice==4)
{
exit(0);
}
}
else
{
System.out.println("Wrong Information!!!!!");
}
}
}
Login Class:
package pkg6;
public class Login
{
private final String id = "12462486";
private final String pass = "j3GbAeY6";
public boolean compare(String id,String pass)
{
if(this.id.equals(id) && this.pass.equals(pass))
{
return true;
}
else
{
return false;
}
}
}
Menu Class:
package pkg6;
public class Menu
{
public void showMenu()
{
System.out.println("Main Menu");
System.out.println("1: Check Balance
2:Withdraw
3: Deposit
4: Exit");
System.out.printf("Your Choice: ");
}
}
Output
Enter Id:12462486
Enter Password:j3GbAeY6
Login Successful
Main Menu
1: Check Balance
2:Withdraw
3: Deposit
4: Exit
Your Choice: 4
Add your comment