0% found this document useful (0 votes)
21 views

Java PBL

The document describes a Java program that allows a user to log in with one of two roles: admin or underwriter. The program prompts the user to select a role, then calls the appropriate login method. The admin login method verifies the hardcoded admin password, while the underwriter login simply prints a success message without password checking.

Uploaded by

Vinay Dahiya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java PBL

The document describes a Java program that allows a user to log in with one of two roles: admin or underwriter. The program prompts the user to select a role, then calls the appropriate login method. The admin login method verifies the hardcoded admin password, while the underwriter login simply prints a success message without password checking.

Uploaded by

Vinay Dahiya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

task 1

import java.util.Scanner;

public class UserRoleLogin {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Select a role:");
System.out.println("1. Admin");
System.out.println("2. Underwriter");

int roleChoice = scanner.nextInt();


scanner.nextLine();

switch (roleChoice) {
case 1:
adminLogin();
break;
case 2:
underwriterLogin(scanner);
break;
default:
System.out.println("Invalid role choice.");
}

scanner.close();
}

private static void adminLogin() {


String adminUserId = "admin";
String adminPassword = "admin123";

Scanner scanner = new Scanner(System.in);

System.out.print("Enter admin password: ");


String enteredPassword = scanner.nextLine();

if (enteredPassword.equals(adminPassword)) {
System.out.println("Admin logged in successfully.");
} else {
System.out.println("Incorrect password. Access denied.");
}
}

private static void underwriterLogin(Scanner scanner) {


System.out.print("Enter underwriter userId: ");
String underwriterUserId = scanner.nextLine();

System.out.print("Enter underwriter password: ");


String underwriterPassword = scanner.nextLine();

System.out.println("Underwriter logged in successfully.");


}
}

You might also like