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

Java實(shí)現(xiàn)圖書借閱系統(tǒng)

 更新時(shí)間:2022年03月11日 08:09:45   作者:Markrce  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)圖書借閱系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

今天這個(gè)是一個(gè)Java小練習(xí),一個(gè)圖書借閱系統(tǒng),需要實(shí)現(xiàn)的功能有:

  • 判斷用戶是否需要進(jìn)行借書
  • 在用戶選擇借書時(shí),展示出圖書列表
  • 圖書列表包含 圖書序號(hào)、圖書名稱、借閱價(jià)格、作者
  • 用戶選擇借書數(shù)量、并選擇對應(yīng)圖書、借閱天數(shù)
  • 計(jì)算出用戶需支付金額

Book.java

package com.imooc;

/**
?* 圖書類 包含圖書序號(hào) 名稱 價(jià)格
?* */

public class Book {
? ? private int id;
? ? private String name;
? ? private double price;
? ? private String author;

? ? public Book(int id, String name, double price, String author) {
? ? ? ? // TODO Auto-generated constructor stub
? ? ? ? this.id = id;
? ? ? ? this.setName(name);
? ? ? ? this.price = price;
? ? ? ? this.author = author;
? ? }

? ? public void setId(int id) {
? ? ? ? this.id = id;
? ? }

? ? public int getId() {
? ? ? ? return id;
? ? }

? ? public void setPrice(double price) {
? ? ? ? this.price = price;
? ? }

? ? public double getPrice() {
? ? ? ? return price;
? ? }

? ? public void setAuthor(String author) {
? ? ? ? this.author = author;
? ? }

? ? public String getAuthor() {
? ? ? ? return author;
? ? }

? ? public void setName(String name) {
? ? ? ? this.name = name;
? ? }

? ? public String getName() {
? ? ? ? return name;
? ? }

}

BorrowBooks.java

