一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務(wù)器之家 - 編程語言 - JAVA教程 - Java版水果管理系統(tǒng)源碼

Java版水果管理系統(tǒng)源碼

2021-03-22 13:50叁念 JAVA教程

這篇文章主要為大家詳細(xì)介紹了Java版水果管理系統(tǒng)源碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

水果管理系統(tǒng)java版分享給大家。

Java版水果管理系統(tǒng)源碼

主類 fruitsdemo

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * 功能:
 * 1. 查看所有的水果
 * 2. 添加新的水果(添加的時候判斷水果名是否有重復(fù))
 * 3. 對所有的水果進行排序(價格排序、庫存排序)
 * 4. 刪除指定的水果
 * 5. 退出系統(tǒng)
 *
 * 注意:
 * 1. 每種水果都必須有水果id,水果名,水果數(shù)量,水果價格
 * 2. 添加水果時,要由用戶輸入水果名、數(shù)量和價格
 * 3. 刪除水果時要二次確認(rèn)
 *
 * 評分依據(jù): 功能實現(xiàn)的情況,代碼規(guī)范性(命名規(guī)范、格式規(guī)范),設(shè)計的合理性
 * @author yj
 *
 */
 
public class fruitsdemo {
 public static void main(string[] args) {
 
 int select = 0; // 主菜單功能選擇
 boolean isstart = true;// 程序運行標(biāo)志位
 
 while (isstart) {
  system.out.println("******************水果管理系統(tǒng)******************\n請輸入下列序號選擇相應(yīng)功能:\n\n 1.查看所有的水果 \t2. 添加新的水果 \n 3.對所有的水果進行排序查看(價格排序、庫存排序) \n 4.刪除水果\t5. 退出系統(tǒng)");
  select = calculation.inputisint();
 
  switch (select) {
  case 1://1.查看所有的水果
  calculation.seeallfruits();
  break;
  case 2://2. 添加新的水果
  calculation.add();
  break;
  case 3://3.對所有的水果進行排序查看(價格排序、庫存排序)
  calculation.sort();
  break;
  case 4:// 4.刪除水果
  system.out.println("請輸入你要刪除的水果");
  string index = calculation.inputisstring();
  system.out.println("二次確認(rèn)!??!請再次輸入你要刪除的水果");
  string index1 = calculation.inputisstring();
  if(index.equals(index1)){
   calculation.remove(index);
  }else{
   system.out.println("兩次輸入不匹配,刪除失?。。?!");
  }
 
  break;
  case 5://5. 退出系統(tǒng)
  isstart = false;
  break;
  default:
  system.out.println("輸入錯誤,請重新輸入");
  break;
  }
 }
 system.out.println("程序已退出,歡迎使用?。。?quot;);
 
 }
}

fruits 類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * 水果類
 * @author yj
 *
 */
public class fruits {
 // 每種水果都必須有水果id,水果名,水果數(shù)量,水果價格
 private int id;//id
 private int nums;//數(shù)量(庫存)
 private string name;//水果名
 private double price;//水果價格
 
 public fruits(int id, string name, int nums, double price) {
 super();
 this.id = id;
 this.nums = nums;
 this.name = name;
 this.price = price;
 }
 
 public int getid() {
 return id;
 }
 
 public void setid(int id) {
 this.id = id;
 }
 
 public int getnums() {
 return nums;
 }
 
 public void setnums(int nums) {
 this.nums = nums;
 }
 
 public string getname() {
 return name;
 }
 
 public void setname(string name) {
 this.name = name;
 }
 
 public double getprice() {
 return price;
 }
 
 public void setprice(double price) {
 this.price = price;
 }
 
 
}

calculation 類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import java.util.collections;
import java.util.comparator;
import java.util.iterator;
import java.util.linkedlist;
import java.util.scanner;
 
/**
 * 計算類,存放關(guān)于計算處理數(shù)據(jù)的函數(shù)
 *
 * @author yj
 *
 */
public class calculation {
 static linkedlist<fruits> list = new linkedlist<fruits>();
 static scanner sc = new scanner(system.in);
 static int id = 1;
 
