- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前在处理我的java银行问题的转账方法时遇到了一些麻烦。无论出于何种原因,当我将钱从一个帐户转移到另一个帐户时,它实际上并没有转移。我认为这可能是因为案例没有小写语句(例如案例“检查”而不是案例“检查”,但这并没有修复错误。但是,它确实阻止了打印默认案例说“您输入了无效的数字”。代码如下:
import java.io.InputStream;
import java.util.Scanner;
public class CustomerDemo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
Customer customer = new Customer(System.in);
int accountChoice; // show which account needs to be chosen.
String cusSel; //for customer selection.
double money;
do
{
System.out.println("main menu to be selected: " );
System.out.println("1.deposit " );
System.out.println("2.withdraw " );
System.out.println("3.transfer " );
System.out.println("4.print balance " );
System.out.println("q.quit " );
cusSel=in.next();
switch(cusSel.charAt(0))
{
case '1':
System.out.println("please select account: " );
System.out.println("1. Checking" );
System.out.println("2. Saving " );
accountChoice=in.nextInt();
if((accountChoice==1)||(accountChoice==2))
{
System.out.println("please imput the deposit amount: " );
money=in.nextDouble();
if(accountChoice==1)
{
customer.deposit(money, "Checking");
}
else if(accountChoice==2)
{
customer.deposit(money, "Saving");
}
}
else
{
System.out.println("invalid choice. your choice does not exsist");
break;
}
break;
case '2':
System.out.println("Please select account: " );
System.out.println("1. Checking" );
System.out.println("2. Saving " );
accountChoice=in.nextInt();
if((accountChoice==1)||(accountChoice==2))
{
System.out.println("please input the withdraw amount: " );
money=in.nextDouble();
if(accountChoice==1)
{
customer.withdraw(money, "Checking");
}
else if(accountChoice==2)
{
customer.withdraw(money, "Saving");
}
}
else
{
System.out.println("invalid choice. your choice does not exsist");
break;
}
break;
case '3':
System.out.println("please select an account to transfer from: " );
System.out.println("1. Checking" );
System.out.println("2. Saving " );
accountChoice=in.nextInt();
if((accountChoice==1)||(accountChoice==2))
{
System.out.println("please input the transfer amount: " );
money=in.nextDouble();
if(accountChoice==1)
{
customer.transfer(money, "saving");
}
else if(accountChoice==2)
{
customer.transfer(money, "checking");
}
}
else
{
System.out.println("invalid choice. your choice does not exsist");
break;
}
break;
case '4':
customer.printBalance();
break;
case 'q':
System.out.println("transaction complete, please have a nice day");
break;
default:
System.out.println("invalid choice.");
}
} while (cusSel.charAt(0)!= 'q' && cusSel.charAt(0)!= 'Q');
}
private void getAccountChoice(int accountChoice) {
// TODO Auto-generated method stub
}
}
class Customer
{
//two objects/ saving and checking
Account Saving = new Account();
Account Checking = new Account();
public Customer(InputStream in)
{
// TODO Auto-generated constructor stub
}
boolean deposit(double amount, String acc)
{
double currentBalanceChecking, currentBalanceSaving;// this currentBalence is subtracted from and account.
boolean retVal = false;
switch (acc)
{
case "Checking": case "checking":
if(amount >=0)
{
currentBalanceChecking = this.Checking.deposit(amount);
retVal = true;
}
break;
case "Saving": case "saving":
if(amount >=0)
{
currentBalanceSaving = this.Saving.deposit(amount);
retVal = true;
}
break;
default:
System.out.println("You entered an invalid number.");
}
return retVal;
}
boolean withdraw(double amount, String acc)
{
double currentBalanceChecking, currentBalanceSaving;// this currentBalence is subtracted from and account.
boolean retVal = false;
switch (acc)
{
case "Checking": case "checking":
if(amount <=Checking.getBalance())
{
currentBalanceChecking = this.Checking.withdraw(amount);
retVal = true;
}
break;
case "Saving": case "saving":
if(amount <=Saving.getBalance())
{
currentBalanceSaving = this.Saving.withdraw(amount);
retVal = true;
}
break;
default:
System.out.println("You entered an invalid number.");
}
return retVal;
}
boolean transfer(double amount, String acc)
{
double currentBalanceChecking, currentBalanceSaving;// this currentBalence is subtracted from and account.
boolean retVal = false;
switch (acc)
{
case "Checking": case "checking":
if(amount <=Checking.getBalance())
{
currentBalanceChecking = this.Checking.withdraw(amount);
currentBalanceSaving = this.Saving.deposit(amount);
retVal = true;
}
break;
case "Saving": case "saving":
if(amount <=Saving.getBalance())
{
currentBalanceSaving = this.Saving.withdraw(amount);
currentBalanceChecking = this.Checking.deposit(amount);
retVal = true;
}
break;
default:
System.out.println("You entered an invalid number.");
}
return retVal;
}
void printBalance()
{
System.out.println("The checking balance is $" + Checking.getBalance());
System.out.println("The saving balance is $" + Saving.getBalance());
}
}
class Account
{
double balance;
//the constructor tells the customer that there are zero dollars in the account.
Account()
{
balance = 0;
}
//deposit money
double deposit( double depAmount )
{
balance= balance + depAmount;//balance+ = depAmount
return balance;
}
double withdraw( double withAmount )
{
balance= balance - withAmount;//balance- = withAmount
return balance;
}
double getBalance()
{
return balance;
}
}
最佳答案
您的帐户类别从 0 美元开始。当要转帐的金额大于帐户余额时,您的转帐方法不会提供输出。
关于java - 转账方法在银行程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26536188/
我正在创建一个在线学习平台,我们在其中使用 Moodle 输入和存储问题。我需要创建一个包装器,使用它我可以从我的应用程序访问 Moodle 的问题库。最好的方法是什么:插件还是 Web 服务?已经有
我有一个银行线程和 4 个 ATM 机 .txt 文件。(atm_0_input_file.txt - atm_4_input_file.txt)。 每个文件都是一个线程,一个bank也是一个线程。当
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
当我使用“exchange_to (: CLP) .to_i”方法时,它在 OrdersController#create 中给我错误 Money::Bank::GoogleCurrencyFetch
您好,我对数据库的“用户”和从数据库访问其详细信息的企业“客户”感到困惑。 我正在构建一个网络,客户可以在其中登录并访问他们的银行余额、对账单、直接借记等(银行应用程序)。我的 SQL 数据库将有一个
我正在使用 Monzo 银行 API 开发一个金融应用程序,身份验证过程最终会从 Monzo api 接收 access_token:https://docs.monzo.com/#acquire-a
我正在设计银行 ATM 消息处理/路由框架,需要一些帮助来完成技术和架构。交易来自多个合作银行的 ATM,比如目前我们为 5 到 6 家银行提供服务,每家银行不超过 10 台 ATMS。 消息通过 t
我是第一次使用 Stripe,对它们提供的不同 API 有点困惑。有一个 Payment Method API,它是推荐用于处理客户付款方式的 API,但目前它只支持信用卡,如果我理解正确的话....
我是一名优秀的程序员,十分优秀!