Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with correct this below switch / case block java code, so the same ssn not can be entered by a user mistakenly again,
Please help with correct this below switch / case block java code, so the same ssn not can be entered by a user mistakenly again, when a new customer is registered by the user.
The problem is when the user add /registered a new customer, still the same ssn can be used/entered.
I don't have any compiler errors, but the if/else block doesn't work,
the user can sill type in same ssn that have been entered before when a another customer
was added/registered.
Thanks!
HashSet hashSet = new HashSet(); switch (choice) { case 1: { System.out.print("Enter customer unique ssn: "); ssn = sc.nextInt(); if (hashSet.contains(ssn)) { System.out.println("Ssn already exists"); } else { hashSet.add(ssn); System.out.print("Enter customer name: "); sc.nextLine(); String name = sc.nextLine(); Customer customer = new CustomerBuilder().setSsn(ssn).setName(name).createCustomer(); Bank.addCustomer(customer); System.out.println(" Customer added successfully with uniquely ssn: " + customer.getSSN()); } } break;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started