查看“Java实例:手机计费程序”的源代码
←
Java实例:手机计费程序
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==手机计费程序== 某电信公司设计了一个手机话费套餐,套餐价格为58元/月,套餐国内免费通话时长为250min,超出部分按0.25元/min分收费;提供免费流量为50MB,超出部分按0.3元/MB收费, 输入:用户的实际通话时长 和实际数据流量; 输出:该用户本月的实际话费。 ==问题解决== ===初始代码=== <nowiki> package task5; import java.util.Scanner; public class MethodTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入实际通话时长(分钟):"); float call_time=sc.nextInt(); System.out.println("请输入实际数据流量(M):"); float data_flow=sc.nextInt(); float total =58; if(call_time >250) { total += 0.25*(call_time-250); } if(data_flow >50) { total += 0.3*(data_flow-50); } System.out.println("本月实际话费为"+total); sc.close(); } } </nowiki> ===带返回值的方法=== <nowiki> package task5; import java.util.Scanner; public class MethodTest { public static float getPay(float c,float d) { float total =58; if(c >250) { total += 0.25*(c-250); } if(d >50) { total += 0.3*(d-50); } //System.out.println("本月实际话费为"+total); return total; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入实际通话时长(分钟):"); float call_time=sc.nextInt(); System.out.println("请输入实际数据流量(M):"); float data_flow=sc.nextInt(); float t=getPay(call_time,data_flow); System.out.println("本月实际话费为"+t); sc.close(); } } </nowiki> ===不带返回值的方法=== <nowiki> package task5; import java.util.Scanner; public class MethodTest { public static void getPay(float c,float d) { float total =58; if(c >250) { total += 0.25*(c-250); } if(d >50) { total += 0.3*(d-50); } System.out.println("本月实际话费为"+total); //return total; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入实际通话时长(分钟):"); float call_time=sc.nextInt(); System.out.println("请输入实际数据流量(M):"); float data_flow=sc.nextInt(); getPay(call_time,data_flow); sc.close(); } } </nowiki>
返回至
Java实例:手机计费程序
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息