I have figured out questions 1-3. I don't need a repost of questions 1-3. Can anyone use the code to answer questions 4
Posted: Thu Jul 14, 2022 2:12 pm
I have figured out questions 1-3. I don't need a repost of questions 1-3. Can anyone use the code to answer questions 4 and 5 about redefining Credit and Debit as ABSTRACT METHODS and rewriting Q1 with an INTERFACE? My base code is below. PLEASE HELP!
Q4. (40 points) Modify the class Account in Q1 to an abstract class. The method Credit and the method Debit are redefined as two abstract methods. Modify the derived class SavingsAccount in Q2 and the derived class CheckingAccount in Q3. [Hint: implement the method Credit and the method Debit in each derived class.] After defining the class, create a class named AccountTest. It creates an instance of the class CheckingAccount and tests the methods of the class CheckingAccount. In addition, it also creates an instance of the class SavingsAccount and tries the methods of the class SavingsAccount. That is, each instance will show the initial balance, deposit some money, show the updated balance, withdraw some cash, and show the updated balance.
Q5. (20 points) Rewrite the program in Q1 with an interface. You use an interface to replace the abstract class and, if needed, modify any other members. After defining the class, create a class named AccountTest. It creates an instance of the class CheckingAccount and tests the methods of the class CheckingAccount. In addition, it also creates an instance of the class SavingsAccount and tries the methods of the class SavingsAccount. That is, each instance will show the initial balance, deposit some money, show the updated balance, withdraw some cash, and show the updated balance. Note: we have discussed a lot of Java techniques. So when working on this problem, you can develop the program flexibly, such as adding any additional fields and methods, and/or modifying any members.
Ans 1) The Answer to the Question no.1 is as follows:
The Sample output for the Question no. 1 is as follows:
Ans 2) The Answer to the Question no.2 is as follows:
The Sample output for the Question no.2 is as follows:
Ans 2) The Answer to the Question no.3 is as follows:
The Sample output for the Question no.3 is as follows
C:\ Users \HP\ Desktop>java AccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0
C: \Users \HP\ Desktop>java SavingsAccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0 Interest for the rest amount is: 2.0
C: Users \HP\Desktop>java CheckingAccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0 After passing Balance as 1000 and fee as 20 Initial Balance: 100.0 Balance after crediting 500 is: 600.0 Balance after debiting 400 is: 200.0
Q4. (40 points) Modify the class Account in Q1 to an abstract class. The method Credit and the method Debit are redefined as two abstract methods. Modify the derived class SavingsAccount in Q2 and the derived class CheckingAccount in Q3. [Hint: implement the method Credit and the method Debit in each derived class.] After defining the class, create a class named AccountTest. It creates an instance of the class CheckingAccount and tests the methods of the class CheckingAccount. In addition, it also creates an instance of the class SavingsAccount and tries the methods of the class SavingsAccount. That is, each instance will show the initial balance, deposit some money, show the updated balance, withdraw some cash, and show the updated balance.
Q5. (20 points) Rewrite the program in Q1 with an interface. You use an interface to replace the abstract class and, if needed, modify any other members. After defining the class, create a class named AccountTest. It creates an instance of the class CheckingAccount and tests the methods of the class CheckingAccount. In addition, it also creates an instance of the class SavingsAccount and tries the methods of the class SavingsAccount. That is, each instance will show the initial balance, deposit some money, show the updated balance, withdraw some cash, and show the updated balance. Note: we have discussed a lot of Java techniques. So when working on this problem, you can develop the program flexibly, such as adding any additional fields and methods, and/or modifying any members.
Ans 1) The Answer to the Question no.1 is as follows:
The Sample output for the Question no. 1 is as follows:
Ans 2) The Answer to the Question no.2 is as follows:
The Sample output for the Question no.2 is as follows:
Ans 2) The Answer to the Question no.3 is as follows:
The Sample output for the Question no.3 is as follows
C:\ Users \HP\ Desktop>java AccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0
C: \Users \HP\ Desktop>java SavingsAccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0 Interest for the rest amount is: 2.0
C: Users \HP\Desktop>java CheckingAccountTest Initial Balance: 0.0 Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0 After passing Balance as 1000 and fee as 20 Initial Balance: 100.0 Balance after crediting 500 is: 600.0 Balance after debiting 400 is: 200.0