Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please add comments to the code so i can understand it, thanks Design and implem

ID: 3720307 • Letter: P

Question

Please add comments to the code so i can understand it, thanks

Design and implement a Java program to create a system that will keep track of customers and their accounts at a local bank branch. The program will maintain a current list of customers and their account information. Customer data for the program includes a customer’s first and last name, a customer ID, a customer e-mail address (valid emails contain an @ and .), a customer telephone number, a customer’s pin number and an array of accounts owned by the customer. The array of accounts should contain the following: types of account (savings, checking, money market, deposit box), the account number or a box number in the case of a deposit box, the current balance in each individual account (a deposit box does not need this information). The maximum number of accounts a customer can have is five. Error checking of all data is required. The program should allow entry of customer information via the keyboard with the maximum number of customers being 30, but the array can contain less. Once the data is entered the program should then allow the user to retrieve either the entire list of customers along with their account(s) information or an individual customer’s information via their customer ID number.

Explanation / Answer

//create a class CustomerBean to hold the customer data

import java.util.Map;

public class CustomerBean {

String firstName;

String lastName;

String customerId;

String emailID;

Long customerTelPhone;

int customerPin;

Map<String, Integer> accountsBalance;

int accountNumOrBoxNum;

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public String getCustomerId() {

return customerId;

}

public void setCustomerId(String customerId) {

this.customerId = customerId;

}

public String getEmailID() {

return emailID;

}

public void setEmailID(String emailID) {

this.emailID = emailID;

}

public Long getCustomerTelPhone() {

return customerTelPhone;

}

public void setCustomerTelPhone(Long customerTelPhone) {

this.customerTelPhone = customerTelPhone;

}

public int getCustomerPin() {

return customerPin;

}

public void setCustomerPin(int customerPin) {

this.customerPin = customerPin;

}

public Map<String, Integer> getAccountsBalance() {

return accountsBalance;

}

public void setAccountsBalance(Map<String, Integer> accountsBalance) {

this.accountsBalance = accountsBalance;

}

public int getAccountNumOrBoxNum() {

return accountNumOrBoxNum;

}

public void setAccountNumOrBoxNum(int accountNumOrBoxNum) {

this.accountNumOrBoxNum = accountNumOrBoxNum;

}

}

//create a MainClass for the logic as requested

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;

public class MainClass {

static Map<String, CustomerBean> customerData = new HashMap<String, CustomerBean>();

static Map<Integer, String> accouttypeMap = new HashMap<Integer, String>();

static {

accouttypeMap.put(1, "saving");

accouttypeMap.put(2, "checking");

accouttypeMap.put(3, "money market");

accouttypeMap.put(4, "deposit");

}

public static void main(String[] args) {

System.out.println("please enter a count of customers details you want to register -- strict int");

Scanner s = new Scanner(System.in);

int countOfCustoemrs = -1;

try {

countOfCustoemrs = s.nextInt();

while(countOfCustoemrs > 20) {

System.out.println("Please enter a value less than or equal to 20");

countOfCustoemrs = s.nextInt();

}

}catch(Exception e ) {

System.out.println("something went wrong - please start again");

}

for(int i = 0; i< countOfCustoemrs; i++) {

consumeCustomerData(s);

}

System.out.println("Plese enter a customer ID to fetch the data");

System.out.println("please enter 0 to exit from the process");

System.out.println("please enter 1 to fetch all customers data");

String cusID = "";

do {

cusID = s.next();

try {

if(cusID.equalsIgnoreCase("1")) {

for (String custID : customerData.keySet()) {

getCustomerWithID(custID);

}

}else {

getCustomerWithID(cusID);

}

}catch(NullPointerException e) {

System.out.println("the entered customer does not exists -- process terminated thanks for using");

}

}while(cusID!="0");

}

private static void getCustomerWithID(String cusID) {

CustomerBean res = customerData.get(cusID);

System.out.println("firstName+lastName :"+res.getFirstName() +" "+res.getLastName());

System.out.println("Customer ID "+ res.getCustomerId());

System.out.println("email id "+res.emailID);

System.out.println("customer tel number "+ res.getCustomerTelPhone());

System.out.println("customer Pin "+ res.getCustomerPin());

System.out.println("customer Acc num "+res.getAccountNumOrBoxNum());

for (String accType: res.getAccountsBalance().keySet()) {

System.out.println("Account Type "+accType +" acc Balance "+res.getAccountsBalance().get(accType));

}

}

private static void consumeCustomerData(Scanner s) {

CustomerBean c = new CustomerBean();

System.out.println("please enter customer firstName");

String customerName = s.next();

while(customerName=="" || customerName==null) {

System.out.println("please enter a valid customer first name");

customerName = s.next();

}

c.setFirstName(customerName);

System.out.println("plese enter customer lastname");

String customerLastName = s.next();

while(customerLastName=="" || customerLastName==null) {

System.out.println("please enter a valid customer first name");

customerLastName = s.next();

}

c.setLastName(customerLastName);

System.out.println("please enter customerID");

String customerID = s.next();

while(customerID=="" || customerID==null) {

System.out.println("please enter a valid number");

customerID = s.next();

}

c.setCustomerId(customerID);

System.out.println("please enter customer email id ");

String emailId = s.next();

while(emailId =="" || emailId == null) {

System.out.println("please enter a valid email id");

emailId = s.next();

}

c.setEmailID(emailId);

System.out.println("please enter customer Telephone number -- strict int");

Long num = s.nextLong();

c.setCustomerTelPhone(num);

System.out.println("please enter customer PIN -- strict int");

int pin = s.nextInt();

c.setCustomerPin(pin);

System.out.println("plese enter how many accounts you want to enter for this customer -- strict int");

int countOfAcc = s.nextInt();

while(countOfAcc>6) {

System.out.println("please enter a value less than or equal to 5");

}

Map<String, Integer> accountTypeBalance = new HashMap<String, Integer>();

for(int i=0; i<countOfAcc; i++) {

System.out.println("please enter customer customer account type saving/checking/money market/deposit box");

System.out.println("select 1 for saving, 2 for checking, 3 for money market, 4 or deposit box -- strict int");

int accountType = s.nextInt();

System.out.println("please enter the account balance -- strict int");

int accountBalance = s.nextInt();

accountTypeBalance.put(accouttypeMap.get(accountType), accountBalance);

}

c.setAccountsBalance(accountTypeBalance);

System.out.println("please enter accoutn number -- strict int");

try {

int accntNum = s.nextInt();

c.setAccountNumOrBoxNum(accntNum);

}catch(Exception e){

System.out.println("somwthign went wrong.. only int allowed");

}

customerData.put(customerID, c);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote