public class SavingsAccount {
private double interestRate;
private double balance;
private double monthlyRate = interestRate / 12;
private double deposits;
private double withdraws;
private double monthInterest;
String getBalance;
public SavingsAccount(double balance, double interestRate) {
this.balance = balance;
this.interestRate = interestRate;
}
SavingsAccount() {
throw new UnsupportedOperationException("This is not yet implemented");
}
public void withdraw(double amount) {
balance = balance - amount;
withdraws = withdraws + amount;
}
public void deposit(double amount) {
balance = balance + amount;
deposits = deposits + amount;
}
public void addInterest() {
balance = balance + monthInterest;
}
public double monthInterest() {
monthInterest = balance * monthlyRate;
return monthInterest;
}
public double getBalance() {
return balance;
}
public double getInterestRate() {
return interestRate;
}
public double getLastInterest(double LastInterest) {
return LastInterest;
}
public double getDeposit() {
return deposits;
}
public double getWithdraw() {
return withdraws;
}
}
========================================================================
import java.text.DecimalFormat;
import java.util.Scanner;
public class SavingsAccountTest {
public static void main(String args[], int months, double
deposit, double withdraw, double totalInterestEarned) {
double interestRate; // Annual interest rate
double balance; // Starting balance
double deposits; // Amount of deposits for a month
double withdraws; // Amount withdrawn in a month
double totalInterest; // Interest earned
double month; // Months that have passed
// Deposit accumulator
// Withdrawal accumulator
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the starting balance.
System.out.println("What is the starting balance of your account?");
balance = keyboard.nextDouble();
// Get the annual interest rate.
System.out.println("What is the interest rate of your account?");
interestRate = keyboard.nextDouble();
// Create a SavingsAccount object.
SavingsAccount account = new SavingsAccount(balance, interestRate);
// Get the number of months that have passed.
System.out.println("How many months have passed since you got your " +
"account?");
month = keyboard.nextDouble();
// Get the deposits and withdrawals for each month.
for (int i = 1; i <= months; i++) {
System.out.println("How much money was deposited into your " +
"account in month " + i + "?");
deposit = keyboard.nextDouble();
account.deposit(deposit);
System.out.println("How much money was withdrawn from your " +
"account in month " + i + "?");
withdraw = keyboard.nextDouble();
account.withdraw(withdraw);
System.out.println("The interest earned for this month is ");
account.monthInterest();
totalInterestEarned = totalInterestEarned + account.monthInterest();
}
// Create a DecimalFormat object for formatting output.
DecimalFormat dollar = new DecimalFormat("#,##0.00");
// Display the totals and the balance.
System.out.println("The total amount of deposits was $" +
account.getDeposit() + ". Your total withdrawls in " +
"your account was $" + account.getWithdraw() + ". The total " +
"amount of interest earned was $" + totalInterestEarned + ". " +
"The current balance is " + account.getBalance);
}
}
======================================================================
import java.util.*;
import java.io.*;
import java.text.*;
public class SavingsAccountTest2 {
public static void main(String[] args) throws IOException {
double accumulator = 0.0;
double TotalWithdrawal = 0.0;
String filename1 = "Deposits.txt";
String filename2 = "Withdrawals.txt";
NumberFormat cf = NumberFormat.getCurrencyInstance();
SavingsAccount account = new SavingsAccount();
File file1 = new File(filename1);
Scanner input = new Scanner(file1);
while (input.hasNext()) {
double data = input.nextDouble();
accumulator += data;
}
account.deposit(accumulator);
input.close();
File file2 = new File(filename2);
Scanner input2 = new Scanner(file2);
while (input2.hasNext()) {
double data2 = input2.nextDouble();
TotalWithdrawal += data2;
}
account.withdraw(TotalWithdrawal);
input2.close();
account.getWithdraw();
System.out.println("You have earned " + cf.format(account.getInterestRate()) +
", resulting in a balance of " + cf.format(account.getBalance()));
}
}
THANKS IN ADVANCE

New Topic/Question
Reply



MultiQuote



|