Question
solve this JAVA problem in NETBEANS
Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the answer:

SavingsAccount.java

import java.util.Scanner;

public class SavingsAccount {
    Scanner sc = new Scanner(System.in);
    private double annualRate;
    private double balance;
    private int months;
    private double totalWithdraw;
    private double totalDeposite;
    private double totalInterest;

    public double getBalance() {
        return balance;
    }

    SavingsAccount(int months, double balance, double annualRate){
        this.months = months;
        this.balance = balance;
        this.annualRate = annualRate;

    }

    public double getAnnualRate() {
        return annualRate;
    }

    public void setAnnualRate(double annualRate) {
        this.annualRate = annualRate;
    }

    public int getMonths() {
        return months;
    }

    public void setMonths(int months) {
        this.months = months;
    }

    public void withdraw(double amount){
        if(amount > balance || amount < 0)
        {
            System.out.println("Insufficient amount! Please enter again: ");
            amount = sc.nextDouble();
            balance -= amount;
            totalWithdraw += amount;
        }else {
            balance -= amount;
            totalWithdraw += amount;
        }
    }

    public void deposite(double amount){
        if(amount < 0)
        {
            System.out.println("Insufficient amount! Please enter again: ");
            amount = sc.nextDouble();
            balance += amount;
            totalDeposite += amount;
        }else {
            balance += amount;
            totalDeposite += amount;
        }
    }

    public void calculateInterest(){
        double interest = annualRate / 12;
        double interestAmount = (balance * (interest/100));
        totalInterest += interestAmount;
        balance += interestAmount;
    }

    public void print(){
        System.out.println("Total Withdraw: " + totalWithdraw);
        System.out.println("Total Deposite: " + totalDeposite);
        System.out.println("Total Interest: " + totalInterest);

    }


}

main.java

import java.util.Scanner;

public class main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int months;
        double balance;
        double interest;

        System.out.println("How many months passed?");
        months = sc.nextInt();
        System.out.println("Starting balance: ");
        balance = sc.nextDouble();
        System.out.println("Annual Interest Rate: ");
        interest = sc.nextDouble();

        SavingsAccount account = new SavingsAccount(months, balance, interest);

        for(int i = 1 ; i <= months; i++){
            System.out.println("Enter Deposite amount for month " + i + ":");
            double amount = sc.nextDouble();
            System.out.println("Enter Withdraw amount for month " + i + ":");
            double withdraw = sc.nextDouble();
            account.deposite(amount);
            account.withdraw(withdraw);
            account.calculateInterest();
            System.out.println("Balance for month " + i + " : " + account.getBalance());
        }

        account.print();

    }
}

Output:

How many months passed? 3 Starting balance: 30000 Annual Interest Rate: 12 Enter Deposite amount for month 1: 3000 Enter With

Add a comment
Know the answer?
Add Answer to:
solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account...

    C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following A) Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the...

  • i need this to be in OOP using C++ 25. Savings Account Balance Write a program...

    i need this to be in OOP using C++ 25. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three-month feried. It should ask the user for the starting balance and the annual interest rate. A loop abculd then iterate once for every month in the period, performing the following steps: B) A) Ask the user for the total amount deposited into the account during that month and add it...

  • BankAccount and SavingsAccount Classes (JAVA)

    Must be in GUI interfaceDesign an abstract class namedBankAccountto hold the following data for a bankaccount:* Balance* Number of deposits this month* Number of withdrawals (this month)* Annual interest rate* Monthly service chargesThe class should have the following methods:Constructor: The constructor should accept arguments for the balance and annual interest rate.deposit: A method that accepts an argument for the amount of the deposit. The methods should add the argument to the account balance. It should also increment thevariable holding the...

  • JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to...

    JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to store the annual interest rate for all account holders. Each object of the class should contain a private instance variable named, savingsBalance, indicating the amount the saver currently has on deposit. Write methods to perform the following: calculateMonthlyInterest – calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. This interest should be added to the balance. depositAmount – allows the...

  • Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the...

    Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12- this interest should be added to savingsBalance. Provide a static method setInterestRate that sets the annualInterestRate to a new value....

  • JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design...

    JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design an abstract class named BankAccount to hold the following data for a bank account: • Balance • Number of deposits this month • Number of withdrawals • Annual interest rate • Monthly service charges The class should have the following methods: Constructor:   The constructor should accept arguments for the balance and annual interest rate. deposit:             A method that accepts an argument for the amount of...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

  • JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest...

    JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest rate 5%. So, the monthly interest rate is 0.05/12 = 0.00417. After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 After the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417)...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT