åµåµï¼çè±æçç´¯ï¼ä¸é¢æ¯å
·ä½ç代ç ï¼æäºé¿ï¼ä½æ¯åè½é½å
¨ï¼åèä¸ä¸ï¼
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
/*
* Design an algorithm that will continuously(è¿ç»ä¸æç) prompt an operator for customer number,
* customer name and total amount owing on the customer's credit card
* and print the customer number,name and minimum amount due(æä½çå°æéé¢) for each customer;
The minimum amount due is calculated based on(计ç®ä¾æ®) the total amount owing, as follows:
If the total amount owing is less than or equal to (<=) $5.00,
then the minimum amount due = total amount owing.
If the total amount owing is greater than (>) $5.00.
then the minimum amount due = one quarter (1/4 or 25%) of the total amount owing,
provided this resulting (minimum amount due) is not less than $5.00;
If the resulting amount (1/4 of total amount owing) is less than (<) $5.00,
then the minimum amount due is $5.00.
Your program should end when the operator enters a customer number = 0.
At the end of the program print the total number of customers processed
and the sum total of the amount owing by each customer.
*/
/*
* 设计ä¸ç§ç®æ³,å®å°ä¸æå°ä¸ºå®¢æ·åæ¶æä½åå·ç ,ç±äºå®¢æ·å称åæ»éå¨å®¢æ·çä¿¡ç¨å¡
* åæå°å®¢æ·ç¼å·ãå§ååæä½éé¢ç款项为æ¯ä¸ä½å®¢æ·; ããç±äºè®¡ç®æä½éé¢æ¯ç±äºåºäºæ»é,
* å¦ä¸: ããå¦ææ»æ¬ éé¢å°äºæçäº(< = 5.00ç¾å
,ç¶åæä½éé¢ç款项æ»é¢ç±äº=ã
* å¦ææ»æ¬ éé¢å¤§äº5.00ç¾å
(>)ã
* ç¶åæä½éé¢=ä¸ä¸ªå£åº¦ç±äº(æ25%)çæ»æ¬ éé¢,è¿å¯¼è´æä¾(æä½éé¢ç款项)æ¯ä¸å°äº5.00ç¾å
,
* å¦æç»æéé¢æ»æ°ç±äº)ä½äº5.00ç¾å
(<)çæä½éé¢ç款项,ç¶åæ¯$ 5.00ããã
* ä½ çç¨åºåºè¯¥ç»ææ¶æä½è
è¿å
¥äºä¸ä¸ªå®¢æ·ç¼å·= 0ãæåçç¨åºæå°çæ»æ°ã客æ·å¤ç
*/
class Customer1{
private int number ;
private String name ;
private double amount ;
private double min_amount_due ;
public Customer1(){}
public Customer1(int no,String n,double a){
number = no ;
name = n ;
amount = a ;
}
//è¿ä¸ªé¢çå
³é®å¨è¿é
public double getMin_amount_due() {
if(amount<=5){
min_amount_due = amount ;
}else{
if(0.25*amount <= 5){
min_amount_due = 5 ;
}else{
min_amount_due = 0.25*amount ;
}
}
return min_amount_due;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String toString(){
return "|--ç¼å·ï¼" + number + "\n"
+ "|--å§åï¼" + name + "\n"
+ "|--æä½å°æéé¢ï¼ " + getMin_amount_due() ;
}
}
public class TestCustomer {
private List<Customer1> list = new ArrayList<Customer1>() ;
private int count = 0 ;
private double totle = 0 ;
public void inputInfo(){
int number ;
String name ;
double amount ;
Scanner sc = new Scanner(System.in) ;
System.out.println("===============å¼å§å½å
¥ä¿¡æ¯=================") ;
boolean flag = true ;
while(flag){
System.out.print("请è¾å
¥ç¨æ·çç¼å·ï¼") ;
number = sc.nextInt() ;
System.out.print("请è¾å
¥ç¨æ·çå§åï¼") ;
name = sc.next() ;
System.out.print("请è¾å
¥ç¨æ·çéé¢ï¼") ;
amount = sc.nextDouble() ;
Customer1 c = new Customer1(number,name,amount) ;
list.add(c) ;
if(number==0){
flag = false ;
}
System.out.println();
}
}
public void printInfo(List<Customer1> list){
System.out.println("===============å¼å§è¾åºä¿¡æ¯=================") ;
Iterator<Customer1> it = list.iterator() ;
while(it.hasNext()){
Customer1 c = it.next() ;
System.out.println(c);
System.out.println();
totle += c.getAmount() ;
count ++ ;
}
}
public static void main(String[] args) {
TestCustomer tc = new TestCustomer() ;
tc.inputInfo() ;
tc.printInfo(tc.list) ;
System.out.println("==============ç»æåçç»è®¡ä¿¡æ¯================") ;
System.out.println("æ»å
±æ" + tc.count + "åç¨æ·ï¼æ»éé¢ä¸ºï¼$" + tc.totle + ".") ;
}
}
温馨提示:答案为网友推荐,仅供参考