クラス ShoppingSystem

java.lang.Object
  上位を拡張 ShoppingSystem

public class ShoppingSystem
extends Object

演習2の買い物をするプログラムのスケルトン. メソッドなり属性なり付け足して完成してください. 無論,必要なクラスを付け足さないといけないかもしれません. TODO 自分で改造すべし

作成者:
学籍番号を書いてね

フィールドの概要
private  HashSet<Customer> rcustomers
          登録されている顧客の集合.
private  HashSet<Product> rproducts
          登録されている商品の集合
 
コンストラクタの概要
ShoppingSystem()
           
 
メソッドの概要
 boolean addCustomer(String c)
          cを新規顧客として登録する
 boolean addProduct(String p)
          p を新規の商品として登録する
 boolean buyProduct(Customer c, Product p, int n)
          顧客 c が 商品 p を n 個買う.
 boolean buyProduct(String c, String p, String n)
          顧客 c が 商品 p を n 個買う.
 Customer[] getCustomers()
          現状登録されている全ての顧客の配列を返す
 Product[] getProducts()
          現状登録された全ての商品のリストを返す
 HashSet<Customer> getRcustomers()
           
 HashSet<Product> getRproducts()
           
private  boolean isOverlap(HashSet<Product> set1, HashSet<Product> set2)
          二つの集合の交わりがあるかどうかテスト.
 Product[] recommendProducts(Customer c)
          顧客 c に勧める商品を計算
 String[] recommendProducts(String c)
          顧客 c に勧める商品を計算
 void setRcustomers(HashSet<Customer> rcustomers)
           
 void setRproducts(HashSet<Product> rproducts)
           
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

rcustomers

private HashSet<Customer> rcustomers
登録されている顧客の集合. あとから,HashMapのほうがいいかなー,とか,ちょっと思った.


rproducts

private HashSet<Product> rproducts
登録されている商品の集合

コンストラクタの詳細

ShoppingSystem

public ShoppingSystem()
メソッドの詳細

getRcustomers

public HashSet<Customer> getRcustomers()

setRcustomers

public void setRcustomers(HashSet<Customer> rcustomers)

getRproducts

public HashSet<Product> getRproducts()

setRproducts

public void setRproducts(HashSet<Product> rproducts)

addCustomer

public boolean addCustomer(String c)
cを新規顧客として登録する

パラメータ:
c - 追加する顧客名
戻り値:
登録できれば true 既に同名の顧客がいる等の理由で登録できなければ false

addProduct

public boolean addProduct(String p)
p を新規の商品として登録する

パラメータ:
p - 追加する商品名
戻り値:
登録できれば true 既に同名の商品がある等で登録できなければ false

buyProduct

public boolean buyProduct(String c,
                          String p,
                          String n)
顧客 c が 商品 p を n 個買う.

パラメータ:
c - 買う顧客
p - 買う商品名
n - 個数の文字列表現
戻り値:
該当する顧客,商品が存在しなかったり,個数の指定が1以上の数値でなかったりしたら false そうでなければ買えるとして true

buyProduct

public boolean buyProduct(Customer c,
                          Product p,
                          int n)
顧客 c が 商品 p を n 個買う.

パラメータ:
c -
p -
n -
戻り値:
該当する顧客,商品が存在しなかったり,nが1以上でなかったりしたら false そうでなければ買えるとして true

recommendProducts

public String[] recommendProducts(String c)
顧客 c に勧める商品を計算

パラメータ:
c - 勧めたい顧客
戻り値:
当該顧客がいなければ null. それ以外は勧めたい商品の名前が文字列の配列として返る.お勧めが無い場合は長さゼロの配列が返る.

recommendProducts

public Product[] recommendProducts(Customer c)
顧客 c に勧める商品を計算

パラメータ:
c -
戻り値:
当該顧客がいなければ null. それ以外は勧めたい商品の配列を返す,お勧めが無ければゼロ長の配列を返す.

isOverlap

private boolean isOverlap(HashSet<Product> set1,
                          HashSet<Product> set2)
二つの集合の交わりがあるかどうかテスト. retainAllを使おうと思ったっけど,ちょいと使い勝手が悪いので.

パラメータ:
set1 -
set2 -
戻り値:
交わりがあれば true その他,false;

getProducts

public Product[] getProducts()
現状登録された全ての商品のリストを返す

戻り値:
商品の配列,登録が無ければ長さゼロの配列を返す

getCustomers

public Customer[] getCustomers()
現状登録されている全ての顧客の配列を返す

戻り値:
顧客の配列,登録が無ければ長さゼロの配列を返す.