Page 1 of 1

Create a class Account with one private instance variable Balance representing the account balance. The data type of th

Posted: Sun Jul 10, 2022 11:23 am
by answerhappygod
Create a class Account with one private instance variableBalance representing the account balance. The data type ofthe variable Balance is double. The class should provide aparameterless constructor that initializes the instance variableBalance to 0.0. The class should provide a constructor thatreceives an initial balance via its parameter and uses it toinitialize the instance variable Balance.
The class should have a public setter method and a public gettermethod to set or get the value of the variable Balance. Whensetting variable Balance, the setter should validate the balance toensure that the value assigned to the variable should be greaterthan or equal to 0.0. Otherwise, the setter should give an errormessage and set the value assigned to the variable Balance to 0.0.The getter method should return the current balance, i.e. thecurrent value of the variable Balance, The class should provide twopublic methods. A method named Credit should add an amount to thecurrent balance. A method named Debit should withdraw money fromthe account and ensure that the debit amount does not exceed theaccount’s balance. If it does, the balance should be leftunchanged, and the method should display the message "Debit amountexceeded account balance!" to the user.
After defining the class above, create a class named AccountTestthat creates an instance of the class Account and tests the methodsof the class Account. That is, the instance will show the initialbalance, deposit some money, show the updated balance, withdrawsome money, and show the updated balance.