📄 basketcontroller.java
字号:
/**
* BasketController is used to control user's basket.
* It contains an attribute basket with type of Basket.
*/
import java.util.*;
public class BasketController {
private Basket basket;
/**
* Class constructor.
* When create this object, the basket to manage will be set.
*
* @param basket the basket's object that this class will manage.
*/
public BasketController(Basket basket){
this.basket=basket;
}
/**
* Add a product to user's basket.
* <p>
* Algorithm:
* <p>
* This method takes two arguments: the product to add and it's count.
* Firstly, this method will judage whether the product is in the basket or not.
* If the product already in the basket, this method will add it's purchasecount number with the param count.
* Otherwise, this method will set the product's purchasecount with param count.
* And then add the product object into the collection class(products vector) of the basket(this class control,also the user's basket)
* This method will invoke the basket class's add method.
* <p>
* Internal data structures:
* <p>
* Product p.
* @see Product
* @see Basket
*
* @param p the product's object to added.
* @param count how many the user wants to buy.
*/
public void add(Product p,int count){
//body
}
/**
* Remove a product from user's basket.
* <p>
* Algorithm:
* <p>
* This method takes one arguments: the product to removed.
* This method will set the removed product's purchasecount with 0.
* And then remove it from the collection class(products vector) of the basket(this class control,also the user's basket.)
* This method will invoke the basket class's remove method.
* <p>
* Internal data structures:
* <p>
* Product p.
* @see Product
* @see Basket
*
* @param p the product's object to removed.
*/
public void remove(Product p){
//body
}
/**
* Clear user's basket.
* <p>
* Algorithm:
* <p>
* This method will set the all the product purchasecount with 0 in basket.
* And then clear collection class(products vector) of the basket(this class control,also the user's basket.)
* This method will invoke the basket class's clear method.
* <p>
* Internal data structures:
* <p>
* Product p.
* @see Product
* @see Basket
*
*/
public void clear(){
//body
}
/**
* Gets all products in the basket.
* <p>
* Algorithm:
* <p>
* This method will invoke the basket class's getProducts method.
* <p>
* Internal data structures:
* <p>
* Basket basket
* @see Basket
* @return the collection class(vector) of the basket (this class control,also the user's basket.)
*/
public Vector getAllProducts(){
return this.basket.getProducts();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -