我創建了一個主要的Java程序,像一個銀行給用戶的平衡,取款和轉賬的工作。我不能得到Java文件給我的錯誤
import java.util.Scanner;
public class Lab12 {
public static void main(String[] args)
{
//Creating Two BankAccounts
BankAccount B1 = new BankAccount(1000, "ASU_ACCOUNT_110");
BankAccount B2 = new BankAccount(500, "ASU_ACCOUNT_100");
double amount;
Scanner scan = new Scanner(System.in);
//Account Deposit
System.out.println("Please Enter amount to deposit into ASU_ACCOUNT_110 Account");
amount = scan.nextDouble();
if(!B1.deposit(amount))
System.out.println("Error depositing amount in account. Please enter positive value.");
else
System.out.println("Successfully deposited $"+amount+". The current balance is "+B1.getBalance());
//Account Withdrawal
System.out.println("Please Enter the amount you would like to withdraw from ASU_ACCOUNT_110");
amount = scan.nextDouble();
if(!B1.withdraw(amount))
System.out.println("Error withdrawing amount. You are either overdrawing or you have entered a negative value");
else
System.out.println("Successfully withdrew $"+amount+". The current balance is "+B1.getBalance());
//Account Transfer
System.out.println("Please Enter the amount you would like to transfer from ASU_ACCOUNT_110 to ASU_ACCOUNT_100");
amount = scan.nextDouble();
if(!B1.transfer(amount, B2))
{
System.out.println("Error transfering amount. You are either overdrawing or you have entered a negative value");
}
else
{
System.out.println("Successfully transferred $"+amount+".\nThe current balance in ASU_ACCOUNT_110 is "+B1.getBalance());
System.out.println("The current balance in ASU_ACCOUNT_100 is "+B2.getBalance());
}
//Account Display
System.out.println("\nThe details of the two accounts are:");
System.out.println("------------------------------------------");
display(B1);
System.out.println("------------------------------------------");
display(B2);
}
public static void display(BankAccount B)
{
System.out.println("The Account Number is "+B.getAccountNumber());
System.out.println("The balance is "+B.getBalance());
}
}
我創造出了方法和獲取並調用餘額
第二類public class BankAccount {
private String AccountNumber;
private double balance;
public BankAccount(double balance, String accountNumber)
{
this.balance = balance;
this.AccountNumber = accountNumber;
}
public boolean deposit(double amount)
{
return true;
}
public double getBalance()
{
return balance;
}
public boolean withdraw(double amount)
{
return true;
}
public boolean transfer(double amount, BankAccount b2)
{
return true;
}
public String getAccountNumber()
{
return AccountNumber;
}
}
的問題是,當我進入一個負金額存款,取款,轉賬,我沒有得到我把這個錯誤放在主類
有什麼想法?
你似乎是堆棧溢出的新手。因此,答對的人得到信用,如果他們的問題有幫助,請點擊向上箭頭。如果與問題無關,請單擊向下箭頭。如果他們的答案解決了您的問題,請點擊勾號。謝謝! – Cin316 2013-04-06 02:37:05
以下有關您的BankAccount中的方法需要完成的一些很好的答案。但是,當您開始編寫真正的銀行軟件爲生活時,請不要使用浮點數來表示錢! :) – Todd 2013-04-06 02:37:07