Hi
import java.util.Scanner;
public class ConsumerApp {
private static Consumer registeredConsumer = null;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
if (registeredConsumer == null) {
System.out.println("1. Register");
System.out.println("2. Login");
System.out.println("3. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
registeredConsumer = register(scanner);
break;
case 2:
if (login(scanner)) {
showHomePage(scanner);
} else {
System.out.println("Invalid credentials.");
}
break;
case 3:
System.exit(0);
default:
System.out.println("Invalid option, try again.");
}
} else {
showHomePage(scanner);
}
}
}
private static Consumer register(Scanner scanner) {
System.out.println("== Consumer Registration ==");
System.out.print("Consumer ID (13 digits): ");
String consumerId = scanner.nextLine();
System.out.print("Bill Number (5 digits): ");
String billNumber = scanner.nextLine();
System.out.print("Title (Mr/Ms/Mrs/Dr): ");
String title = scanner.nextLine();
System.out.print("Customer Name: ");
String customerName = scanner.nextLine();
System.out.print("Email: ");
String email = scanner.nextLine();
System.out.print("Country Code: ");
String countryCode = scanner.nextLine();
System.out.print("Mobile Number (10 digits): ");
String mobileNumber = scanner.nextLine();
System.out.print("User ID: ");
String userId = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
System.out.print("Confirm Password: ");
String confirmPassword = scanner.nextLine();
if (!password.equals(confirmPassword)) {
System.out.println("Passwords do not match. Please try again.");
return null;
}
Consumer consumer = new Consumer(consumerId, billNumber, title, customerName, email, countryCode, mobileNumber, userId, password);
System.out.println("Registration successful.");
System.out.println("Customer ID: " + consumer.getConsumerId());
System.out.println("Customer Name: " + consumer.getCustomerName());
System.out.println("Email: " + consumer.getEmail());
return consumer;
}
private static boolean login(Scanner scanner) {
System.out.println("== Login ==");
System.out.print("User ID: ");
String userId = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
return registeredConsumer != null && registeredConsumer.getUserId().equals(userId) && registeredConsumer.getPassword().equals(password);
}
private static void showHomePage(Scanner scanner) {
while (true) {
System.out.println("== Home ==");
System.out.println("Welcome, " + registeredConsumer.getCustomerName());
System.out.println("1. Pay Bill");
System.out.println("2. Register Complaint");
System.out.println("3. Complaint Status");
System.out.println("4. Logout");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
payBill(scanner);
break;
case 2:
registerComplaint(scanner);
break;
case 3:
viewComplaintStatus(scanner);
break;
case 4:
registeredConsumer = null;
return;
default:
System.out.println("Invalid option, try again.");
}
}
}
private static void payBill(Scanner scanner) {
System.out.println("== Pay Bill ==");
System.out.print("Enter the amount to pay: ");
double amount = scanner.nextDouble();
scanner.nextLine(); // Consume newline
System.out.print("Enter Payment Method (Credit/Debit): ");
String paymentMethod = scanner.nextLine();
System.out.println("Payment successful. Amount: $" + amount);
}
private static void registerComplaint(Scanner scanner) {
System.out.println("== Register Complaint ==");
System.out.print("Complaint Type (e.g., Billing, Voltage): ");
String complaintType = scanner.nextLine();
System.out.print("Description: ");
String description = scanner.nextLine();
System.out.println("Complaint registered successfully. Complaint Type: " + complaintType);
}
private static void viewComplaintStatus(Scanner scanner) {
System.out.println("== Complaint Status ==");
System.out.println("All complaints are resolved.");
}
}
class Consumer {
private String consumerId;
private String billNumber;
private String title;
private String customerName;
private String email;
private String countryCode;
private String mobileNumber;
private String userId;
private String password;
public Consumer(String consumerId, String billNumber, String title, String customerName, String email, String countryCode, String mobileNumber, String userId, String password) {
this.consumerId = consumerId;
this.billNumber = billNumber;
this.title = title;
this.customerName = customerName;
this.email = email;
this.countryCode = countryCode;
this.mobileNumber = mobileNumber;
this.userId = userId;
this.password = password;
}
public String getConsumerId() {
return consumerId;
}
public String getBillNumber() {
return billNumber;
}
public String getTitle() {
return title;
}
public String getCustomerName() {
return customerName;
}
public String getEmail() {
return email;
}
public String getCountryCode() {
return countryCode;
}
public String getMobileNumber() {
return mobileNumber;
}
public String getUserId() {
return userId;
}
public String getPassword() {
return password;
}
}