目录
熟悉面向对象思维
创建类
package com.google.demo;
/**
* @author North
* @date 2022/9/20 13:27
*/
public class Goods {
int id; // 编号
String name; // 名称
double price; // 价格
int buyNumber; // 购买数量
}
创建测试类
package com.google.demo;
import javax.xml.ws.soap.Addressing;
import java.util.Scanner;
/**
* @author North
* @date 2022/9/20 13:28
*/
public class ShopCarTest {
public static void main(String[] args) {
/**
* 目标 : 面向对象编程训练 , 购物车模拟
*
* 1. 定义商品类 , 用于后期创建商品对象
* 2. 定义购物车对象 , 使用一个数组对象表示
*/
// 定义一个动态数组
Goods[] showCar = new Goods[100];
while (true) {
// 搭建操作架构
System.out.println("请你选择一下命令进行操作");
System.out.println("添加商品到购物车:add");
System.out.println("查询购物车商品展示:query");
System.out.println("修改商品购买数量:update");
System.out.println("结算购买商品的金额:pay");
System.out.println("退出界面:quit");
Scanner scanner = new Scanner(System.in);
System.out.println("请您输入命令:");
String command = scanner.next();
switch