1、項目背景
基于JavaSE完成如下需求:
功能需求:
1、查詢庫存量
2、可以修改庫存中不同品牌手機的個數(shù)
3、退出系統(tǒng)
實現(xiàn)步驟:
1、把List當做庫房
2、把手機存放在庫房中
3、使用封裝的方法區(qū)操作倉庫中的手機
2、項目知識點
面向對象
集合
循環(huán)
流程控制語句
方法文章來源:http://www.zghlxwxcb.cn/news/detail-605531.html
3、 代碼
//模板類
public class Phone {
//屬性
String brand;//品牌
double size;//尺寸
int price;//價格
int num;//庫存量
}
import java.util.ArrayList;
import java.util.Scanner;
/*
手機庫存管理系統(tǒng)
*/
public class Demo15 {
public static void main(String[] args) {
/*
功能需求:
1、查詢庫存量
2、可以修改庫存中不同品牌手機的個數(shù)
3、退出系統(tǒng)
實現(xiàn)步驟:
1、把List當做庫房
2、把手機存放在庫房中
3、使用封裝的方法區(qū)操作倉庫中的手機
*/
//創(chuàng)建倉庫
ArrayList<Phone> list = new ArrayList<>();
//添加產(chǎn)品到倉庫
add(list);
//選擇功能
action(list);
}
//功能分類
public static void action(ArrayList<Phone> list) {
while (true) {
System.out.println("請用戶選擇需要的功能:");
System.out.println("輸入1,查看庫存清單!");
System.out.println("輸入2,修改庫存數(shù)量!");
System.out.println("輸入3,退出系統(tǒng)!");
//調用方法:提供用戶輸入數(shù)字選擇對應功能的方法
switch (chooseAction()) {
//查看庫存
case 1:
findAll(list);
break;
case 2:
updateNum(list);
break;
case 3:
System.out.println("退出成功!?。?);
return;
}
}
}
//添加數(shù)據(jù)
public static void add(ArrayList<Phone> list) {
//創(chuàng)建產(chǎn)品
Phone p1 = new Phone();
Phone p2 = new Phone();
Phone p3 = new Phone();
Phone p4 = new Phone();
p1.brand = "HUAWEI";
p2.brand = "OPPO";
p3.brand = "VIVO";
p4.brand = "XIAOMI";
p1.size = 12.5;
p2.size = 12.4;
p3.size = 12.3;
p4.size = 12.2;
p1.price = 10000;
p2.price = 20000;
p3.price = 30000;
p4.price = 40000;
p1.num = 2000;
p2.num = 1000;
p3.num = 2100;
p4.num = 1100;
//將產(chǎn)品添加到集合中
list.add(p1);
list.add(p2);
list.add(p3);
list.add(p4);
}
//查詢數(shù)據(jù)
public static void findAll(ArrayList<Phone> list) {
//遍歷集合
for (Phone phone : list) {
String brand = phone.brand;
double size = phone.size;
int price = phone.price;
int num = phone.num;
System.out.println(brand + "手機" + ",尺寸:" + size + ",價錢:" + price + ",庫存數(shù)量:" + num);
}
}
//修改數(shù)據(jù)
public static void updateNum(ArrayList<Phone> list) {
for (Phone phone : list) {
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入要修改:"+phone.brand+"的庫存的值!");
phone.num = scanner.nextInt();
System.out.println("修改成功,請繼續(xù)輸入");
}
//再查詢1次數(shù)
findAll(list);
}
//功能選擇
public static int chooseAction() {
System.out.println("請輸入選擇的功能序號!");
Scanner sc = new Scanner(System.in);
int anInt = sc.nextInt();
return anInt;
}
}
4、運行功能
文章來源地址http://www.zghlxwxcb.cn/news/detail-605531.html
到了這里,關于基于JavaSE的手機庫存管理系統(tǒng)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!