当前位置:网站首页>0708作业---商品信息
0708作业---商品信息
2022-08-11 05:12:00 【余谦吖】
1.柜台商品管理系统
实体类:Goods
属性
id 商品编号
goodsName 商品名称
price 商品价格
desc 商品描述
封装..提供get和set
无参构造器和有参构造器
有参构造器初始化初始化商品对象
重写toString()方法
可以直接显示数据
package cn.hp;
/**
* id 商品编号
* goodsName 商品名称
* price 商品价格
* desc 商品描述
*/
public class Goods {
private Integer id;
private String goodsName;
private Integer price;
private String desc;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Goods(Integer id, String goodsName, Integer price, String desc) {
this.id = id;
this.goodsName = goodsName;
this.price = price;
this.desc = desc;
}
public Goods() {
}
@Override
public String toString() {
return "Goods{" +
"id=" + id +
", goodsName='" + goodsName + '\'' +
", price=" + price +
", desc='" + desc + '\'' +
'}';
}
}
#2.柜台类:Counter
属性:
柜台商品列表,固定10个商品位置
Goods[]goodses = new Goods[10];
num 柜台商品数量
构造器:
无参构造器初始化2个商品
public Counter(){
this.goodses[0]=new Goods(1001,"巧克力",25,"美味可口,恋爱必备!");
this.goodses[1]=new Goods(1002,"卫龙辣条",1,"隔壁小孩馋哭了!");
num=2;//相当于两个商品
}
业务方法:
展示柜台所有的商品(不能输出null)
public void show(){
}
package cn.hp;
/**
* 柜台商品列表,固定10个商品位置
* Goods[]goodses = new Goods[10];
* num 柜台商品数量
*/
public class Counter {
Goods[] goodses = new Goods[10];
int nums;
public Counter(){
this.goodses[0] = new Goods(1001,"巧克力",25,"美味可口,恋爱必备!");
this.goodses[1]=new Goods(1002,"卫龙辣条",1,"隔壁小孩馋哭了!");
nums = 2;
}
public void show(){
for (int i = 0; i < goodses.length; i++) {
if (goodses[i]!=null){
System.out.println(goodses[i]);
}
}
}
}
#3.测试类:CounterTest
程序入口main方法中,创建柜台对象,调用show()方法展示柜台商品
package cn.hp;
public class CounterTest {
public static void main(String[] args) {
Counter cou = new Counter();
cou.show();
}
}

边栏推荐
- Decryption of BitLocker
- K8s复习笔记7--Redis单机和Redis-cluster的K8S实现
- Application layer protocol - DNS
- oracle tablespace and user creation
- 宝塔Linux环境下redis开启多端口
- Trilium使用总结
- 02.折叠隐藏文字
- Weekly recommended short video: your commonly used Polaroid, its predecessor turned out to be like this!
- 3 Module 2: Use of scientific research tools
- Project Practice Lecture 27: Application of Status Mode in Duplicate Brands
猜你喜欢

分库分表ShardingSphere-JDBC笔记整理

Switch and Router Technology-34-Dynamic NAT

How to switch Green Shield encryption to IP-Guard encryption smoothly

The use of async (asynchronous) and await

Switches and routers technology - 26 - configure OSPF peripheral area

Application layer protocol - DNS

什么是三次握手和四次挥手(清晰易懂)

网络协议1

Redis-数据类型(基本指令、String、List、Set、Hash、ZSet、BitMaps、HyperLogLog、GeoSpatial)/发布和订阅

2022年Android面试中最常问的问题是什么?
随机推荐
Paper Notes: BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
[Embedded open source library] The use of MultiButton, an easy-to-use event-driven button driver module
【嵌入式开源库】MultiTimer 的使用,一款可无限扩展的软件定时器
Switch and Router Technology-29-OSPF Virtual Link
Oracle常用语句归纳_持续更新
Four functional interfaces
[E-commerce operation] How to formulate a social media marketing strategy?
Sub-database sub-table ShardingSphere-JDBC notes arrangement
Difference between @Resource and @Autowired
【ARM】rk3399挂载nfs报错
CentOS7静默安装Oracle11g_转载
Switches and routers technology - 26 - configure OSPF peripheral area
02. Fold hidden text
Delphi7 learning record - demo example
Use Adobe genuine software for prostitution to reduce the slow employment and non-employment of fresh graduates
FPGA engineer interview questions collection 111~120
2021 Network Planning Designer Afternoon Case Questions
Decryption of BitLocker
Paper Notes: Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
Win10远程连接(实现多用户同时连接)