KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > bidbuy > BidService


1 package samples.bidbuy;
2
3 /**
4  * Big/PurchaseOrder Service
5  */

6 public class BidService {
7
8     static int nextReceiptNumber = 9000;
9
10     /**
11      * Request a quote for a given quantity of a specified product
12      * @param productName name of product
13      * @param quantity number desired
14      * @return Total amount in US$ for complete purchase
15      */

16     public double RequestForQuote(String JavaDoc productName, int quantity) {
17         if (quantity < 100) {
18            return 1.0 * quantity;
19         } if (quantity < 1000) {
20            return 0.8 * quantity;
21         } else {
22            return 0.7 * quantity;
23         }
24  
25     }
26
27     /**
28      * Purchase a given quantity of a specified product
29      * @param productName name of product
30      * @param quantity number desired
31      * @param price desired price (!!!)
32      * @param customerId who you are
33      * @param shipTo where you want the goods to go
34      * @param date where you want the goods to go
35      * @return Receipt
36      */

37     public String JavaDoc SimpleBuy(String JavaDoc productName, String JavaDoc address, int quantity) {
38         return Integer.toString(nextReceiptNumber++) + "\n" +
39             quantity + " " + productName;
40     }
41
42     /**
43      * Process a purchase order.
44      * @return Receipt
45      */

46     public String JavaDoc Buy(PurchaseOrder PO) {
47         String JavaDoc receipt = Integer.toString(nextReceiptNumber++);
48
49         for (int i=0; i<PO.getItems().length; i++) {
50             LineItem item = PO.getItems()[i];
51             receipt += "\n " + item.getQuantity() + " " + item.getName();
52         }
53
54         return receipt;
55     }
56
57     /**
58      * Let the world know that we are still alive...
59      */

60     public void Ping() {
61     }
62
63 }
64
Popular Tags