尚学堂给同学们带来全新的Java300集课程啦!java零基础小白自学Java必备优质教程_手把手图解学习Java,让学习成为一种享受_哔哩哔哩_bilibili
详细步骤概述
步骤一:创建类Main
package edu.xcdq;
/**
* 商品类
*/
public class Main {
// 名字 单价 库存 已卖数量
public String name;
public double price;
public int amount;
public int number;
/*
1. 商品展示
*/
public void print(int index) {
System.out.println(index + "\t" + name + "\t" + price + "\t" + amount + "\t" + number);
}
public void setArticle(String mingzi , double danjia, int kucun,int yishou){
name=mingzi;
price=danjia;
amount = kucun;
number = yishou;
}
}
步骤二:创建类Main1
package edu.xcdq;
/**
* @author WYP
* @date 2021/4/6 14:30
*/
/*
2.商品集合类
*/
public class Main1 {
Main[] articles= new Main[38];
}
步骤三:创建类Main2
Main内包含 initial、startMenu
package edu.xcdq;
import java.util.Scanner;
/**
* @author WYP
* @date 2021/4/6 14:30
*/
public class Main2 {
Main1 main = new Main1();
Scanner input = new Scanner(System.in);
/**
* 3. 初始化商品
*/
public void initial(){
Main xiaomi12 = new Main();
/*
xiaomi9.name = "小米12";
xiaomi9.price = 4999;
xiaomi9.amount = 30;
xiaomi9.number = 8;
*/
xiaomi12.setArticle("小米12",4999,30,8);
Main xiaomi11 = new Main();
xiaomi11.setArticle("小米11",3999,30,10);
Main redmi10pro &