⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardlist.java

📁 一个出售卡片信息的源码 是我的一个作业
💻 JAVA
字号:
import java.util.LinkedList;

public class CardList {

  /**
   * all the cards
   */
  private static LinkedList<Card> cardList = new LinkedList<Card>();

  /**
   * add card to the list
   * @param card Card
   */
  public static void addCard(Card card){
    if(card!=null)
      cardList.add(card);
  }

  /**
   * get the current cart from the list across the index
   * @param name String
   * @return Card
   */
  public static Card getCard(String index) throws Exception {
    if(cardList!=null)
    for(int i = 0;i < cardList.size();i++){
      Card c = cardList.get(i);
      if(index.equals(c.getId())){
        return c;
      }
    }
    throw new Exception("The card "+index+" doesn't exist");
  }


  public static void saleCard(String index,int quantity) throws
      NotEnoughCardException, Exception {
    Card c = getCard(index);
    int q= c.getQuantity();
    if(quantity<=q){
      c.setQuantity(c.getQuantity()-quantity);
    }else{
        throw new NotEnoughCardException("库存贺卡数量不足");
    }
  }

  /**
   * print the information of the cardlist
   * @return String
   */
  public static String print(){
    String list = "<html><table>";
    if(cardList!=null)
    for(int i =0; i < cardList.size();i++){
      list += "<tr>"+cardList.get(i).getPrintCardInfo()+"</tr>";
    }
    list+="</table></html>";
    return list;
  }

  public static int getSize() {
    return cardList.size();
  }

  public static String getSaleCardName(int i) {
    return cardList.get(i).getName();
  }

  public static int size() {
    return cardList.size();
  }

  public static Card getCard(int i) {
    return cardList.get(i);
  }
}

class NotEnoughCardException
    extends Exception {
 
	private static final long serialVersionUID = 1L;

	public NotEnoughCardException(String s) {
		super(s);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -