最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2018年01月15日 13:42:50   作者:叁念  
這篇文章主要為大家詳細介紹了Java版水果管理系統(tǒng)源碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

主類 FruitsDemo

/**
 * 功能: 
 * 1. 查看所有的水果 
 * 2. 添加新的水果(添加的時候判斷水果名是否有重復(fù)) 
 * 3. 對所有的水果進行排序(價格排序、庫存排序) 
 * 4. 刪除指定的水果
 * 5. 退出系統(tǒng)
 * 
 * 注意: 
 * 1. 每種水果都必須有水果id,水果名,水果數(shù)量,水果價格 
 * 2. 添加水果時,要由用戶輸入水果名、數(shù)量和價格 
 * 3. 刪除水果時要二次確認
 * 
 * 評分依據(jù): 功能實現(xiàn)的情況,代碼規(guī)范性(命名規(guī)范、格式規(guī)范),設(shè)計的合理性
 * @author yj
 *
 */

public class FruitsDemo {
 public static void main(String[] args) {

 int select = 0; // 主菜單功能選擇
 boolean isStart = true;// 程序運行標志位

 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("二次確認?。。≌堅俅屋斎肽阋獎h除的水果");
  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("程序已退出,歡迎使用?。?!");

 }
}

Fruits 類

/**
 * 水果類
 * @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 類

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;
 }

}

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

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

相關(guān)文章

  • springboot3生成本地文件url的實現(xiàn)示例

    springboot3生成本地文件url的實現(xiàn)示例

    本文主要介紹了springboot3生成本地文件url的實現(xiàn)示例,從而提供一種高效的文件管理方式,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-01-01
  • java高并發(fā)ThreadPoolExecutor類解析線程池執(zhí)行流程

    java高并發(fā)ThreadPoolExecutor類解析線程池執(zhí)行流程

    這篇文章主要為大家介紹了java高并發(fā)ThreadPoolExecutor類解析線程池執(zhí)行流程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • SpringBoot常見問題小結(jié)

    SpringBoot常見問題小結(jié)

    這篇文章主要介紹了SpringBoot常見問題小結(jié),需要的朋友可以參考下
    2017-07-07
  • mybatis Example的Criteria用法:or與isNull詳解

    mybatis Example的Criteria用法:or與isNull詳解

    這篇文章主要介紹了mybatis Example的Criteria用法:or與isNull詳解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Java?CAS與JUC組件詳解

    Java?CAS與JUC組件詳解

    CAS是一種基于樂觀鎖的無鎖并發(fā)控制技術(shù),其核心邏輯可以概括為:“我認為當(dāng)前值應(yīng)該是A,如果是,則更新為B;否則放棄或重試”,整個過程由硬件保證原子性,無需傳統(tǒng)鎖機制,本文給大家介紹Java?CAS與JUC組件的相關(guān)知識,感興趣的朋友一起看看吧
    2025-04-04
  • Java 關(guān)系運算符詳情及案例(上)

    Java 關(guān)系運算符詳情及案例(上)

    這篇文章主要介紹了Java 關(guān)系運算符詳情及案例實現(xiàn),Java 也提供了許多類型的運算符,可以根據(jù)需要使用它們來執(zhí)行各種計算和函數(shù),包括邏輯、算術(shù)、關(guān)系等。它們根據(jù)它們提供的功能進行分類,下面將詳細介紹該內(nèi)容,需要的朋友可以參考一下
    2021-12-12
  • 使用Maven將springboot工程打包成docker鏡像

    使用Maven將springboot工程打包成docker鏡像

    這篇文章主要介紹了使用Maven將springboot工程打包成docker鏡像,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Java WeakHashMap案例詳解

    Java WeakHashMap案例詳解

    這篇文章主要介紹了Java WeakHashMap案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 淺談SpringBoot2.4 配置文件加載機制大變化

    淺談SpringBoot2.4 配置文件加載機制大變化

    這篇文章主要介紹了淺談SpringBoot2.4 配置文件加載機制大變化,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Java方法能定義多少個參數(shù)你知道嗎

    Java方法能定義多少個參數(shù)你知道嗎

    這篇文章主要給大家介紹了關(guān)于Java方法能定義多少個參數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用java具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09

最新評論

丁青县| 昭平县| 沾益县| 河源市| 龙泉市| 武山县| 荣成市| 塘沽区| 章丘市| 石柱| 陆川县| 峨边| 青阳县| 肇庆市| 祥云县| 桃园市| 岳阳县| 南华县| 安泽县| 全椒县| 登封市| 西宁市| 科尔| 敖汉旗| 全椒县| 东海县| 分宜县| 秭归县| 元阳县| 甘泉县| 新平| 泊头市| 宿松县| 恩施市| 古田县| 舒兰市| 台州市| 尚志市| 塔河县| 铜鼓县| 永康市|