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. 課程設計感想
本次設計實現了簡單的購物車功能,設計這一整體項目的過程中,培養了我們綜合能力和從全局考慮的思想。出于自己水平有限,也留下了很多待解決的問題,項目中還有不足之處等待完善。通過這次課程設計,鍛煉了動手操作能力。更重要的是,培養了認真鉆研,刻苦學習的精神。