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

Part A Design a class called Customer. The Customer class should contain the fol

ID: 3605135 • Letter: P

Question

Part A

Design a class called Customer.

The Customer class should contain the following data:
firstName
lastName
accountNumber
accountBalance

Your class should have 2 constructors: one that just accepts the customer’s name, and one that also accepts the new account number and initial balance.

Your class should implement the “sets” and “gets” for the class, and contain a method to deposit, and a method to withdraw.

We will also add methods to “compare”, test for “equals”, and prepare information for display.

Explanation / Answer

public class Customer{
//instance variables
String firstName;
String lastName;
int accountNumber;
int accountBalance;
//constructors
public Customer(String firstName,String lastName){
this.firstName = firstName;
this.lastName = lastName;
}
public Customer(String firstName,String lastName,int accountNumber,int accountBalance){
this.firstName = firstName;
this.lastName = lastName;
this.accountNumber = accountNumber;
this.accountBalance = accountBalance;
}
  
//setter methods
public void setfirstName(String firstName){
this.firstName = firstName;
}
public void setlasttName(String lastName){
this.lastName = lastName;
}
public void setaccountNumber(int accountNumber){
this.accountNumber = accountNumber;
}
public void setaccountBalance(int accountBalance){
this.accountBalance = accountBalance;
}
  
//getter methods
public String getfirstName(){
return firstName;
}
public String getlastName(){
return lastName;
}
public int getaccountBalance(){
return accountBalance;
}
public int getaccontNumber(){
return accountNumber;
}
//deposit method to deposit amount
public void deposit(int amount){
accountBalance += amount;
}
//withdraw method to withdraw amount
public void withdraw(int amount){
if(accountBalance<amount){
System.out.println("balance is less than withdraw amount");
}
else{
accountBalance -= amount;
}
}
//compare method to test equals
public boolean compare(Customer c){
if(c.accountNumber == accountNumber){
return true;
}
else{
return false;
}
}
//display method to show values of Customer
public void display(){
System.out.println("Name:"+firstName+" "+lastName);
System.out.println("accountNumber:"+accountNumber);
System.out.println("accountBalance:"+accountBalance);
}
}