Question: Create an Account class (java) with the following member data: 1. Account ID (a random 4-digit number that is generated when the object is created)

Create an Account class (java) with the following member data:

1. Account ID (a random 4-digit number that is generated when the object is created)

2. Balance (starts at $0.00 until a deposit is made)

Your program will read in commands from an input file and perform the corresponding transactions on an instance of Account:

? w - withdraw from the account (e.g. w 50? means withdraw $50). Print a message stating how much was withdrawn from the account. If the account will be overdrawn, cancel the withdraw and print an error message.

? d - deposit into the account (e.g. d 10? means deposit $10). Print a message stating how much was deposited into the account.

? i - add interest to the account. Print a message stating how much interest was added to the account. The interest rate is %0.5 (e.g. i? means multiply the current balance by 1.005). The interest rate should be stored as a final variable inside your class.

? p - prints the current balance of the account, formatted to 2 decimal places.

Notes

? Your program should utilize 2 separate files: Prog8.java? (for your main class) and Account.java? (for your Account class)

? You must make appropriate use of objects in this program to receive full credit (if you try to write the program without creating an Account class, you will not receive many points).

? For this program, you only need to create one instance of Account.

? All member data of class Account should be private. You should make appropriate use of constructors and getter/setter methods to interact with your data.

?Will be using import java.util.Scanner and will be using reader.hasNext and its variants

in1.dat

d 50

w 10

i

p

in1.dat example output:

$50.00 deposited into account 4978

$10.00 withdrawn from account 4978

$0.20 interest added to account 4978

Current balance for account 4978: $40.20

in2.dat

d 100

d 200

w 150

i

p

d 1000

p

w 1150.75

p

output:

$100.00 deposited into account 8890

$200.00 deposited into account 8890

$150.00 withdrawn from account 8890

$0.75 interest added to account 8890

Current balance for account 8890: $150.75

$1000.00 deposited into account 8890

Current balance for account 8890: $1150.75

$1150.75 withdrawn from account 8890

Current balance for account 8890: $0.00

in3.dat:

w 1

p

d 100

p

w 200

p

output:

Error: cannot withdraw $1.00

Current balance for account 3585: $0.00

$100.00 deposited into account 3585

Current balance for account 3585: $100.00

Error: cannot withdraw $200.00

Current balance for account 3585: $100.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!