这是我的代码。我不确定如何使用返回值退出程序。有任何想法吗?这是我完成任务的最后一步。重要区域标有我听到了返回的消息,但是当我将main中的void更改为int时,程序会说main必须为void。

import java.util.Scanner;

public class CommissionCalculator {

public static void main(String args[]) {

// Initialize a Scanner to read input from the command line

Scanner ItemSelect = new Scanner(System.in);

double comp = 200.00;

double item1 = 239.99;

double item2 = 129.75;

double item3 = 99.95;

double item4 = 350.89;

double comm = 0.09;

int choice;

/* Note that we'll be doing this at least once and most likely multiple times...

* Prompt the user with a menu of the four items and their values (this information is included in the problem statement)

*/

System.out.println("Item\tValue");

System.out.println("1\t$239.99");

System.out.println("2\t$129.75");

System.out.println("3\t$99.95");

System.out.println("4\t$350.89");

/* Display the user's current compensation */

System.out.printf("Current compensation: $%.2f", comp);

/*

* Prompt and take input from the user (you may assume that they will only enter int values)

* They'll enter an item number (1 - 4) to record its sale or 0 to exit

*

* NOTE: THE U0SER DOES NOT ENTER PRICES DIRECTLY... THEY ENTER ITEM NUMBERS TO INDICATE WHAT WAS SOLD

* NOTE: THE USER MAY ENTER THE SAME ITEM NUMBRER MULTIPLE TIMES

*

* If the user provides invalid input (a value other than 0 - 4) display "ERROR: Invalid input!" and prompt them again

*/

do

{

System.out.print("\nPlease select an item from the " +

"list above (or enter 0 to exit): ");

choice = ItemSelect.nextInt();

{

if (choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 0)

{

do

{

System.out.print("ERROR: Invalid Input!\n");

System.out.println("Item\tValue");

System.out.println("1\t$239.99");

System.out.println("2\t$129.75");

System.out.println("3\t$99.95");

System.out.println("4\t$350.89");

System.out.printf("Current compensation: $%.2f", comp);

System.out.print("\nPlease select an item from the " +

"list above (or enter 0 to exit): ");

choice = ItemSelect.nextInt();

if (choice == 1)

{

comp += (comm * item1);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 2)

{

comp += (comm * item2);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 3)

{

comp += (comm * item3);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 4)

{

comp += (comm * item4);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0); ///

}

}while (choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 0);

}

else

{

if (choice == 1)

{

comp += (comm * item1);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 2)

{

comp += (comm * item2);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 3)

{

comp += (comm * item3);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 4)

{

comp += (comm * item4);

System.out.printf("Current compensation: $%.2f", comp);

}

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0);

}

}

}

}while (choice != 0);

/* After the user enters 0, display the salesperson's earnings in the format "Total earnings: $NNN.NN" and exit

* For example, if the salesperson sold two item 3s this week the final output would be "Total earnings: $217.99"

*/

if (choice == 0)

{

System.out.printf("Total Earnings: $%.2f", comp);

System.exit(0); ///

}

ItemSelect.close();

System.exit(0); ///

}

}

