Java) Create a new project folder in Eclipse for this activity. In this folder, create two new classes - Account.java and Savings.java and put your name in a Javadoc comment at the top. Make the Account class an abstract class by adding the abstract keyword before the class keyword Inside the Account class, add the following variables and methods: A private variable called name (String) A private variable called balance (double) A two-argument constructor which takes in String and double parameters A no argument constructor, which calls the two-argument constructor, passing in "name unknown" and 0.0 as arguments. Getter and setter methods for the two variables An abstract method called updateBalance A toString() method Make the Savings class final by adding the final keyword before the class keyword - now this class cannot be extended (no inheritance from this class). Also make Savings a subclass of Account Inside the Savings class, add the following variables and methods: A private variable called interestRate (double) A three-argument constructor which takes in a String and two double parameters, and calls the two argument constructor of the Account class A no argument constructor, which calls the three-argument constructor of Savings, passing in "name unknown", 0.0, and 0.0 as arguments. Getter and setter methods for the interestRate variable A method called updateBalance that overrides the abstract method of the super class Note that it is required to override this method or your class will have an error This method is void and has no parameters It multiplies balance by 1 + interestRate and assigns the result to balance A toString() method that overrides toString from the superclass. Add a final class to your project folder called SavingsTest.java. Copy and paste the below code into this class. /** * SavingsTest.java * @author * CIS 36B, Activity 13.1 */ import java.util.Scanner; public class SavingsTest { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.println("Welcome!\n"); System.out.print("Enter your name: "); String name = input.nextLine(); System.out.print("Enter the balance to invest: $"); double balance = input.nextDouble(); System.out.print("Enter the interest rate on your target account: "); double interest = input.nextDouble(); Savings savings = new Savings(name, balance, interest); System.out.println("\nHere is your account summary: \n" + savings); savings.updateBalance(); System.out.printf("In one year, your balance" + " will be: $%.2f", savings.getBalance()); input.close(); } } When your program works as shown in the sample output, upload Account.java and Savings.java to Canvas. Sample Output: Welcome! Enter your name: Grace Kang Enter the balance to invest: $50000 Enter the interest rate on your target account: .025 Here is your account summary: Name: Grace Kang Balance: $50000.0 Interest Rate: 0.025 In one year, your balance will be: $51250.00
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
(Java)
- Create a new project folder in Eclipse for this activity.
- In this folder, create two new classes - Account.java and Savings.java and put your name in a Javadoc comment at the top.
- Make the Account class an abstract class by adding the abstract keyword before the class keyword
- Inside the Account class, add the following variables and methods:
- A private variable called name (String)
- A private variable called balance (double)
- A two-argument constructor which takes in String and double parameters
- A no argument constructor, which calls the two-argument constructor, passing in "name unknown" and 0.0 as arguments.
- Getter and setter methods for the two variables
- An abstract method called updateBalance
- A toString() method
- Make the Savings class final by adding the final keyword before the class keyword - now this class cannot be extended (no inheritance from this class).
- Also make Savings a subclass of Account
- Inside the Savings class, add the following variables and methods:
- A private variable called interestRate (double)
- A three-argument constructor which takes in a String and two double parameters, and calls the two argument constructor of the Account class
- A no argument constructor, which calls the three-argument constructor of Savings, passing in "name unknown", 0.0, and 0.0 as arguments.
- Getter and setter methods for the interestRate variable
- A method called updateBalance that overrides the abstract method of the super class
- Note that it is required to override this method or your class will have an error
- This method is void and has no parameters
- It multiplies balance by 1 + interestRate and assigns the result to balance
- A toString() method that overrides toString from the superclass.
- Add a final class to your project folder called SavingsTest.java. Copy and paste the below code into this class.
* SavingsTest.java
* @author
* CIS 36B, Activity 13.1
*/
import java.util.Scanner;
public class SavingsTest {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome!\n");
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.print("Enter the balance to invest: $");
double balance = input.nextDouble();
System.out.print("Enter the interest rate on your target account: ");
double interest = input.nextDouble();
Savings savings = new Savings(name, balance, interest);
System.out.println("\nHere is your account summary: \n" + savings);
savings.updateBalance();
System.out.printf("In one year, your balance"
+ " will be: $%.2f", savings.getBalance());
input.close();
}
}
- When your program works as shown in the sample output, upload Account.java and Savings.java to Canvas.
Sample Output:
Welcome!
Enter your name: Grace Kang
Enter the balance to invest: $50000
Enter the interest rate on your target account: .025
Here is your account summary:
Name: Grace Kang
Balance: $50000.0
Interest Rate: 0.025
In one year, your balance will be: $51250.00
- Create a new project folder in Eclipse for this activity.
- In this folder, create two new classes - Account.java and Savings.java and put your name in a Javadoc comment at the top.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images