 /**
 * 添加水果 get()
 */
 public static void add() {
 int nums;
 string name;
 double price;
 
 system.out.print("請輸入你要添加的水果名、數(shù)量(單位:個)和價格(單位:元)\n");
 name = calculation.inputisstring();
 nums = calculation.inputisint();
 price = calculation.inputisdouble();
 
 if (cals(name, nums, price)) {
  list.add(new fruits(id, name, nums, price));
  id++;
 }
 
 }
 
 /**
 * 查看所有水果 seeallfruits()
 */
 public static void seeallfruits() {
 if (list.size() == 0) {
  system.out.println("數(shù)據(jù)為空?。?!");
 } else {
  iterator<fruits> it = list.iterator();
  while (it.hasnext()) {
  fruits temp = it.next();
  system.out.println("id -> " + temp.getid() + "\t水果名稱 -> " + temp.getname() + "\t水果數(shù)量 -> "
   + temp.getnums() + "\t水果價格 -> " + temp.getprice());
  }
 }
 
 }
 
 /**
 * 刪除水果 remove(string index)
 *
 * @param index
 *  你要刪除的水果名
 */
 public static void remove(string index) {
 iterator<fruits> it = list.iterator();
 while (it.hasnext()) {
  if (index.equals(it.next().getname())) {
  it.remove();
  system.out.println(index + "已刪除");
  }
 }
 }
 
 /**
 * 判斷是否重復(fù) cals(string name, int nums, double price)
 *
 * @param name
 *  水果名
 * @param nums
 *  水果數(shù)量
 * @param price
 *  水果價格
 * @return
 */
 public static boolean cals(string name, int nums, double price) {
 iterator<fruits> it1 = list.iterator();
 while (it1.hasnext()) {
  fruits temp = it1.next();
  if (name.equals(temp.getname())) {
  temp.setnums(nums + temp.getnums());
  temp.setprice(price);
  system.out.println("水果——"+name+" 已存在,數(shù)量在原基礎(chǔ)上加上 "+nums+",價格已更新為 "+price);
  return false;
  }
 }
 return true;
 }
 
 /**
 * 排序輸出 sort()
 */
 public static void sort() {
 system.out.println("1.按照價格升序 2.按照庫存升序");
 int n = inputisint();
 switch (n) {
 case 1:
  collections.sort(list, new comparator<fruits>() {
  @override
  public int compare(fruits o1, fruits o2) {
   if (o1.getprice() > o2.getprice()) {
   return 1;
   } else if (o1.getprice() < o2.getprice()) {
   return -1;
   } else {
   return 0;
   }
   // return (int) (o1.getprice() * 100 - o2.getprice() * 100);
  }
  });
  break;
 case 2:
  collections.sort(list, new comparator<fruits>() {
  @override
  public int compare(fruits o1, fruits o2) {
   if (o1.getnums() > o2.getnums()) {
   return 1;
   } else if (o1.getnums() < o2.getnums()) {
   return -1;
   } else {
   return 0;
   }
//   return (int) (o1.getnums() - o2.getnums());
  }
  });
  break;
 default:
  system.out.println("輸入指令錯誤?。?!");
  break;
 }
 seeallfruits();
 }
 
 /**
 * 輸入是否是int inputisint()
 *
 * @return
 */
 
 public static int inputisint() {
 boolean isright = true;
 int select = 0;
 do {
  try {
  select = sc.nextint();
  isright = true;
  } catch (exception e) {
  system.out.println("輸入類型不匹配,請輸入一個整數(shù)(int)");
  sc.nextline();
  isright = false;
  }
 } while (!isright);
 return select;
 }
 
 /**
 * 輸入是否是string inputisstring()
 *
 * @return
 */
 public static string inputisstring() {
 boolean isright = true;
 string select = null;
 do {
  try {
  select = sc.next();
  isright = true;
  } catch (exception e) {
  system.out.println("輸入類型不匹配,請輸入一個字符串(string)");
  sc.nextline();
  isright = false;
  }
 } while (!isright);
 return select;
 }
 
 /**
 * 輸入是否為douuble
 *
 * @return
 */
 public static double inputisdouble() {
 boolean isright = true;
 double select = null;
 do {
  try {
  select = sc.nextdouble();
  isright = true;
  } catch (exception e) {
  system.out.println("輸入類型不匹配,請輸入一個小數(shù)(double)!!!");
  sc.nextline();
  isright = false;
  }
 } while (!isright);
 return select;
 }
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/qq_36868342/article/details/76522356

延伸 · 閱讀

精彩推薦
  • JAVA教程Netty粘包拆包問題解決方案

