Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

(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

Expert Solution
Check Mark
Introduction
  • 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.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education