I'm using Eclipse and even though I've done more challenging things than this I keep getting stuck no matter how hard I hammer away at it.
This is a package, so the end of the first part (Driver Class?) is really what I'm having trouble with. Comments are included in the code. Also including the second part/ class is included.
Any guidance, help, flashing light bulbs would be greatly appreciated.
package 6;
import java.util.Scanner;
import java.text.DecimalFormat;
/**
* @author Me
*
*/
public class testAccount {
/**
* @param args
*/
public static void main(String[] args) {
String input;
double balance = 0, InterestRate = 0;
double interest, deposit, withdrawals;
double totalInterest=0, totalDeposits=0, totalWithdrawals=0;
int month=0;
char repeat='Y';
Scanner keyboard = new Scanner(System.in);
DecimalFormat degrees = new DecimalFormat("#,###.00");
System.out.println("What is your account's starting balance?");
balance= keyboard.nextDouble();
System.out.println("What is your annual interest rate?");
InterestRate= keyboard.nextDouble();
SavingsAccount account= new SavingsAccount (balance, InterestRate);
interest=account.MonthlyInterestRate(InterestRate);
balance=account.calculateInterest(balance);
//me testing to see If I can at least get the right balance but
///Something is wrong with my decimal formatter,
//keeps adding two 00's when I tested it
System.out.println("Your balance is is" +degrees.format(balance));
//How do I step into this Loop?
while ( repeat =='Y'|| repeat =='y');
{
month++;
System.out.println("What are your deposits?");
deposit=keyboard.nextDouble();
account.deposit(deposit);
System.out.println( "your deposits" +deposit);
System.out.println("balance" +balance);
System.out.println("What are your withdrawals?");
withdrawals=keyboard.nextDouble();
account.withdraw(withdrawals);
//Around here I'm supposed to be using the Accumulators to set keep count of
//totalwithdrawals,totaldeposits etc.
System.out.println("Calculate Month" + (month +1) + "Y/N .");
repeat=keyboard.nextLine().charAt(0);
}
System.exit(0);
}
}
and this is what it links to
I'm pretty sure (92% at least)most of it is correct
package 6;
/**
The BankAccount class simulates a bank account.
*/
public class BankAccount
{
private double balance; // Account balance
private double annualinterestrate;
/**
This constructor sets the starting balance
at 0.0.
* @param input2
* @param input
*/
public BankAccount()
{
balance = 0.0;
annualinterestrate=0.0;
}
/**
This constructor sets the starting balance
to the value passed as an argument.
@param startBalance The starting balance.
*/
public BankAccount(double startBalance, double InterestRate)
{
balance = startBalance;
annualinterestrate=InterestRate;
}
public double MonthlyInterestRate(double annualrate)
{
annualinterestrate=annualrate;
return annualrate /12;
}
//public void MonthlyInterestRate(String input2) {
// TODO Auto-generated method stub
//annualinterestrate= Double.parseDouble(input2);
//}
public double calculateInterest(double annualrate)
{
// add code to calculate interest
balance += annualrate * balance;
return balance;
}
/**
This constructor sets the starting balance
to the value in the String argument.
@param str The starting balance, as a String.
*/
public BankAccount(String str )
{
balance = Double.parseDouble(str);
}
/**
The deposit method makes a deposit into
the account.
@param amount The amount to add to the
balance field.
*/
public void deposit(double amount)
{
balance += amount;
}
/**
The deposit method makes a deposit into
the account.
@param str The amount to add to the
balance field, as a String.
*/
//This is
public void deposit(String str)
{
balance += Double.parseDouble(str);
}
/**
The withdraw method withdraws an amount
from the account.
@param amount The amount to subtract from
the balance field.
*/
public void withdraw(double amount)
{
balance -= amount;
}
/**
The withdraw method withdraws an amount
from the account.
@param str The amount to subtract from
the balance field, as a String.
*/
public void withdraw(String str)
{
balance -= Double.parseDouble(str);
}}
/**
The setBalance method sets the account balance.
@param b The value to store in the balance field.
*/