Here is the code for Q1-3. Can someone help with the abstract classes for numbers 4 and 5, please? Q1. Create a Java pro

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Here is the code for Q1-3. Can someone help with the abstract classes for numbers 4 and 5, please? Q1. Create a Java pro

Post by answerhappygod »

Here is the code for Q1-3. Can someone help with the abstractclasses for numbers 4 and 5, please?
Q1. Create a Java program with a class Account that has oneprivate instance variable Balance representing the account balance.The data type of the variable Balance is double. The class shouldprovide a parameterless constructor that initializes the instancevariable Balance to 0.0. The class should provide a constructorthat receives an initial balance via its parameter and uses it toinitialize the instance variable Balance. The class should have apublic setter method and a public getter method to set or get thevalue of the variable Balance. When setting variable Balance, thesetter should validate the balance to ensure that the valueassigned to the variable should be greater than or equal to 0.0.Otherwise, the setter should give an error message and set thevalue assigned to the variable Balance to 0.0. The getter methodshould return the current balance, i.e. the current value of thevariable Balance, The class should provide two public methods. Amethod named Credit should add an amount to the current balance. Amethod named Debit should withdraw money from the account andensure that the debit amount does not exceed the account’s balance.If it does, the balance should be left unchanged, and the methodshould display the message "Debit amount exceeded account balance!"to the user. After defining the class above, create a class namedAccountTest that creates an instance of the class Account and teststhe methods of the class Account. That is, the instance will showthe initial balance, deposit some money, show the updated balance,withdraw some money, and show the updated balance.
Q2. Create a derived class named SavingsAccount thatinherits from the class Account that was created in Q1. The derivedclass SavingsAccount should include an instance variable Rateindicating the interest rate (percentage) assigned to the account.The data type of the variable Rate should be double. The classSavingsAccount has two constructors. One is a parameterlessconstructor which always initializes the initial balance to 0.0,and the interest rate to 0.02. The other constructor of the classSavingsAccount should receive the initial balance, as well as aninitial value for the interest rate via its parameters, and theninitialize the corresponding variables. The class SavingsAccountshould provide a public method named CalculateInterest that returnsa double indicating the amount of interest earned by an account.The method CalculateInterest should determine this amount bymultiplying the interest rate by the account balance. [Note:SavingsAccount should inherit methods Credit and Debit withoutredefining them.] After defining the class, create a class namedSavingsAccountTest that creates an instance of the classSavingsAccount and tests the methods of the base class and derivedclass. That is, the instance will show the initial balance, depositsome money, show the updated balance, withdraw some money, and showthe updated balance.
Q3. Create a derived class named CheckingAccount thatinherits from the base class Account created in Q1 and has aninstance variable named Fee. The variable Fee represents the feecharged per transaction. The class CheckingAccount has twoconstructors. One is a parameterless constructor that initializesthe balance and the fee to 0.0. The other constructor shouldreceive the initial balance and fee amount via its parameters andthen assign them to the corresponding variables. The classCheckingAccount should redefine the methods Credit and Debit in thebase class so that they can subtract the fee from the accountbalance whenever either transaction is performed successfully.However, the CheckingAccount’s Debit method should charge a feeonly if the money is actually withdrawn (i.e., the debit amountdoes not exceed the account balance). After defining the class,create a class named CheckingAccountTest that creates an instanceof the class CheckingAccount and tests the methods of the classCheckingAccount. That is, the instance will show the initialbalance, deposit some money, show the updated balance, withdrawsome money, and show the updated balance.
*** The code to this point has been answered***
Q4. Modify the class Account in Q1 to an abstract class. Themethod Credit and the method Debit are redefined as two abstractmethods. Modify the derived class SavingsAccount in Q2 and thederived class CheckingAccount in Q3. [Hint: implement the methodCredit and the method Debit in each derived class.] After definingthe class, create a class named AccountTest. It creates an instanceof the class CheckingAccount and tests the methods of the classCheckingAccount. In addition, it also creates an instance of theclass SavingsAccount and tests the methods of the classSavingsAccount. That is, each instance will show the initialbalance, deposit some money, show the updated balance, withdrawsome money, and show the updated balance.
Q5. Rewrite the program in Q1 with an interface. That is, youuse an interface to replace the abstract class and, if needed,modify any other members. After defining the class, create a classnamed AccountTest. It creates an instance of the classCheckingAccount and tests the methods of the class CheckingAccount.In addition, it also creates an instance of the classSavingsAccount and tests the methods of the class SavingsAccount.That is, each instance will show the initial balance, deposit somemoney, show the updated balance, withdraw some money, and show theupdated balance. Note: we have discussed a lot of Java techniques.So when working on this problem, you can develop the programflexibly, such as adding additional fields and methods and/ormodifying any members.
Expert Answer
Anonymous answered this140 answers
Ans 1) The Answer to the Question no.1 is as follows:
The Sample output for the Question no. 1 is as follows:
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 1
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 1 (4.53 KiB) Viewed 52 times
Ans 2) The Answer to the Question no.2 is as follows:
The Sample output for the Question no.2 is as follows:
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 2
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 2 (5.8 KiB) Viewed 52 times
Ans 2) The Answer to the Question no.3 is as follows:
The Sample output for the Question no.3 is as follows
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 3
Here Is The Code For Q1 3 Can Someone Help With The Abstract Classes For Numbers 4 And 5 Please Q1 Create A Java Pro 3 (9.73 KiB) Viewed 52 times
C:\Users\HP\Desktop>java Initial Balance: 0.0 Account Test Balance after crediting 500 is: 500.0 Balance after debiting 400 is: 100.0
C:\Users\HP\Desktop>java Initial Balance: 0.0 Savings Account Test 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 CheckingAccount Test 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply