admin 管理员组

文章数量: 887021


2023年12月18日发(作者:吊工字钢用什么吊索)

这个购物车用了个简单的Map集合

Megan

1. package ;

2.

3. import p;

4. import ;

5. import r;

6.

7. class Goods{

8.

9.

private Integer id;

private String name;

10. private Integer price;

11. private Integer numbers;

12. Goods(){}

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

27.

28.

29.

30.

31.

32.

33.

34.

35.

36.

public Integer getId() {

}

public void setId(Integer id) {

}

public String getName() {

}

public void setName(String name) {

}

public Integer getPrice() {

}

public void setPrice(Integer price) {

}

public Integer getNumbers() {

}

public void setNumbers(Integer numbers) {

}

s = numbers;

return numbers;

= price;

return price;

= name;

return name;

= id;

return id;

37.

{

38.

39.

40.

41.

42.

43.

44.

45. }

46.

public Goods(Integer id, String name, Integer price, Integer numbers)

}

super();

= id;

= name;

= price;

s = numbers;

47. public class MyGwcDemo {

48.

49.

50.

51.

52.

53.

54.

55.

56.

57.

58.

59.

60.

61.

62.

63.

64.

65.

66.

67.

68. //

69.

70.

71.

72.

Map al=new HashMap();

//添加购物车

public void cun() {

Scanner sc=new Scanner();

n("请输入商品的ID");

Integer id = t();

Goods m=new Goods();

if(nsKey(id)) {

(id).setNumbers(((id).getNumbers()+1));

}else {

(id);

n("请输入商品的名字");

String name = ();

e(name);

n("请输入商品的价格");

int jia = t();

ce(jia);

bers(1);

(id, m);

}

();

}

//查看一件

public void cha() {

n("请输入要查看商品的ID");

73.

74.

75.

76.

77.

78.

79.

80.

81.

82.

83.

84.

85.

86.

87.

88.

89.

90.

91.

92.

93.

94.

95.

96.

97.

98.

99.

Scanner sc=new Scanner();

Integer id = t();

n("Idt名字t价格t数量");

n((id).getId()+"t"+(id).getName()+

}

//删除商品

public void deleate(){

}

//查看购物车

public void View() {

n(()+"t"+e()+"t"+ce()+

}

}

MyGwcDemo myg=new MyGwcDemo();

//Scanner sc =new Scanner();

Scanner sc =new Scanner();

do {

n("1.添加商品t 2.查看商品t 3.删for(Goods g:()) {

n("Idt名字t价格t数量");

n("请输入要删除的商品的ID");

Scanner sc=new Scanner();

Integer id = t();

(id);

//();

//();

"t"+(id).getPrice()+"t"+(id).getNumbers());

"t"+bers());

public static void main(String[] args) {

除商品 t 4.查看所有商品t 5.退出");

100.

101.

102.

103.

Integer it = t();

switch(it) {

case 1: ();

break;

104.

105.

106.

107.

108.

109.

110.

111.

112.

113.

case 2:();

break;

break;

break;

case 3:e();

case 4:();

case 5:

();

(0);

default:n("输入有误,请重新输入");

114.

115.

116.

117.

118.

119.

120.

}

}

break;

}

}while(true);


本文标签: 商品 输入 工字钢 查看 名字