    Netty粘包拆包問題解決方案

    這篇文章主要介紹了Netty粘包拆包問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下...

    猿天地4162020-08-13
  • JAVA教程SpringMVC---配置與使用的示例

    SpringMVC---配置與使用的示例

    這篇文章主要介紹了SpringMVC---配置與使用的示例,幫助大家更好的理解和學(xué)習(xí)spring框架,感興趣的朋友可以了解下...

    yxs1492020-10-05
  • JAVA教程郵件的組織結(jié)構(gòu)介紹 郵件實現(xiàn)詳解(三)

    郵件的組織結(jié)構(gòu)介紹 郵件實現(xiàn)詳解(三)

    這篇文章主要為大家詳細(xì)介紹了郵件的組織結(jié)構(gòu),郵件內(nèi)容的基本格式和具體細(xì)節(jié),具有一定的參考價值,感興趣的小伙伴們可以參考一下...

    YSOcean9332021-01-19
  • JAVA教程mybatis-plus使用@EnumValue處理枚舉類型的示例代碼

    mybatis-plus使用@EnumValue處理枚舉類型的示例代碼

    這篇文章主要介紹了mybatis-plus使用@EnumValue處理枚舉類型的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,...

    碼農(nóng)-文若書生6402020-09-02
  • JAVA教程Java大數(shù)字運算之BigInteger

    Java大數(shù)字運算之BigInteger

    在Java中提供了大數(shù)字的操作類,即 java.math.BigInteger 類與 java.math.BigDecimal 類。其中,BigInteger 類是針對大整數(shù)的處理類,這里有Integer 類的解釋,使用方法和...

    司機2512020-12-22
  • JAVA教程java實現(xiàn)模擬RPG格斗

    java實現(xiàn)模擬RPG格斗

    這篇文章主要介紹了java實現(xiàn)模擬RPG格斗,每個英雄具有以下幾個屬性:生命值(為0時英雄倒下)、攻擊力(每次攻擊時扣除對方的生命值點數(shù))、攻擊間...

    hebedich4742019-12-14
  • JAVA教程解析Java的Spring框架的基本結(jié)構(gòu)

    解析Java的Spring框架的基本結(jié)構(gòu)

    這篇文章主要介紹了Java的Spring框架的基本結(jié)構(gòu),作者從Spring的設(shè)計角度觸發(fā)解析其基礎(chǔ)的架構(gòu)內(nèi)容,需要的朋友可以參考下 ...

    liweisnake3852020-04-11
  • JAVA教程Java class文件格式之常量池_動力節(jié)點Java學(xué)院整理

    Java class文件格式之常量池_動力節(jié)點Java學(xué)院整理

    這篇文章主要為大家詳細(xì)介紹了Java class文件格式之常量池的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下...

    動力節(jié)點2222020-11-17
主站蜘蛛池模板: 色老板免费在线观看 | 天美视频在线 | 高清一级片 | 色综色| 九九免费精品视频 | 95视频免费看片 | 80日本xxxxxxxxx96| 国产在亚洲线视频观看 | 日韩视频一区 | 亚洲美洲国产日产 | 亚洲人成网站在线观看青青 | 亚洲视频在线一区二区 | 我的妹妹最近有点怪在线观看 | 国产精品毛片va一区二区三区 | 黄动漫车车好快的车车a | 99爱在线精品视频免费观看9 | 亚洲首页国产精品丝袜 | 3d蒂法精品啪啪一区二区免费 | 奇米影视奇米色777欧美 | 91视频a| 亚洲精品久久中文字幕 | 日本成人黄色片 | 奇米视频7777 | 美女脱了内裤让男桶爽 | 国产福利在线观看永久视频 | 色就色欧美综合偷拍区a | 大象传媒免费网址 | 国产乱子伦一区二区三区 | 亚洲乱码一区二区三区国产精品 | 美女模特被c免费视频 | 6个老师的尿奴 | 日本肉体xxxx| 久久久精品免费免费直播 | ai换脸明星专区在线观看 | 调教催眠 | 国产精品网站在线观看 | 顶级欧美做受xxx000大乳 | 亚洲国产天堂久久精品网 | 亚洲 欧美 清纯 校园 另类 | 99这里只有精品视频 | 我被黑人彻底征服的全文 |