package com.imooc;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BorrowBooks {

? ? /**
? ? ?* @param args
? ? ?*/
? ? public static void main(String[] args) {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? System.out.println("~~~~~~~歡迎使用圖書借閱系統(tǒng)~~~~~~~~ ");
? ? ? ? System.out.println("您是否要借書:1.是 >> 點(diǎn)擊其他鍵退出");
? ? ? ? BorrowBooks test = new BorrowBooks();
? ? ? ? while (test.test1()) {
? ? ? ? ? ? System.out.println(">>>您可選擇圖書及其價(jià)目表:");
? ? ? ? ? ? System.out.println("-------------------------------------------");
? ? ? ? ? ? Book[] books = { new Book(0, "紅樓夢", 12, "曹雪芹"),
? ? ? ? ? ? ? ? ? ? new Book(1, "西游記", 12, "吳承恩"),
? ? ? ? ? ? ? ? ? ? new Book(2, "漢鄉(xiāng)", 12, "孑與2"),
? ? ? ? ? ? ? ? ? ? new Book(3, "大魏宮廷", 12, "賤宗首席"),
? ? ? ? ? ? ? ? ? ? new Book(4, "三國演義", 12, "羅貫中"),
? ? ? ? ? ? ? ? ? ? new Book(5, "水滸傳", 12, "施耐庵") };
? ? ? ? ? ? System.out.println("序號(hào)" + " ?" + "\t" + "書名" + " ? ? " + "\t"
? ? ? ? ? ? ? ? ? ? + "租金" + " ? ? ?" + "\t" + "作者");
? ? ? ? ? ? for (Book book : books) {
? ? ? ? ? ? ? ? if (book.getClass().equals(Book.class)) {
? ? ? ? ? ? ? ? ? ? System.out.println(book.getId() + "\t" + "\t"
? ? ? ? ? ? ? ? ? ? ? ? ? ? + book.getName() + "\t" + "\t" + book.getPrice()
? ? ? ? ? ? ? ? ? ? ? ? ? ? + "/天" + "\t" + "\t" + book.getAuthor() + "/著");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println("-------------------------------------------");
? ? ? ? ? ? System.out.println("-->請輸入你要借書的數(shù)量:");
? ? ? ? ? ? Scanner zScanner = new Scanner(System.in);
? ? ? ? ? ? int BookNum = zScanner.nextInt();
? ? ? ? ? ? if (BookNum > 0) {
? ? ? ? ? ? ? ? List<Book> bookList = new ArrayList<Book>();
? ? ? ? ? ? ? ? int add = 0;
? ? ? ? ? ? ? ? int bookPrice = 0;
? ? ? ? ? ? ? ? for (int i = 0; i < BookNum; i++) {
? ? ? ? ? ? ? ? ? ? System.out.println(">>請輸入第" + (i + 1) + "本書的序號(hào):");
? ? ? ? ? ? ? ? ? ? int num = zScanner.nextInt();
? ? ? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? ? ? bookList.add(books[num]);
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("----成功添加:"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? + bookList.get(add).getName());
? ? ? ? ? ? ? ? ? ? ? ? if (books[num].getClass().equals(Book.class)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? bookPrice += ((Book) bookList.get(add)).getPrice();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? add++;
? ? ? ? ? ? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? ? ? ? ? ? // TODO: handle exception
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的圖書序號(hào)不正確");
? ? ? ? ? ? ? ? ? ? ? ? i = i - 1;
? ? ? ? ? ? ? ? ? ? ? ? BookNum = BookNum;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println("->請輸入借閱的天數(shù):");
? ? ? ? ? ? ? ? Scanner g = new Scanner(System.in);
? ? ? ? ? ? ? ? int bookDay = g.nextInt();
? ? ? ? ? ? ? ? bookPrice = bookPrice * bookDay;
? ? ? ? ? ? ? ? System.out.println("------------借閱選書完成------------" + "\n"
? ? ? ? ? ? ? ? ? ? ? ? + "下面開始統(tǒng)計(jì)數(shù)據(jù)..........");
? ? ? ? ? ? ? ? System.out.print("您借閱的圖書" + BookNum + "本:" + " ");
? ? ? ? ? ? ? ? for (Book book : bookList) {
? ? ? ? ? ? ? ? ? ? System.out.println(book.getName() + " " + "\n");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println();
? ? ? ? ? ? ? ? System.out.println("共租用:" + bookDay + " 天");
? ? ? ? ? ? ? ? System.out.println("需要付款:" + bookPrice + " 元");
? ? ? ? ? ? ? ? System.out.println("->請輸入付款金額:");
? ? ? ? ? ? ? ? System.out.println("------------");
? ? ? ? ? ? ? ? Scanner x = new Scanner(System.in);
? ? ? ? ? ? ? ? ?int priceSpread = bookPrice - x.nextInt();//定義差價(jià)
? ? ? ? ? ? ? ? ?while (bookPrice != x.nextInt())

? ? ? ? ? ? ? ? ?System.out.println("------------" + "\n" + "輸入錯(cuò)誤,請重新輸入金額!");


? ? ? ? ? ? ? ? /*
? ? ? ? ? ? ? ? ?while (bookPrice != x.nextInt())
? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ?if (bookPrice > x.nextInt()) {
? ? ? ? ? ? ?int priceSpread = bookPrice - x.nextInt();//定義差價(jià)
? ? ? ? ? ? ? ? ?System.out.println("------------" + "\n" + "您已付款"
? ? ? ? ? ? ?+ x.nextInt() + "元,還需支付" + priceSpread + "元");
? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ?if (bookPrice <x.nextInt()) {
? ? ? ? ? ? ? ? ?int priceSpread = x.nextInt()-bookPrice ;//定義差價(jià)
? ? ? ? ? ? ?System.out.println("------------" + "\n" + "您已付款"
? ? ? ? ? ? ?+ x.nextInt() + "元,找您" + priceSpread + "元");
? ? ? ? ? ? ?}
*/
? ? ? ? ? ? ? ? System.out.println("------------");
? ? ? ? ? ? ? ? System.out.println(" ? ? ? ? ? ? ?交易成功!");
? ? ? ? ? ? ? ? System.out.println();
? ? ? ? ? ? ? ? System.out.println("------------感謝您的使用--------------");
? ? ? ? ? ? ? ? System.out.println("………………繼續(xù)借書請按1,退出請按其他鍵………………");
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? System.out.println("您輸入的借書數(shù)量為“0”,自動(dòng)為您退出系統(tǒng)");
? ? ? ? ? ? ? ? System.exit(0);
? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? private static Object bookPrice(int nextInt) {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? return null;
? ? }

? ? // 捕獲輸入?yún)?shù)不正確異常
? ? public boolean test1() {
? ? ? ? try {
? ? ? ? ? ? Scanner z = new Scanner(System.in);
? ? ? ? ? ? if (z.nextInt() == 1) {
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? } catch (Exception e1) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? }
}

運(yùn)行效果圖

存在問題

在BorrowBooks.java這個(gè)Class中,下面這段代碼本想實(shí)現(xiàn)判斷用戶輸入的金額是否和應(yīng)付金額一致,不一致時(shí)給出不同的回復(fù),但是自己試了好多種方法,都沒有實(shí)現(xiàn),還是自己懂得太少:

while (bookPrice != x.nextInt())
? ? ? ?{
? ? ? ? if (bookPrice > x.nextInt()) {
? ? ? ? int priceSpread = bookPrice - x.nextInt();//定義差價(jià)
? ? ? ? System.out.println("------------" + "\n" + "您已付款"
? ? ? ? + x.nextInt() + "元,還需支付" + priceSpread + "元");
? ? ? ? }

? ? ? ? if (bookPrice <x.nextInt()) {
? ? ? ? int priceSpread = x.nextInt()-bookPrice ;//定義差價(jià)
? ? ? ? System.out.println("------------" + "\n" + "您已付款"
? ? ? ? + x.nextInt() + "元,找您" + priceSpread + "元");
? ? ? ? }
? ? ? ? }

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

相關(guān)文章

  • Mybatis-Plus 多表聯(lián)查分頁的實(shí)現(xiàn)代碼

    Mybatis-Plus 多表聯(lián)查分頁的實(shí)現(xiàn)代碼

    本篇文章主要介紹了Mybatis-Plus 多表聯(lián)查分頁的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • java.io.NotSerializableException異常的問題及解決

    java.io.NotSerializableException異常的問題及解決

    這篇文章主要介紹了java.io.NotSerializableException異常的問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • 數(shù)據(jù)庫連接超時(shí)java處理的兩種方式

    數(shù)據(jù)庫連接超時(shí)java處理的兩種方式

    這篇文章主要介紹了數(shù)據(jù)庫連接超時(shí)java處理的兩種方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • java學(xué)生信息管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)

    java學(xué)生信息管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了java學(xué)生信息管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • IDEA的TODO的使用方式

    IDEA的TODO的使用方式

    這篇文章主要介紹了IDEA的TODO的使用方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Spring中的@CrossOrigin注解的使用詳細(xì)解讀

    Spring中的@CrossOrigin注解的使用詳細(xì)解讀

    這篇文章主要介紹了Spring中的@CrossOrigin注解的使用詳細(xì)解讀,跨源資源共享(CORS),是由大多數(shù)瀏覽器實(shí)現(xiàn)的W3C規(guī)范,允許對跨域請求進(jìn)行靈活授權(quán),用來代替IFRAME或JSONP等非正規(guī)實(shí)現(xiàn)方式,需要的朋友可以參考下
    2023-11-11
  • SpringBoot通過AOP與注解實(shí)現(xiàn)入?yún)⑿r?yàn)詳情

    SpringBoot通過AOP與注解實(shí)現(xiàn)入?yún)⑿r?yàn)詳情

    這篇文章主要介紹了SpringBoot通過AOP與注解實(shí)現(xiàn)入?yún)⑿r?yàn)詳情,文章從相關(guān)問題展開全文內(nèi)容詳情,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • Java中解析JSON和生成JSON字符串的全面指南

    Java中解析JSON和生成JSON字符串的全面指南

    在現(xiàn)代 Java 開發(fā)中,JSON(JavaScript Object Notation)作為一種輕量級(jí)的數(shù)據(jù)交換格式,廣泛應(yīng)用于前后端交互、配置文件讀取以及各類數(shù)據(jù)存儲(chǔ)場景,本文將深入剖析常用庫及對應(yīng)實(shí)現(xiàn)方式,助力您輕松駕馭 JSON 數(shù)據(jù)處理,需要的朋友可以參考下
    2025-03-03
  • Java RabbitMQ 中的消息長期不消費(fèi)會(huì)過期嗎

    Java RabbitMQ 中的消息長期不消費(fèi)會(huì)過期嗎

    RabbitMQ支持消息的過期時(shí)間,在消息發(fā)送時(shí)可以進(jìn)行指定。 RabbitMQ支持隊(duì)列的過期時(shí)間,從消息入隊(duì)列開始計(jì)算,只要超過了隊(duì)列的超時(shí)時(shí)間配置,那么消息會(huì)自動(dòng)的清除
    2021-09-09
  • spring緩存代碼詳解

    spring緩存代碼詳解

    這篇文章主要介紹了spring緩存代碼詳解,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02

最新評論

杭锦后旗| 无极县| 康平县| 海安县| 抚宁县| 乐至县| 石阡县| 三原县| 玛曲县| 镇安县| 民丰县| 祁东县| 台南市| 峨山| 大厂| 航空| 临漳县| 湖口县| 怀安县| 芮城县| 博乐市| 连江县| 左云县| 容城县| 师宗县| 雅安市| 类乌齐县| 鄯善县| 岢岚县| 常宁市| 赣榆县| 黎城县| 南丹县| 临沂市| 桂林市| 阿克| 翼城县| 马公市| 宜城市| 阜新| 福安市|