Java课程设计 购物车系统(个人博客) 201521123052 蓝锦明

1. 团队课程设计博客链接

课程设计团队博客

2. 个人负责模块或任务说明

(1)制作图形菜单引导界面
(2)定义各获取和输出类函数

3. 自己的代码提交记录截图


4. 自己负责模块或任务详细说明

import java.text.NumberFormat; 

public class Item 
{ 
	private int no;
	private String name; 
	private String brand; 
	private double price; 

	// ------------------------------------------------------- 
	//  Create a new item with the given attributes. 
	// ------------------------------------------------------- 

	public Item(int no, String name, String brand, double price) {
		this.no = no;
		this.name = name;
		this.brand = brand;
		this.price = price;
	}
	
	public void setNo(int no) {
		this.no = no;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public double getPrice() 
	{ 
		return price; 
	} 

	public String getName() 
	{ 
		return name; 
	} 

	public String getBrand() {
		return brand;
	}

	public int getNo() {
		return no;
	}

	public String toString () 
	{ 
		NumberFormat fmt = NumberFormat.getCurrencyInstance(); 

		return (no + "\t\t" + name + "\t\t" + brand + "\t\t" + fmt.format(price));
	} 

}  
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ItemPanel extends JPanel{
	private final int MAXNUM = 100;
	private JLabel[] item;
	private JLabel[] options;
	private Scanner scanItems;
	int num = 0;
	
	
	public ItemPanel() throws FileNotFoundException {
		scanItems = new Scanner(new File("E:\\Eclipse\\project\\JAVA\\src\\item2\\Items"));
		
		item = new JLabel[MAXNUM];
		for (int i = 0; scanItems.hasNextLine(); i++) {
			item[i] = new JLabel(scanItems.nextLine());
			num++;
		}
		
		options = new JLabel[5];
		setLayout(new GridLayout(num + options.length, 1));
		
                options[0] = new JLabel("查看商品请输入1");
		options[1] = new JLabel("购买商品请输入2");
		options[2] = new JLabel("删除商品请输入3");
		options[3] = new JLabel("修改商品请输入4");
		options[4] = new JLabel("结算商品请输入0");
	
		for (int i = 0; i < num; i++) {
			add(item[i]);
		}
		for (int i = 0; i < options.length; i++) {
			add(options[i]);
		}
		setBackground(Color.white);
		setPreferredSize(new Dimension(200,200
				));
	}
}

5. 课程设计感想

本次设计实现了简单的购物车功能,设计这一整体项目的过程中,培养了我们综合能力和从全局考虑的思想。出于自己水平有限,也留下了很多待解决的问题,项目中还有不足之处等待完善。通过这次课程设计,锻炼了动手操作能力。更重要的是,培养了认真钻研,刻苦学习的精神。

posted @ 2017-06-23 12:13  N.Jming  阅读(438)  评论(0编辑  收藏  举报