Question: Hello, please help with this Java switch/case below to make it work with the while/if statement and make it work with the class HashSet. So

Hello, please help with this Java switch/case below to make it work with the while/if statement and make it work with the class HashSet. So if the user type in for example 1234 the class HashSet shall check if numbers already exist in the system? (Or am I wrong about HashSet?) As it is now the user can still type in same number combination and the prinln "already exist" does not show. Thanks!  
switch (choice) { case 1: { while(true) { System.out.print("Enter customer unique ssn: "); ssn = sc.nextInt(); if (hashSet.contains(ssn)) { System.out.println("Ssn already exist"); continue; } else break; } 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!