At the end of the activity, the students should be able to: • Create a program that invokes static methods and uses static variables. Procedure: 1. Develop a simple program for an individual savings account. Create two (2) classes named SavingsAccount (no class modifier) and RunSavingsAccount (public). 2. In the SavingsAccount class, declare/Initialize variables based on the table below. Access Level Static? Variable Name No Yes Data Type double double private public balance interestRate Value None 3. Within the constructor, initialize balance with the value of 0. 4. Declare a static setter method named setInterestRate with a parameter of double type named newRate. This method should assign newRate to interestRate. All methods in the program should be public. 5. Add a static method named get InterestRate and a non-static method named getBalance, where each returns an appropriate variable. Both should of double type. 6. Declare a void method named deposit with a parameter of double type named amount. This method should update balance by adding an amount to it. 7. Add another method of double type named withdraw with a parameter of double type also named as amount. Create an if-else statement based on this condition: If balance is greater than or equal than amount, deduct amount from balance; else, amount is equal to 0. Return the amount afterwards. 8. Add a void method named addInterest. Within this method, declare a double variable named interest that accepts the product of balance and interestRate. Update balance by adding interest to it. 9. Declare a void static method named showBalance witha parameter of SavingsAccount type named account. This method should display the current balance of the account by calling the getBalance() method using the object account. 10. Move to the other class, RunSavingsAccount. Import the Scanner class for the user input. 11. Instantiate a SavingsAccount object named savings in the main method to use the methods you have created earlier. This should be the expected sequence of the program upon execution: a. Ask the user to input the interest rate. b. Ask the user to type an amount to be deposited. c. Ask the user to press either D for another deposit or W for withdraw. Show balance afterward. If savings is greater than 1000, display the new balance with applied interest.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

show how it is done and explain

At the end of the activity, the students should be able to:
• Create a program that invokes static methods and uses static variables.
Procedure:
1. Develop a simple program for an individual savings account. Create two (2) classes named
SavingsAccount (no class modifier) and RunSavingsAccount (public).
2. In the SavingsAccount class, declare/Initialize variables based on the table below.
Data Type
double
double
Access Level
private
public
Variable Name
balance
interestRate
Static?
Value
None
No
Yes
3. Within the constructor, initialize balance with the value of 0.
4. Declare a static setter method named setInterestRate with a parameter of double type named
newRate. This method should assign newRate to interestRate. All methods in the program should
be public.
5. Add a static method named getInterestRate and a non-static method named getBalance, where
each returns an appropriate variable. Both should of double type.
6. Declare a void method named deposit with a parameter of double type named amount. This
method should update balance by adding an amount to it.
7. Add another method of double type named withdraw with a parameter of double type also named
as amount. Create an if-else statement based on this condition: If balance is greater than or equal
than amount, deduct amount from balance; else, amount is equal to 0. Return the amount
afterwards.
8. Add a void method named addInterest. Within this method, declare a double variable named
interest that accepts the product of balance and interestRate. Update balance by adding
interest to it.
9. Declare a void static method named showBalance with a parameter of SavingsAccount type named
account. This method should display the current balance of the account by calling the
getBalance() method using the object account.
10. Move to the other class, RunSavingsAccount. Import the Scanner class for the user input.
11. Instantiate a SavingsAccount object named savings in the main method to use the methods you
have created earlier. This should be the expected sequence of the program upon execution:
a. Ask the user to input the interest rate.
b. Ask the user to type an amount to be deposited.
Ask the user to press either D for another deposit or W for withdraw. Show balance
afterward. If savings is greater than 1000, display the new balance with applied interest.
C.
Transcribed Image Text:At the end of the activity, the students should be able to: • Create a program that invokes static methods and uses static variables. Procedure: 1. Develop a simple program for an individual savings account. Create two (2) classes named SavingsAccount (no class modifier) and RunSavingsAccount (public). 2. In the SavingsAccount class, declare/Initialize variables based on the table below. Data Type double double Access Level private public Variable Name balance interestRate Static? Value None No Yes 3. Within the constructor, initialize balance with the value of 0. 4. Declare a static setter method named setInterestRate with a parameter of double type named newRate. This method should assign newRate to interestRate. All methods in the program should be public. 5. Add a static method named getInterestRate and a non-static method named getBalance, where each returns an appropriate variable. Both should of double type. 6. Declare a void method named deposit with a parameter of double type named amount. This method should update balance by adding an amount to it. 7. Add another method of double type named withdraw with a parameter of double type also named as amount. Create an if-else statement based on this condition: If balance is greater than or equal than amount, deduct amount from balance; else, amount is equal to 0. Return the amount afterwards. 8. Add a void method named addInterest. Within this method, declare a double variable named interest that accepts the product of balance and interestRate. Update balance by adding interest to it. 9. Declare a void static method named showBalance with a parameter of SavingsAccount type named account. This method should display the current balance of the account by calling the getBalance() method using the object account. 10. Move to the other class, RunSavingsAccount. Import the Scanner class for the user input. 11. Instantiate a SavingsAccount object named savings in the main method to use the methods you have created earlier. This should be the expected sequence of the program upon execution: a. Ask the user to input the interest rate. b. Ask the user to type an amount to be deposited. Ask the user to press either D for another deposit or W for withdraw. Show balance afterward. If savings is greater than 1000, display the new balance with applied interest. C.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY