我在编程测试中得到了以下问题,但我似乎无法理解为什么它无法清除所有测试用例。我错过了哪些可能的测试用例?
信用卡公司按照以下规则向每位交易收取费用:
WAP计算费用。
输入如下:第一行包含说N的交易数。接下来的N行按顺序包含交易详情:交易日期,客户名称,金额。
输出:按给定交易的顺序打印交易费用(每行一个)。
EG。样本输入
10
2014-06-13,ABC RETAIL,10000.00
2014-06-14,ABC RETAIL,40000.00
2014-06-20,ABC RETAIL,1000.50
2014-06-23,XYZ RETAIL,9000.00
2014-06-23,ABC RETAIL,5000.00
2014-06-24,ABC RETAIL,100.00
2014-07-12,XYZ RETAIL,900.00
2014-07-13,XYZ RETAIL,55000.00
2014-07-13,XYZ RETAIL,550.00
2014-07-13,ABC RETAIL,105000.00
示例输出:
100.0
400.0
0.0
135.0
0.0
1.0
0.0
550.0
0.0
1050.0
输出说明:
100.0 (Rule 3 applied)
400.0 (Rule 3 applied)
0.0 (Rule 5 applied for June for ABC RETAIL)
135.0 (Rule 2 applied)
0.0 (Rule 5 applied for July for ABC RETAIL)
1.0 (Rule 4 and 6 applied)
0.0 (Rule 5 applied for August for XYZ RETAIL)
550.0 (Rule 3 Applied)
0.0 (Rule 5 applied for August for xyz RETAIL)
1050.0 (Rule 3 Applied)
我的代码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Merchant
{
ArrayList<Transaction> listTrans;
String name;
Merchant(String n)
{
listTrans=new ArrayList<Transaction> ();
name=n;
}
}
class Transaction
{
int date;
int month;
int year;
double amount;
double charge;
}
public class TestClass{
public static void main(String[] args) {
HashMap<String,Merchant> merchantMap=new HashMap<String,Merchant>();
Merchant merch=null;
String[] trans=new String[3];
String[] date=new String[3];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line=null;
try
{
line=br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
int N=Integer.parseInt(line);
for(int i=0;i<N;i++)
{
System.out.println("i = "+i);
try
{
line=br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
trans=line.split(",");
date=trans[0].split("-");
merch=merchantMap.get(trans[1]);
if(merch==null)
{
merchantMap.put(trans[1],new Merchant(trans[1]));
merch=merchantMap.get(trans[1]);
}
Transaction t=new Transaction();
t.date=Integer.parseInt(date[2]);
t.month=Integer.parseInt(date[1]);
t.year=Integer.parseInt(date[0]);
t.amount=Double.parseDouble(trans[2]);
int countFree=0;
double totalAmount=0;
for(Transaction tr:merch.listTrans)
{
if(tr.year==t.year)
{
if(tr.month==t.month)
{
totalAmount+=tr.amount;
if(tr.amount<=5000)
countFree++;
}
}
}
if(countFree<2 && t.amount<=5000)
{
t.charge=0.00;
System.out.println("FREE RULE APPLIED");
}
else if(totalAmount>=50000)
{
t.charge=Math.ceil(t.amount*(0.5/100));
System.out.println("0.5 Applied.total amt>50000");
}
else
{
if(t.amount<5000)
{
t.charge=Math.ceil(t.amount*(2.0/100));
System.out.println("2.0 Applied.amt<5000");
}
else if(t.amount>=5000 && t.amount<=9999.99)
{
t.charge=Math.ceil(t.amount*(1.5/100));
System.out.println("1.5 Applied.amt=>5000..<=9999.99");
}
else
{
t.charge=Math.ceil(t.amount*(1.0/100));
System.out.println("1.0 Applied.amt>10,000");
}
}
merch.listTrans.add(t);
System.out.println(t.charge);
merch=null;
}
}
}
答案 0 :(得分:0)
关于&#34;的规则大于10000.00&#34;不应使用编码 &#34;&t.amount LT = 9999.99&#34;
如果有的话,应该是t.amount&lt; = 10000.0