import java.util.ArrayList;
import java.util.Scanner;
class Phone{
private String name;
private String color;
private int price;
private int num;
public Phone() {
}
public Phone(String name, String color, int price, int num) {
this.name = name;
this.color = color;
this.price = price;
this.name = name;
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
@Override
public String toString() {
return "Phone [name=" + name + ", color=" + color + ", price=" + price + ", num=" + num + "]";
}
}
public class li2 {
static ArrayList<Phone> c = new ArrayList<>();
static Scanner sc = new Scanner(System.in);
public static void main (String[] arge) {
c.add(new Phone("小米14","玫瑰金",3999,15));
c.add(new Phone("小米14","幻彩紫",3699,28));
c.add(new Phone("华为p30","白金色",5699,2));
c.add(new Phone("华为p30","幻彩白",5999,18));
c.add(new Phone("VIVO PLus9","幻彩紫",2699,28));
c.add(new Phone("魅族16th","紫金黑",5229,10));
c.add(new Phone("苹果11","土豪金",5999,51));
System.out.println("欢迎使用库房管理系统,请选择要进行的操作");
while (true) {
System.out.println("1、商品入库");
System.out.println("2、商品显示");
System.out.println("3、删除商品");
System.out.println("4.退出系统");
int choice = sc.nextInt();
if(choice ==1) {
add();
show();
}else if (choice ==2) {
show();//商品显示
}else if (choice ==3) {
delete();
show();
}else if (choice ==4) {
break;
}else {
System.out.println("您的输入有误!");
}
}
}
private static void delete() {
System.out.println("请输入要删除的商品编号:");
int i = sc.nextInt();
c.remove(i-1);
System.out.println("商品删除成功");
}
private static void show() {
if(c.size() == 0) {
System.out.println("目前没有商品可以查看");
}else {
System.out.println("目前现有的商品为:");
for(Phone phone :c) {
System.out.println(phone);
}
}
}
private static void add() {
System.out.println("您是否录入商品?");
String choice = sc.next();
if("yes".equals(choice)) {
System.out.println("请输入商品的名称:");
String name = sc.next();
System.out.println("请输入商品的颜色:");
String color = sc.next();
System.out.println("请输入商品的价格:");
int price = sc.nextInt();
System.out.println("请输入商品的数量:");
int num = sc.nextInt();
Phone p = new Phone(name,color,price,num);
c.add(p);
System.out.println("商品入库成功");
}else {
return;
}
}
}
效果呈现

800

被折叠的 条评论
为什么被折叠?



