3 Replies - 1716 Views - Last Post: 07 April 2009 - 01:06 AM Rate Topic: -----

#1 TankerIncident   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 16-February 09

SavingsAccount and SavingsAccountTests

Posted 06 April 2009 - 10:48 PM

I am doing some work for class and I have to create a savings account and it should store the account's interest rate and balance. I have to run 2 different test and I have done everything I knew, but it is not working. I am really lost and any help would be greatly appriciated. this is what I have so far I have it divided in 3 different pages:

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

Is This A Good Question/Topic? 0
  • +

Replies To: SavingsAccount and SavingsAccountTests

#2 Sentrosi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 03-April 09

Re: SavingsAccount and SavingsAccountTests

Posted 06 April 2009 - 11:35 PM

What's the issue you're having?
Was This Post Helpful? 0
  • +
  • -

#3 TankerIncident   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 16-February 09

Re: SavingsAccount and SavingsAccountTests

Posted 06 April 2009 - 11:40 PM

when i try to run the project, it tells me that the savingsAccountTest does not have a main method, and it says the same thing when i run it from the savingsAccount page. It just doesn't run the file
Was This Post Helpful? 0
  • +
  • -

#4 Sentrosi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 03-April 09

Re: SavingsAccount and SavingsAccountTests

Posted 07 April 2009 - 01:06 AM

I could be wrong, but I'm pretty sure you can't have any parameters in main besides (String[]args).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1