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

📄 coffee.java

📁 这是一个用JAVA编写的小型商品管理系统
💻 JAVA
字号:
import  java.awt.*;
import java.util.StringTokenizer;

import  javax.swing.*;

/**
 * This class models a coffee product. It extends
 * {@link Product} and adds the following information:
 * <ol>
 * <li>the origin of the coffee, a <code>String</code></li>
 * <li>the roast of the coffee, a <code>String</li>
 * <li>the flavor of the coffee, a <code>String</li>
 * <li>the aroma of the coffee, a <code>String</li>
 * <li>the acidity of the coffee, a <code>String</li>
 * <li>the body of the product, a <code>double</li>
 * </ol>
 *
 * @author
 * @version  1.0.0
 * @see Product
 */
public class Coffee extends Product  {

	/* Origin of the coffee. */
	private String  origin;

	/* Roast of the coffee. */
	private String  roast;

	/* Flavor of the coffee. */
	private String  flavor;

	/* Aroma of the coffee. */
	private String  aroma;

	/* Acidity of the coffee.*/
	private String  acidity;

	/* Body of the coffee */
	private String  body;

	/**
	 * Constructs a <code>Coffee</code> object.
	 *
	 * @param initialCode  the code of the product.
	 * @param initialDescription  a short description of the product.
	 * @param initialPrice  the price of the product.
	 * @param initialOrigin the origin of coffee.
	 * @param initialRoast the kind of roast of the coffee.
	 * @param initialFlavor  the flavor of the coffee.
	 * @param initialAroma  the aroma of the coffee.
	 * @param initialAcidity  the acidity of the coffee.
	 * @param initialBody  the body of the coffee.
	 */
	public Coffee(String initialCode, String initialDescription,
			double  initialPrice, String initialOrigin,
			String initialRoast, String initialFlavor,
			String initialAroma, String initialAcidity,
			String initialBody) {

		super(initialCode, initialDescription, initialPrice);

		origin = initialOrigin;
		roast = initialRoast;
		flavor = initialFlavor;
		aroma = initialAroma;
		acidity = initialAcidity;
		body = initialBody;
	}

	/**
	 * Returns the origin of this coffee.
	 *
	 * @return  the origin of this coffee.
	 */
	public String  getOrigin()  {

		return  origin;
	}

	/**
	 * Returns the roast of this coffee.
	 *
	 * @return  the roast of this coffee.
	 */
	public String  getRoast()  {

		return  roast;
	}

	/**
	 * Returns the flavor of this coffee.
	 *
	 * @return  the flavor of this coffee.
	 */
	public String  getFlavor()  {

		return  flavor;
	}

	/**
	 * Returns the aroma of this coffee.
	 *
	 * @return  the aroma of this coffee.
	 */
	public String  getAroma()  {

		return  aroma;
	}

	/**
	 * Returns  the acidity of this coffee.
	 *
	 * @return  the acidity of this coffee.
	 */
	public String  getAcidity()  {

		return  acidity;
	}

	/**
	 * Returns the body of this coffee.
	 *
	 * @return  the body of this coffee.
	 */
	public String  getBody()  {

		return  body;
	}

	/**
	 * Returns the string representation of this coffee.
	 *
	 * @return  the string representation of this coffee.
	 */
	public String  toString()  {

		return super.toString() + "_" + getOrigin() + "_" + getRoast() + "_"
		       + getFlavor() + "_" + getAroma()	+"_"+ getAcidity() + "_"
		       + getBody();
	}

	/**
	 * Obtains a {@link JPanel} object with the information of this
	 * coffee product.
	 *
	 * @return a {@link JPanel} with the information of this coffee product.
	 */
	public JPanel getPanel() {
		
		JTextArea text1;
		JTextArea text2;
		
		String item = "Code:\nDescription:\nPrice:\nOrigin:\nRoast:\nFlavor:\nAroma:\nAcidity:\nBody:";
		text1 = new JTextArea(item ,10, 1);
		text1.setEditable(false);
		
		
		StringTokenizer tokenizer =
            new StringTokenizer(this.toString(), "_");
		String token = tokenizer.nextToken();
		String add = token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;
		token = tokenizer.nextToken();
		add = add+"\n"+token;

		
		text2 = new JTextArea(add, 10, 1);
		text2.setEditable(false);
		
		JPanel text3 = new JPanel();
		text3.setLayout(new GridLayout(1,2));
		text3.add(text1);
		text3.add(text2);
		

		return text3;
	}


		
}

⌨️ 快捷键说明

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