我有大部分代码用于阻止信用卡持有人的数量,对于某种卡类型,余额和平均值,由于某种原因,某些内容无效。我在Java,bluejay工作,如果这是一个区别。代码如下,
public String getCardSummary(String card){
//return a String that summarizes the total number of cards and average debt for the requested card type.
//Valide enters are: Discover, Visa, and MasterCard.
//Return an appropriate error message if the card is not valid.
//If there are no customers with the specific card, return a message indicationg that "Customers was not found"
//User the NumberFormat class to help fromat the dollars and cnets outputs.
//Sample result should look like:
//Discover: 1981 cards with average balce of $3,735.20
if(card.equalsIgnoreCase("Disvoer") || card.equalsIgnoreCase("Visa") || card.equalsIgnoreCase("MasterCard")){
double runningSum = 0.0;
int counter = 0;
for(int i = 0; i < customers.size() - 1; i++){
if(customers(i).getCard.equals(card)){
runningSum += custumer(i).getBalance();
counter ++;
}
else{
System.out.println("Customers were not found.");
}
}
double avg = runningSum / counter;
System.out.println("" + Card + ": " + counter + " with average balance of " + fmt.format(avg));
}
else{
System.out.println("Invalid Card type");
}