没有合适的资源?快使用搜索试试~ 我知道了~
首页软件测试技术实验报告.doc
1.1黑盒测试问题描述 假设商店货品价格(R) 都不大于100元(且为整数),若顾客付款(P)在100元内,现有一个程序能在每位顾客付款后给出找零钱的最佳组合(找给顾客货币张数最少)。 假定此商店的货币面值只包括:50元(M50)、10元(M10)、 5元(M5)、1元(M1) 四种。 1.2白盒测试问题描述 10个铅球中有一个假球(比其他铅球的重量要轻),用天平三次称出假球。 第一次使用天平分别称5个球,判断轻的一边有假球;拿出轻的5个球,取出其中4个第二次称,两边分别放2个球:如果两边同重,则剩下的球为假球;若两边不同重,拿出轻的两个球称第三次,轻的为假球。
资源详情
资源评论
资源推荐

软件测试技术实验报
1. 问题描述
1.1 黑盒测试问题描述
假设商店货品价格(R) 都不大于 100 元(且为整数),若顾客付款(P)在
100 元内,现有一个程序能在每位顾客付款后给出找零钱的最佳组合(找给
顾客货币张数最少)。
假定此商店的货币面值只包括:50 元(M50)、10 元(M10)、 5 元(M5)、1
元(M1) 四种。
1.2 白盒测试问题描述
10 个铅球中有一个假球(比其他铅球的重量要轻),用天平三次称出
假球。
第一次使用天平分别称 5 个球,判断轻的一边有假球;拿出轻的 5 个球,
取出其中 4 个第二次称,两边分别放 2 个球:如果两边同重,则剩下的球为
假球;若两边不同重,拿出轻的两个球称第三次,轻的为假球。
2. 被测核心代码及控制图
2.1 黑盒测试被测核心代码
import java.util.Scanner;
public class Change {
/**
*
主函数
* @param args
*/
public static void main (String[] args) {
// TODO Auto-generated method stub
int pay = 0;//付款金额
int cost = 0;//商品花费
int change = 0;//找钱
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
System.out.println("请输入顾客付款金额:");

//对输入的内容进行检测,是否符合规则
try
{
pay = args[0] == null ? scanner.nextInt() : Integer.parseInt(args[0]);
if (pay > 100 || pay < 0)
{
System.out.println("请输入正确的金额");
return;
}
}catch (Exception e)
{
System.out.println("请输入合法数字");
return;
}
System.out.println("请输入商店货品价格:");
//对输入的内容进行检测,是否符合规则
try
{
cost = args[1] == null ? scanner.nextInt() : Integer.parseInt(args[1]);
if (cost > 100 || cost < 0)
{
System.out.println("请输入正确的金额");
return;
}
else if (cost > pay)
{
System.out.println("您的消费金额超出支付金额");
return;
}
}catch (Exception e)
{
System.out.println("请输入合法数字");
return;
}
change = pay-cost;
//输出此时的付款金额,商品价格,应找金额
System.out.println("付款金额" + pay +" 货品价格" + cost + " 应找总金额:" +
change);

//获得结果,进行输出
String end = giveChange(change);
System.out.println("此次消费应找金额 " + change + " 元,其中应找 " + end);
}
/**
*
以找钱规则找钱
* @param change
* @return String//
返回最终的找钱结果
*/
public static String giveChange(int change)
{
String str="";
int qianshu;//应该找钱的张数
int leftmoney = change;//还剩下多少钱,初始值为 change
if (leftmoney / 50 != 0)
{
qianshu = leftmoney / 50;
str = str + qianshu + "张 50 元 ";
leftmoney = leftmoney - qianshu * 50;
}
if (leftmoney / 10 != 0)
{
qianshu = leftmoney / 10;
str = str + qianshu + "张 10 元 ";
leftmoney = leftmoney - qianshu * 10;
}
if (leftmoney / 5 != 0)
{
qianshu = leftmoney / 5;
str = str + qianshu + "张 5 元 ";
leftmoney = leftmoney - qianshu * 5;
}
if (leftmoney / 1 != 0)
{
qianshu = leftmoney / 1;
str = str + qianshu + "张 1 元 ";
leftmoney = leftmoney - qianshu * 1;
}
//检验是否完全找完
剩余12页未读,继续阅读











一只猫.
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0