02 Laboratory Exercise 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

IT1908

Laboratory Exercise
Savings Account
Objective:

At the end of the activity, the students should be able to:

 Create a program that invokes static methods and uses static variables.

Software Requirements:

 Latest version of NetBeans IDE


 Java Development Kit (JDK) 8

Procedure:

1. Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark)


2. Develop a simple program for an individual savings account. Create a new project named LabExer3.
Set the project location to your own folder. The main class should be named RunSavingsAccount.
Then, add another class called SavingsAccount.
3. Start coding the SavingsAccount class.
4. Declare/Initialize variables based on the table below.
Data Type Access Level Static? Variable Name Value
double private No balance None
double public Yes interestRate 0
5. Within the constructor, initialize balance with the value of 0.
6. 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.
7. Add a static method named getInterestRate and a non-static method named getBalance, where
each returns an appropriate variable. Both should of double type.
8. 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.
9. 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.
10. 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.
11. 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.
12. Move to the other class, RunSavingsAccount. Import the Scanner class for the user input.
13. 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.

02 Laboratory Exercise 1 *Property of STI


Page 1 of 2
IT1908

Sample Output:

GRADING RUBRIC (100 points):

Criterion Description Max Points


Correctness The code produces the expected result. 40
Logic The code meets the specifications of the problem. 40
Efficiency The code is concise without sacrificing correctness and logic. 10
Syntax The code adheres to the rules of the programming language. 10

References:
Farrell, J. (2014). Java programming (7th ed.). Boston: Course Technology, Cengage Learning.
Savitch, W. (2014). Java: An introduction to problem solving and programming (7th ed.). New Jersey:
Pearson Education, Inc.

02 Laboratory Exercise 1 *Property of STI


Page 2 of 2

You might also like