我沒有從Eclipse中獲取錯誤,但是我的控制檯輸出不是它應該的。這些是我正在研究的兩個課程。在Eclipse中沒有完成程序輸出
頭等艙
public class BankAccount
{
private double balance;
private double interestRate;
private double interest;
public BankAccount(double startBalance, double intRate)
{
balance = startBalance;
interestRate = intRate;
interest = 0.0;
}
public void deposit(double amount)
{
balance += amount;
}
public void withdraw(double amount)
{
balance -= amount;
}
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}
public double getBalance()
{
return balance;
}
public double getInterest()
{
return interest;
}
}
下一個類
import java.util.Scanner;
import java.text.DecimalFormat;
public class Program2
{
public static void main(String[] args)
{
BankAccount account;
double balance = 500,
interestRate = 0.00125,
pay = 1000,
cashNeeded = 900;
Scanner keyboard = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat ("#0.00");
System.out.print("What is your account's starting balance?");
balance = keyboard.nextDouble();
System.out.print("What is your monthly interest rate?");
interestRate = keyboard.nextDouble();
account = new BankAccount(balance, interestRate);
System.out.print("How much were you paid this month? ");
pay = keyboard.nextDouble();
System.out.println("We will deposit your pay into your account.");
account.deposit(pay);
System.out.println("Your current balance is "
+ formatter.format(account.getBalance()));
System.out.print("How much would you like to withdraw? ");
cashNeeded = keyboard.nextDouble();
account.withdraw(cashNeeded);
account.getInterest();
System.out.println("This month you have earned "
+ formatter.format(account.getInterest())
+ " in interest.");
System.out.println("Now your balance is "
+ formatter.format(account.getBalance()));
}
}
輸出,我得到:
什麼是你的帳戶的期初餘額?
輸出我應該得到:
什麼是你的帳戶的期初餘額? 500
你的月利率是多少? 0.00125
您這個月支付了多少錢? 1000
我們會將您的工資存入您的帳戶。
您目前的餘額是1500.00
您要退出多少? 900
本月你已賺取0.75利息。
現在,您的餘額是600.75
你給它它要求輸入? – resueman