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

OBJECT ORIENTED PROGRAMING CONCEPTS USING METHODS OBJECTIVE: Students will gain

ID: 3740465 • Letter: O

Question

OBJECT ORIENTED PROGRAMING CONCEPTS USING METHODS OBJECTIVE: Students will gain experience using methods and setting parameter/argument lists 1. Create a class called BankAccount_yourName save it as BankAccount_yourName It will be a generic simple type of BankAccount (not Checking, not Savings just BankAccount) a. 2. BankAccount will contain variables to store: the owner/owners of the account(owner is of type Person object) accountBalance it may contain other basic information (up to you) a. b. c. 3. BankAccount will contain methods that will allow you to: a. Set the account owners information (this method will create a person object) b. Deposit money (does the math to calculate the balance) C. Withdraw money (does the math to calculate the balance d. Print out transactions (think more like an atm ...each time an action is taken it gets printed) 4. BankAccount will contain its own main() a. Create one BankAccount_yourName object named richGuy Call all of the methods declared in the class Create a second object of type BankAccount_yourName and call it poorGuy User the Scanner object and its methods to allow end user keyboard input b. c. HINTS: 1. Make sure you save Person and BankAccount in the same folder. 2. Don't forget to import java.util.Scanner; . Add comments to your code 4. We will use this code for a couple of weeks and add to it.

Explanation / Answer

import java.util.Scanner;
public class BankAccount_YourName{
int AccountNumber,AccountBalance;
String AccountHolderName;
public void setAccountNumber(int AccountNumber){
this.AccountNumber=AccountNumber;
}
public int getAccountNumber(){
return AccountNumber;
}
public void setAccountBalance(int AccountBalance){
this.AccountBalance=AccountBalance;
}
public int getAccountBalance(){
return AccountBalance;
}
public void getdetails(){
System.out.println("AccountNumber--->"+AccountNumber);
System.out.println("AccountBalance--->"+AccountBalance);
System.out.println("AccountHolderName--->"+AccountHolderName);
}
public void setAccountHolderName(String AccountHolderName){
this.AccountHolderName=AccountHolderName;
}
public String getAccountHolderName(){
return AccountHolderName;
}
public int DepoistMoney(int money){
this.AccountBalance=AccountBalance+money;
return AccountBalance;
}
public int WithdrawMoney(int money){
this.AccountBalance=AccountBalance-money;
return AccountBalance;
}

public static void main(String []args){
BankAccount_YourName RichGuy = new BankAccount_YourName();
RichGuy.setAccountNumber(54321);
RichGuy.setAccountHolderName("RichGuy");
RichGuy.setAccountBalance(2000);
BankAccount_YourName PoorGuy = new BankAccount_YourName();
PoorGuy.setAccountNumber(12345);
PoorGuy.setAccountHolderName("PoorGuy");
PoorGuy.setAccountBalance(100);
Scanner sc=new Scanner(System.in);
System.out.println("Please select the Bank_Object");
System.out.println("1------>RichGuy");
System.out.println("2------>PoorGuy");
int Selected_Object = sc.nextInt();
if(Selected_Object==1){
System.out.println("Your Selected Object is RichGuy");
}
if(Selected_Object==2){
System.out.println("Your Selected Object is PoorGuy");
}
if(Selected_Object==1 || Selected_Object==2){
System.out.println("Modes Of Operations:");
System.out.println("1--->Display the AccountDetails");
System.out.println("2--->Depoist the Money");
System.out.println("3--->Withdraw the Money");
System.out.println("4--->Exit");
while(1>0){
int Selected_Mode = sc.nextInt();
if(Selected_Mode==1){
if(Selected_Object==1){
RichGuy.getdetails();
}
else{
PoorGuy.getdetails();
}
continue;
}
if(Selected_Mode==2){
System.out.println("Please Enter Depoist Amount:");
int depoist_amount = sc.nextInt();
if(Selected_Object==1){
System.out.println("Your Transaction Details:");
System.out.println("Old_Balance----->"+RichGuy.getAccountBalance());
System.out.println("New_Balance----->"+RichGuy.DepoistMoney(depoist_amount));
}
else{
System.out.println("Your Transaction Details:");
System.out.println("Old_Balance----->"+PoorGuy.getAccountBalance());
System.out.println("New_Balance----->"+PoorGuy.DepoistMoney(depoist_amount));
}
continue;
}
if(Selected_Mode==3){
System.out.println("Please Enter WithDraw Amount:");
int withdraw_amount = sc.nextInt();
if(Selected_Object==1){
if(RichGuy.getAccountBalance()>withdraw_amount){
System.out.println("Your Transaction Details:");
System.out.println("Old_Balance----->"+RichGuy.getAccountBalance());
System.out.println("New_Balance----->"+RichGuy.WithdrawMoney(withdraw_amount));}
else{
System.out.println("AccountBalance is too low....Can't withdraw amount");
}
}
else{
if(PoorGuy.getAccountBalance()>withdraw_amount){
System.out.println("Your Transaction Details:");
System.out.println("Old_Balance----->"+PoorGuy.getAccountBalance());  
System.out.println("New_Balance----->"+PoorGuy.WithdrawMoney(withdraw_amount));}
else{
System.out.println("AccountBalance is too low....Can't withdraw amount");
}
}
continue;
}
if(Selected_Mode==4){
System.out.println("Bye...Bye...");
break;
}

}
}
else{
System.out.println("You Selected Wrong Object");
}
}}

Note: Run the code in any ide or complier.........give file name same as the class name........give proper inputs for the Required OutPut...