Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

ISBN: 0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago