q2
import java.util.ArrayList;
import java.util.Scanner;
class CustomerRegistration {
// Class to store customer details
static class Customer {
String name;
String email;
String countryCode;
String mobileNumber;
String address;
String userID;
String password;
String preferences;
Customer(String name, String email, String countryCode, String mobileNumber, String address, String userID, String password, String preferences) {
this.name = name;
this.email = email;
this.countryCode = countryCode;
this.mobileNumber = mobileNumber;
this.address = address;
this.userID = userID;
this.password = password;
this.preferences = preferences;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Customer> customers = new ArrayList<>(); // To store registered customers
System.out.println("Customer Registration:");
// Input for Customer Name
System.out.print("Enter Customer Name (Max 50 characters): ");
String name = scanner.nextLine();
if (name.length() > 50) {
System.out.println("Name exceeds maximum character limit. Exiting...");
return;
}
// Input for Email
System.out.print("Enter Email: ");
String email = scanner.nextLine();
// Input for Mobile Number
System.out.print("Enter Country Code (e.g., +1, +91): ");
String countryCode = scanner.nextLine();
System.out.print("Enter 10-digit Mobile Number: ");
String mobileNumber = scanner.nextLine();
if (mobileNumber.length() != 10 || !mobileNumber.matches("\\d+")) {
System.out.println("Invalid mobile number. Exiting...");
return;
}
// Input for Address
System.out.print("Enter Address (including ZIP code and Parcel code): ");
String address = scanner.nextLine();
// Input for User ID
System.out.print("Enter User ID (5-20 characters): ");
String userID = scanner.nextLine();
if (userID.length() < 5 || userID.length() > 20) {
System.out.println("User ID does not meet length requirements. Exiting...");
return;
}
// Input for Password and Confirmation
System.out.print("Enter Password (Max 30 characters): ");
String password = scanner.nextLine();
if (password.length() > 30) {
System.out.println("Password exceeds maximum character limit. Exiting...");
return;
}
System.out.print("Confirm Password: ");
String confirmPassword = scanner.nextLine();
if (!password.equals(confirmPassword)) {
System.out.println("Passwords do not match. Exiting...");
return;
}
// Input for Preferences
System.out.print("Enter Preferences (e.g., mail delivery, notifications): ");
String preferences = scanner.nextLine();
// Add customer to the list
customers.add(new Customer(name, email, countryCode, mobileNumber, address, userID, password, preferences));
System.out.println("Customer registered successfully!");
// Display all registered customers
System.out.println("\nRegistered Customers:");
for (Customer customer : customers) {
System.out.println("Name: " + customer.name);
System.out.println("Email: " + customer.email);
System.out.println("Mobile: " + customer.countryCode + " " + customer.mobileNumber);
System.out.println("Address: " + customer.address);
System.out.println("User ID: " + customer.userID);
System.out.println("Preferences: " + customer.preferences);
System.out.println("--------------------------");
}
scanner.close();
}
}