exit java_没有System.exit,如何退出Java程序?(通过用户输入?)相关推荐

  1. 通过java程序判断用户输入的是字符串还是整数

    在Java程序中可以使用instanceof关键字判断用户输入的是字符串还是整数.可以将用户输入的值存储在一个Object类型的变量中,然后使用instanceof关键字检查该变量是否是String类 ...

  2. 用java输入学生姓名查询成绩_编写一个Java程序,提示用户输入学生数量,学生姓名和他们的成绩,并按照成绩的降序打印学生姓名...

    importjava.util.Scanner;publicclassmyclass{publicstaticvoidmain(String[]args){Scannerinput=newScanne ...

  3. Java黑皮书课后题第5章:*5.30(金融应用:复利值)假设你每月在储蓄账户上多存100美元,年利率为5%,那么每月利率是0.05 / 12 = 0.00417。编写程序提示用户输入数据显示定月钱数

    5.30(金融应用:复利值)假设你每月在储蓄账户上多存100美元,年利率为5%,那么每月利率是0.05 / 12 = 0.00417.编写程序提示用户输入数据显示定月钱数 题目 题目概述 破题 代码 ...

  4. Java黑皮书课后题第3章:*3.33(金融:比较成本)假设你要通过两种不同的包裹运输大米。你可能会编写一个程序来比较成本,该程序提示用户输入每个包裹的重量和价格,然后显示具有更优惠的包裹

    *3.33(金融:比较成本)假设你要通过两种不同的包裹运输大米.你可能会编写一个程序来比较成本,该程序提示用户输入每个包裹的重量和价格,然后显示具有更优惠的包裹 题目 题目概述 运行示例 破题 代码 ...

  5. Java黑皮书课后题第3章:**3.15(游戏:彩票)修改程序清单3-8,产生三位整数的彩票。程序提示用户输入一个三位整数,然后依照规则判定用户是否赢得奖金

    **3.15(游戏:彩票)修改程序清单3-8,产生三位整数的彩票.程序提示用户输入一个三位整数,然后依照规则判定用户是否赢得奖金 题目 题目概述 破题 代码 题目 题目概述 **3.15(游戏:彩票) ...

  6. Java黑皮书课后题第8章:***8.35(最大块)给定一个元素为0或者1的方阵,编写程序,找到一个元素都为1的最大的子方阵。程序提示用户输入矩阵的行数。然后显示最大的子方阵的第一个元素、行数

    ***8.35(最大块)给定一个元素为0或者1的方阵,编写程序,找到一个元素都为1的最大的子方阵.程序提示用户输入矩阵的行数.然后显示最大的子方阵的第一个元素.行数 题目 题目描述与运行示例 破题 代 ...

  7. Java黑皮书课后题第7章:*7.1(指定等级)编写一个程序读入学生成绩,得到最高分best,然后根据下面的规则给出等级值。程序提示用户输入学生总数,然后提示用户输入所有的分数,最后显示等级给出结论

    7.1(指定等级)编写一个程序读入学生成绩,得到最高分best,然后根据下面的规则给出等级值 题目 题目描述与运行示例 破题 代码 题目 题目描述与运行示例 *7.1(指定等级)编写一个程序读入学生成 ...

  8. Java黑皮书课后题第3章:*3.1(代数:解一元二次方程)可以使用下面的公式求一元二次方程ax2+bx+c=0,编写程序提示用户输入a b c的值,并显示基于判断式的结果

    *3.1(代数:解一元二次方程)可以使用下面的公式求一元二次方程ax2+bx+c=0,编写程序提示用户输入a b c的值,并显示基于判断式的结果 题目 题目描述 运行示例 破题 代码 题目 题目描述 ...

  9. Java语言中 (游戏:彩票)修改程序清单3-8,产生三位整数的彩票。程序提示用户输入一个三位整数,依照以下规则判定用户是否赢得奖金:

    游戏:(彩票)修改程序清单3-8,产生三位整数的彩票.程序提示用户输入一个三位整数,然后依照以下规则判定用户是否赢得奖金: (1)如果用户输入的所有数包括顺序完全匹配彩票数字,奖金是10 000美元 ...

最新文章

  1. 《Photoshop Lab修色圣典(修订版)》—第1课1.6节小河川流而过
  2. 10-3 5-3 查询生产最高速度的计算机(PC或便携式电脑)厂商 (20 分)
  3. C++:22 再议const的作用(上)
  4. python数字字符串乘以2_Python基础(2)_数字和字符串类型
  5. 【转】前端开发必备网站
  6. python学习笔记(对象)
  7. iOS 内存管理arc
  8. 【Unity3D】GUI控件
  9. vue网页调用高德获取经纬度
  10. java 正序a~z_java 策略模式,list集合,实现id 姓名年龄正序倒序排序(如果年龄或者姓名重复,按id正序排序)...
  11. 【OSPF的特殊区域和特性】ospf的lsdb优化、特殊区域、路由汇总、静默接口、ospf报文认证、LSA路由汇总、高级特性(PRC、智能计时器、FRR、ospf database overflow)
  12. 第7章 集成方法、随机森林
  13. 理解事务四大特性(Transaction)——原子性、一致性、隔离性和持久性(ACID)
  14. 软件工程知识点总结——第三、四部分
  15. java linux mdb,在Linux下实现对Microsoft Access Database(.mdb)查询访问
  16. html5 canvas实现在线生成图片后保存到服务器(数据库)
  17. com.mchange.v2.c3p0.ComboPooledDataSource 报红
  18. Jmeter 性能测试的基础了解
  19. 微软放弃“封禁”商业开源!
  20. ROS笔记(33) 关节空间规划

热门文章

  1. TypeScript Type Compatibility 类型兼容性
  2. 一步步把 SAP UI5 应用部署到 SAP BTP Kyma 运行环境中去
  3. 关于jasmine里debugElement.query和fixture.detectChanges的依赖关系
  4. SAP Spartacus 读取payment detail数据的API
  5. ABAP内表在ABAP 740后支持的filter操作
  6. 如何创建SAP C4C Product list并用OData服务消费
  7. how is service url defined in configuration.js consumed
  8. react native命令行全局安装
  9. check generated report by SE16
  10. IBASE business knowledge from Gerhard