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

Need help with this project and not able to complete. Listed complete details be

ID: 3658877 • Letter: N

Question

Need help with this project and not able to complete. Listed complete details below. Thanks!





Bank Account Class

In this program we simulate small part of an account in a bank. The class has the following private

instance data members, which are all declared private. Their description, data types, and suggested

names for them are also given.


Instance data member

Description

Instance data member data type Suggested variable name


Account number associated withthe bank account =integer ActNum

Last Name of the account holder = String LastName

First Name of the account holder = String FirstName

Current Balance in dollars in theaccount =double balance


Table 1

Proceed in the following manner to code either using textpad or Eclipse.

1. Generate a Java class called BankAccount.

2. Add the data members (all private) described in the table 1 to the class.

3. Write an explicit constructor, in above class, which takes four arguments, each one of which

maps to the four class instance data members. The suggested header (first line) for the

constructor is shown.


public BankAccount(int act, String first, String last, double bal)

{

//body of explicit constructor

}

4. Write a print method in class BankAccount whose suggested header is given below.

public void print()

{

Class member ActNum willbe equal to act Class member

FirstName will be equalto first.

Class member LastName will beequal to last

Class member balance willbe equal to bal.


//body of print method

}

This method prints all class data member values to console. Use printf for currency formatting

and output to console.


5. Write another class (suggested name: MainClass), and write a main method in it.


6. In main method call the explicit constructor you wrote in step 3 and pass some hard coded

values as arguments to this constructor. This way you are creating an object of type

BankAccount in your main method. Suggested values for example are as follows:

Account number: 5623

First Name: Jim

Last Name: Jones

Balance: 100.89


7. Call the print method for the BankAccount object you created in step 6 which when you run the

program would print same values that you passed to explicit constructor as arguments. This will

confirm that your explicit constructor is working correctly. If not then fix all errors at this point.


8. Back to the BankAccount class: Now write a method called deposit which simulates depositing

money in a bank account. Deposit method will take a double type argument which is the

amount of money customer wishes to deposit to their current account. Thus after deposit

method is executed the customer

Explanation / Answer

Please find below the program. public class BankAccount { Integer actNum; String lastName; String firstName; double balance; public Integer getActNum() { return actNum; } public BankAccount(Integer actNum, String lastName, String firstName, double balance) { super(); this.actNum = actNum; this.lastName = lastName; this.firstName = firstName; this.balance = balance; } public void setActNum(Integer actNum) { this.actNum = actNum; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public void print() { System.out.println("Account Number: " + this.actNum); System.out.println("First Name: " + this.firstName); System.out.println("Last Name: " + this.lastName); System.out.println("Balance: " + this.balance); } public void deposit(double money) { this.setBalance(this.getBalance() + money); } public void withdrawal(double money) { if (money > this.getBalance()) System.out.println("Insufficient funds"); else this.setBalance(this.getBalance() - money); } } import java.util.Scanner; public class MainClass { public static void main(String[] args) { BankAccount ba = new BankAccount(5623, "Jim", "Jones", 100.89); ba.print(); System.out.println("How much Amount need to be deposited?"); Scanner sc = new Scanner(System.in); ba.deposit(sc.nextDouble()); System.out.println("Details after depositing"); ba.print(); System.out.println("How much Amount need to be withdrawn?"); ba.withdrawal(sc.nextDouble()); System.out.println("Details after withdrawing"); ba.print(); } } Output: Account Number: 5623 First Name: Jones Last Name: Jim Balance: 100.89 How much Amount need to be deposited? 20 Details after depositing Account Number: 5623 First Name: Jones Last Name: Jim Balance: 120.89 How much Amount need to be withdrawn? 30 Details after withdrawing Account Number: 5623 First Name: Jones Last Name: Jim Balance: 90.89 import java.io.FileWriter; import java.util.Scanner; public class ClientMainClass { public static void main(String[] args) throws Exception { BankAccount ba = new BankAccount(5623, "Jim", "Jones", 100.89); Scanner sc = new Scanner(System.in); System.out.println("Select a Menu Item"); System.out .println("1. Create an instance of Bank Account from keyboard data entry."); System.out .println("2. Print the details of Bank Account instance to console."); System.out .println("3. Print details of Bank Account instance to an output file."); System.out.println("4. Make a deposit."); System.out.println("5. Make a withdrawal."); System.out.println("6. Print current balance."); System.out.println("7. Print account holder’s full name."); System.out.println("8. Exit"); Integer value = sc.nextInt(); while (value != 8) { if (value == 1) { ba = new BankAccount(5623, "Jim", "Jones", 100.89); System.out.println("Bank account instane created"); } if (value == 2) ba.print(); if (value == 3) { System.out.println("Enter the output file name"); String outputFile = sc.next(); FileWriter out = new FileWriter(outputFile); out.write("Account Number: " + ba.actNum); out.write("First Name: " + ba.firstName); out.write("Last Name: " + ba.lastName); out.write("Balance: " + ba.balance); out.close(); } if (value == 4) { System.out.println("How much Amount need to be deposited?"); ba.deposit(sc.nextDouble()); } if (value == 5) { System.out.println("How much Amount need to be withdrawn?"); ba.withdrawal(sc.nextDouble()); } if (value == 6) { System.out.println("Printing current balance"); ba.print(); } if (value == 7) { System.out.println(ba.firstName + ba.lastName); } if (value == 8) System.exit(0); System.out.println("Select a Menu Item"); System.out .println("1. Create an instance of Bank Account from keyboard data entry."); System.out .println("2. Print the details of Bank Account instance to console."); System.out .println("3. Print details of Bank Account instance to an output file."); System.out.println("4. Make a deposit."); System.out.println("5. Make a withdrawal."); System.out.println("6. Print current balance."); System.out.println("7. Print account holder’s full name."); System.out.println("8. Exit"); value = sc.nextInt(); } } } Output: Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 1 Bank account instane created Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 2 Account Number: 5623 First Name: Jones Last Name: Jim Balance: 100.89 Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 3 Enter the output file name aaa.txt Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 4 How much Amount need to be deposited? 20 Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 5 How much Amount need to be withdrawn? 30 Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 6 Printing current balance Account Number: 5623 First Name: Jones Last Name: Jim Balance: 90.89 Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 7 JonesJim Select a Menu Item 1. Create an instance of Bank Account from keyboard data entry. 2. Print the details of Bank Account instance to console. 3. Print details of Bank Account instance to an output file. 4. Make a deposit. 5. Make a withdrawal. 6. Print current balance. 7. Print account holder’s full name. 8. Exit 8 Hope it helps.