- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在致力于制作一个模拟银行交易的程序。我必须询问用户是否要存款、取款或转账。现在我正在研究帐户的存款和取款选项。
当用户选择一项交易(例如存款)并输入一个数字时,我让程序询问“您想继续此交易吗?显然,如果是,程序将继续交易,如果否,它不会存入用户输入的号码。
我的问题是,我不知道我需要在 no 选项中添加什么。我不知道拒绝交易是否意味着我必须退出循环或者什么,但目前如果我点击“否”,交易仍然会进行。下面是当我输入交易但不想继续时发生的情况的视觉效果:
下面是我的整个代码。我不知道该放什么的代码部分有**这可能对我的组织没有帮助,对此我深感抱歉!
import java.util.Scanner;
public class BankTransactions {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num;
double balance = 0;
double checkingBalance= 0, savingsBalance =0;
do {
double amount;
System.out.println("------------------------");
System.out.println("Select a Transaction by typing number");
System.out.println("1. Deposit");
System.out.println("2. Withdrawal");
System.out.println("3. Balance");
System.out.println("4. Exit");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) { //if DEPOSIT is selected
//ask to deposit from checking or savings
System.out.println("------------------------");
System.out.println("Would you like to deposit in checking or savings?");
System.out.println("1. Checking");
System.out.println("2. Savings");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) { //if CHECKING is selected
//enter amount to be deposited
System.out.println("------------------------");
System.out.println("Enter amount to deposit in checking account: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
// Add the amount to the checking balance
checkingBalance += amount;
System.out.println("------------------------");
System.out.println("Your checking account's balance is " + checkingBalance);
System.out.println("------------------------");
} else if (num == 2) { //if SAVINGS is selected
//enter amount to be deposited
System.out.println("------------------------");
System.out.println("Enter amount to deposit in savings account: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) {
// Add the amount entered to the savings balance
savingsBalance += amount;
System.out.println("------------------------");
System.out.println("Your savings account's balance is " + savingsBalance);
System.out.println("------------------------");
**} else if (num == 2) {
//EMPTY NEEDS CODE
}**
}
} else if (num == 2) { //if withdrawal is selected
//ask to withdrawal from checking or savings
System.out.println("------------------------");
System.out.println("Would you like to withdrawal from checking or savings?");
System.out.println("1. Checking");
System.out.println("2. Savings");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) { //if checking is selected
//enter amount to be withdrawn
System.out.println("------------------------");
System.out.println("Enter amount to withdrawal: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) { //if you say yes to continuing
// Remove the amount from the balance
checkingBalance -= amount;
System.out.println("------------------------");
System.out.println("Your checking account's balance is " + checkingBalance);
System.out.println("------------------------");
} else if (num == 2) { //if you say no to continuing
//Do not remove amount from savings balance
//EMPTY NEEDS CODE
}
} else if (num == 2) { //if savings is selected
//enter amount to be withdrawn
System.out.println("------------------------");
System.out.println("Enter amount to withdrawal: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) { //if you say yes to continuing
// Remove the amount from the savings balance
savingsBalance -= amount;
System.out.println("------------------------");
System.out.println("Your savings account's balance is " + savingsBalance);
System.out.println("------------------------");
} else if (num == 2) { //if you say no to continuing
//Do not remove amount from savings balance
//EMPTY NEEDS CODE
}
}
} else if (num == 3) { //if balance is selected
//ask to see balance of checking or savings
System.out.println("------------------------");
System.out.println("Your Checking balance is " + checkingBalance);
System.out.println("Your Savings balance is " + savingsBalance);
System.out.println("------------------------");
num = scan.nextInt();
//needs to return to transaction options
}
} while (num != 4);
System.out.println("------------------------");
System.out.println("Good Bye!");
System.out.println("------------------------");
}
}
我被困住了,我想弄清楚。请不要发布更正后的整个代码。我想自己修复并学习!
最佳答案
交易仍会进行检查,但不会进行储蓄。
原因如下:
if (num == 1) { //if CHECKING is selected
//enter amount to be deposited
System.out.println("------------------------");
System.out.println("Enter amount to deposit in checking account: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
// Add the amount to the checking balance
checkingBalance += amount;
System.out.println("------------------------");
System.out.println("Your checking account's balance is " + checkingBalance);
System.out.println("------------------------");
} else if (num == 2) { //if SAVINGS is selected
//enter amount to be deposited
System.out.println("------------------------");
System.out.println("Enter amount to deposit in savings account: ");
System.out.println("------------------------");
amount = scan.nextDouble();
//ask if they want to continue with transaction
System.out.println("------------------------");
System.out.println("Would you like to continue this transaction?");
System.out.println("1. Yes");
System.out.println("2. No");
System.out.println("------------------------");
num = scan.nextInt();
if (num == 1) {
// Add the amount entered to the savings balance
savingsBalance += amount;
System.out.println("------------------------");
System.out.println("Your savings account's balance is " + savingsBalance);
System.out.println("------------------------");
**} else if (num == 2) {
//EMPTY NEEDS CODE
}**
}
注意“num = scan.nextInt();”之后的区别两种情况下都行吗?在第一种情况下,您指示它继续并添加,无论输入如何,在第二种情况下,您有一个 if/else 语句,仅当用户输入 1 时才会添加它,如果他输入 2 ,您将什么也不做。
至于你关于在除 1 或 2 之外的任何其他选项的情况下该怎么做的问题。我会使用 if 语句来检查 num 是否为 1,而不使用 else 语句,因此如果输入任何其他选项,它会又回到起点。 (但是如果你坚持 2 是“否”,你可以使用 else if(num != 2){System.out.println("Invalid Option. Going to the begin";}
关于java - 银行账户程序: Rejecting Deposit or Withdrawal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19297576/
我正在我的 python 应用程序中实现剪贴板监视器。如果复制的文本满足某些要求,我想向用户显示一个对话框。如果用户单击"is",我想触发一个函数 - 在本例中为 webui.app.add_inte
我想在调用withdraw 后显示一个窗口。 以下是我目前的代码: from Tkinter import * def callback(): global root root.
我一直在致力于制作一个模拟银行交易的程序。我必须询问用户是否要存款、取款或转账。现在我正在研究帐户的存款和取款选项。 当用户选择一项交易(例如存款)并输入一个数字时,我让程序询问“您想继续此交易吗?显
本文整理了Java中io.dddbyexamples.cqrs.application.WithdrawalProcess.withdraw()方法的一些代码示例,展示了WithdrawalProce
我需要插入一个按钮,让我的参与者可以随时退出我的研究。 我找到了一个 css 代码,可以在每个页面上插入“撤回”按钮。然而,这个“退出”按钮位于“下一步”按钮旁边,我不希望我的参与者误按它并退出调查。
我正在尝试处理由 PayPal 银行提款产生的交易。 当系统(通过自动转账)或用户将资金从 PayPal 账户转账到关联的银行账户时,就会发生银行提款。这将创建交易类型:“将资金提取到银行账户” 任何
就 Tkinter 的 iconify() 和 withdraw() 方法的区别而言,我一直在搜索但没有找到答案。 iconify() 似乎将窗口“转换”为任务栏图标并具有“图标”状态 withdra
我目前正在使用 Kraken API 下订单和提取货币。问题是当我想通过 Kraken API 提取欧元时,他们要求我输入我的提款 key 名称。我以为这是我的 API key 或我的 key 描述,
我是一名优秀的程序员,十分优秀!