- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在写一个程序,我需要程序返回一个特定的语句。我试过做一个循环,但它非常复杂。有没有更简单的方法?
(如果用户选择是,则重新运行程序。如果否,则结束程序。)
public class CA_1316855_P3 {
public static void main(String[] args) {
//Variables
char Destination, JobType, Currency;
double ExchangeRate = 0, Maximum = 0, Ammount = 0, NewExchangeRate, NewCharge;
int Charge = 0;
String ID, JobTitle = null, Name, Nationality, Mobile, CurrencyTitle = null, DestinationTitle = null;
int BLANK = 0;
int Count_u = 0;
int Count_y = 0;
int Count_p = 0;
int Count_i = 0;
//Destination
while (BLANK == 0) {
System.out.println("\t\t\t ---------------------------------------------");
System.out.println("\t\t\t\t\t Welcome to Transferring System");
System.out.println("\t\t\t ---------------------------------------------");
System.out.println(" Press u for Transferring to USA \n Press y for transferring to Yemen \n Press p for Transferring to Pakistan");
System.out.println(" Press i for Transferring to India \n Press n for new destination country");
System.out.print("Enter the Choice: ");
Scanner input1 = new Scanner(System.in);
Destination = input1.next().charAt(0);
while (Destination != '*')
if (Destination == 'u' ||
Destination == 'U' ||
Destination == 'y' ||
Destination == 'Y' ||
Destination == 'p' ||
Destination == 'P' ||
Destination == 'i' ||
Destination == 'I' ||
Destination == 'n' ||
Destination == 'N') {
if (Destination == 'u' || Destination == 'U') {
ExchangeRate = 0.267;
Count_u++;
DestinationTitle = "United States";
} else if (Destination == 'y' || Destination == 'Y') {
DestinationTitle = "Yemen";
Count_y++;
ExchangeRate = 57.300;
} else if (Destination == 'p' || Destination == 'P') {
DestinationTitle = "Pakistan";
Count_p++;
ExchangeRate = 28.367;
} else if (Destination == 'i' || Destination == 'I') {
DestinationTitle = "India";
Count_i++;
ExchangeRate = 17.417;
} else if (Destination == 'n' || Destination == 'N') {
System.out.print("Enter the name of destination country: ");
Scanner input3 = new Scanner(System.in);
String NewDestinationName = input3.next();
System.out.print("Enter the Exchange Rate between SAR and " + NewDestinationName + " Currency: ");
Scanner input4 = new Scanner(System.in);
NewExchangeRate = input4.nextDouble();
}
break;
} else {
System.out.print("***Wrong Selection !!*** \nEnter choice again:");
Destination = input1.next().charAt(0);
}
//Job Type
System.out.println("\t\t------------\n\t\t Job Type \n\t\t------------ ");
System.out.println(" Press 0 for ordinary employee \n Press 1 for academician employee \n Press 2 for medical employee");
System.out.print("Enter the Choice: ");
Scanner input2 = new Scanner(System.in);
JobType = input2.next().charAt(0);
while (JobType != '*') {
if (JobType == '0' || JobType == '1' || JobType == '2') {
if (JobType == '0') {
JobTitle = "Ordinary";
Maximum = 15000;
} else if (JobType == '1') {
JobTitle = "Academician";
Maximum = 50000;
} else if (JobType == '2') {
JobTitle = "Medical";
Maximum = 80000;
}
break;
} else {
System.out.println("***Wrong Selection !!*** \nEnter choice again:");
JobType = input2.next().charAt(0);
}
}
//Currency
System.out.println("\t\t------------\n\tType of Currency to be received \n\t\t------------ ");
System.out.println(" Press S for Saudi Riyal \n Press L for local Currency");
System.out.print("Enter The Choice: ");
Scanner input5 = new Scanner(System.in);
Currency = input5.next().charAt(0);
while (Currency != '*') {
if (Currency == 's' || Currency == 'l' || Currency == 'S' || Currency == 'L') {
break;
} else {
System.out.println("***Wrong Selection !!*** \nEnter choice again:");
Currency = input5.next().charAt(0);
}
}
System.out.print("Enter the amount to be transferred: ");
Scanner input6 = new Scanner(System.in);
Ammount = input6.nextDouble();
if (Ammount > Maximum) {
System.exit(0);
} else if (Ammount <= 10000 && (Destination == 'u' || Destination == 'U') && Currency == 's') {
Charge = 40;
ExchangeRate = 1;
CurrencyTitle = "SAR";
} else if (Ammount < 10000 && (Destination == 'u' || Destination == 'U') && Currency == 'l') {
Charge = 25;
CurrencyTitle = "USD";
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'u' || Destination == 'U') && Currency == 's') {
Charge = 100;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'u' || Destination == 'U') && Currency == 'l') {
Charge = 70;
CurrencyTitle = "USD";
} else if (Ammount < 10000 && (Destination == 'y' || Destination == 'Y') && Currency == 's') {
Charge = 20;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount < 10000 && (Destination == 'y' || Destination == 'Y') && Currency == 'l') {
Charge = 10;
CurrencyTitle = "YER";
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'y' || Destination == 'Y') && Currency == 's') {
Charge = 50;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'y' || Destination == 'Y') && Currency == 'l') {
Charge = 30;
CurrencyTitle = "YER";
} else if (Ammount < 10000 && (Destination == 'p' || Destination == 'P') && Currency == 's') {
Charge = 30;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount < 10000 && (Destination == 'p' || Destination == 'P') && Currency == 'l') {
Charge = 20;
CurrencyTitle = "PKR";
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'p' || Destination == 'P') && Currency == 's') {
Charge = 80;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'p' || Destination == 'P') && Currency == 'l') {
Charge = 55;
CurrencyTitle = "PKR";
} else if (Ammount < 10000 && (Destination == 'i' || Destination == 'I') && Currency == 's') {
Charge = 25;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount < 10000 && (Destination == 'i' || Destination == 'I') && Currency == 'l') {
Charge = 15;
CurrencyTitle = "INR";
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'i' || Destination == 'I') && Currency == 's') {
Charge = 70;
CurrencyTitle = "SAR";
ExchangeRate = 1;
} else if (Ammount > 10000 && Ammount < 80000 && (Destination == 'i' || Destination == 'I') && Currency == 'l') {
Charge = 50;
CurrencyTitle = "INR";
} else if (Destination == 'n' || Destination == 'N') {
System.out.print("Enter the charges: ");
Scanner input9 = new Scanner(System.in);
NewCharge = input9.nextDouble();
System.out.print("Enter the currency: ");
Scanner input12 = new Scanner(System.in);
CurrencyTitle = input12.next();
}
System.out.print("Enter the ID Number: ");
Scanner input7 = new Scanner(System.in);
ID = input7.next();
System.out.print("Enter the Name: ");
Scanner input8 = new Scanner(System.in);
Name = input8.next();
System.out.print("Enter the Nationality: ");
Scanner input10 = new Scanner(System.in);
Nationality = input10.next();
System.out.print("Enter the Mobile Number: ");
Scanner input11 = new Scanner(System.in);
Mobile = input11.next();
//Printing the Bill
System.out.println("\n\n\n\n\t\t\t\t------------------------------------------");
System.out.println("\t\t\t\t\t The current Transaction");
System.out.println("\t\t\t\t------------------------------------------");
System.out.println("Sender: " + Name + "\t\t\t Destination: " + DestinationTitle);
System.out.println("Job Type: " + JobTitle + "\t\t\t Nationality: " + Nationality + "\t\t Mobile: " + Mobile);
System.out.println("\t\t\t The Original Ammount: " + Ammount);
System.out.println("\t\t\t The Recieved Ammount: " + Ammount * ExchangeRate);
System.out.println("\t\t\t The Total Amount Cost: " + ((int) (Ammount) + (Charge)));
int reply = JOptionPane.showConfirmDialog(null, "Would you like to do another transaction ?", "Question.", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
continue;
} else if (reply == JOptionPane.NO_OPTION && Count_u >= 1 && Count_y >= 1 && Count_p >= 1 && Count_i >= 1) {
System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "You need to perform at least one transaction for each country.");
continue;
}
}
}
}
最佳答案
试试extract method pattern .这使得这个困惑可读。
解压后,只复制粘贴重要的部分到stackoverflow求助,实现回跳会容易很多。
public class CA_1316855_P3 {
public static void main(String[] args) {
int reply;
do {
businessLogic();
reply = askUser();
} while (userWantRepeat(reply));
}
}
关于java - 要求 Java 返回到特定语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20016678/
我有一个类和构造函数,如下所示: def init(log, edge): if edge: return Helper(log, edge) return Booka
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
有人知道在 mongo 上安装标准 ubuntu 需要多少磁盘空间和内存吗?试图找出我的 VPS 需求... 最佳答案 没有最低要求,但我不建议在与您的网络服务器相同的机器上运行 Mongo。 Mon
我的 Django 项目有一个虚拟环境,但是当我 pip 击 pip freeze 时,我得到了一个必须是全局站 pip 包列表的东西,包括太多包,比如ubuntu包和这么多不相关的东西。无论 vir
我曾尝试在 Heroku 上部署我的应用程序,但 smth 出错了。 错误:找不到满足要求的版本 get==2019.4.13(来自 -r/tmp/build_53ad6d03_/requiremen
我无法将 semantic-ui-calendar npm 模块加载到我的应用程序中。 我已经使用脚本标签成功地将它加载到我的 HTML 中, 但每次我尝试将它加载到我的应用程序中时,我都会出错。 在
如何修复 php.ini 中“require”函数内的地址?它进行故障排除并显示错误: 警告:require (..) 无法打开流:没有这样的文件或目录。 文件“db_connection.php”工
我有一个在 Node.js 应用程序中使用的外部库 ( Objection.js )。我创建了一个基本模型类,它为我的实体模型扩展了 Objection 的 Model 类: const { Mode
有谁知道在哪里可以找到RHEL5的GLIBC2.7,如果没有这个,Android模拟器将无法启动。它会给出一条消息,要求GLIBC 2.7或更高版本。 我尝试在网上搜索,但没有找到 最佳答案 我也遇到
Android 设备是否有任何要求/指南?例如按钮数量或所需的最少按钮数量。 还有没有菜单和后退按钮的安卓设备吗? (我知道就可用性而言,没有菜单/后退按钮会杀死大多数应用程序,我只是想了解更多有关该
我想要求/包含一个文件并将其内容检索到一个变量中。 test.php index.php ".$test; ?> 类似于 file_get_contents() 但它仍应执行 PHP 代码。这可能吗
我想要求/包含一个文件并将其内容检索到一个变量中。 test.php index.php ".$test; ?> 类似于 file_get_contents() 但它仍应执行 PHP 代码。这可能吗
我正在尝试在我的 Linux Mint 发行版上安装一个 python 模块“pyAudioProcessing”(https://github.com/jsingh811/pyAudioProces
我已经创建了我的第一个 composer 包,它具有 MySQL 和 MongoDB 的功能,但是,它不需要两者。我意识到有人可能只想将这个包与两个数据库之一一起使用,目前我有: "require":
我想调试以下函数,但假设在调试器中查看 moreajaj 的参数等于什么(假设不像在这个人为的示例中那么明显)是有用的。我可以在调试器框架中打印它,但是在每个参数的每个框架中都这样做很烦人。在宣布每一
我有一些生成的 GNUmakefiles,我需要从中提取变量的值。 有没有一种简单的方法可以在不修改 makefile 的情况下查看变量的值? 仅供引用,变量包含 emacs c-macro-expa
我正在使用 aspell 在 Linux 上拼写检查 LaTeX 文档。我的文档经常包含各种编程语言的代码示例,我希望 aspell 在拼写检查时简单地跳过这些行。 我可以在文档中写些什么来关闭一段文
我有一个包含多个列的数据集... 一列是具有重复值的主石斑鱼列,另一列是具有 bool 值 (1,0) 的 NUMBER,如下所示: grp bool --- ---- A 1 A 1 A
出于测试目的,我正在尝试删除一些 amd 模块并从服务器重新加载更新版本 - 目的是不刷新浏览器。 我目前正在执行以下操作,但浏览器仍然没有从网络重新加载项目。 var scripts = docum
当我键入irb> require 'rubygems'时,它返回false。我的Rails应用程序中有很多 gem ,这些 gem 显然可以正常工作-耙子,activerecord等。这里可能出什么问
我是一名优秀的程序员,十分优秀!