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

📄 card.java

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

public class Card {
	/**
	 * the maximum quantity of the card
	 */
	private static final int MAX = 100;

	/**
	 * the id of the card
	 */
	private String id;

	/**
	 * the name of the card
	 */
	private String name;

	/**
	 * the rest quantity of the card
	 */
	private int quantity;

	/**
	 * the price of the card
	 */
	private double price;

	/**
	 * the name of the stuff
	 */
	private String stuffName;
	
	/**
	 * construct the card when the info read from the
	 */
	public Card(String id, String name, double price) {
		this.id = id;
		this.name = name;
		this.price = price;
		this.quantity = MAX;
	}

	/**
	 * constructor
	 */
	public Card(String stuffName, String id, String name, int quantity,
			double price) {
		this.stuffName = stuffName;
		this.id = id;
		this.name = name;
		this.quantity = quantity;
		this.price = price;
	}

	/**
	 * the get methods
	 */
	public String getStuffName() {
		return this.stuffName;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getQuantity() {
		return quantity;
	}

	public String getStringPrice() {
		NumberFormat nf = NumberFormat.getInstance();
		nf.setMinimumFractionDigits(2);
		String p = nf.format(price);
		return p;
	}

	public double getPrice() {
		return price;
	}

	/**
	 * the set methods
	 */
	public void setName(String name) {
		this.name = name;
	}

	public void setQuantity(int quantity) throws Exception {
		if (quantity > MAX) {
			throw new Exception(
					"The number of card is beyond the maximum quantity");
		}
		if (quantity <= 0) {
			throw new Exception("The number of the card must be bigger the 0");
		}
		this.quantity = quantity;
	}

	public void setStuffName(String stuffName) {
		this.stuffName = stuffName;
	}

	public void setSalesInfo(int quantity,String stuffName) {
		this.quantity -= quantity;
		this.stuffName = stuffName;
	}


	/**
	 * overwrite the method toString() in the super class
	 * 
	 * @return String
	 */
	public String toString() {
		return id + "号 " + name + " 圣诞卡:单价 " + getStringPrice() + "\r\n";
	}

	/**
	 * get the sales information of the card
	 */
	public String getPrintSalesInfo() {
		String info = "";

		for (int i = 0; i < SaleList.getSize(); i++) {
			Card s = (Card) (SaleList.remove());
			NumberFormat f = NumberFormat.getInstance();
			f.setMinimumFractionDigits(2);
			f.setMaximumFractionDigits(2);
			double fee = s.getQuantity() * price;
			String f1 = f.format(fee);
			String p = f.format(price);
			info += (s.getStuffName() + "                 " + s.getQuantity()
					+ " * $  " + p + " =  $ " + f1 + "\n");
		}
		return info;
	}

	/**
	 * get the sales information of the card
	 * 
	 * @return String
	 */
	public String getPrintCardInfo() {
		String info = "<td>" + getId() + "  </td>" + "<td>" + getName()
				+ "  </td><td>$" + getStringPrice() + "  </td><td>"
				+ getQuantity() + "  </td>";
		return info;
	}
}

⌨️ 快捷键说明

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