Java의 기초를 스스로 배워왔고, JavaWeb 방향으로 발전해 나가고 싶습니다. 오랫동안 독학을 했는데 기본적으로 매번 기록하는 방법을 모르겠습니다. 어제 GitChat 푸시를 보고 나서 매일 학습 내용을 기록하여 감독 역할을 해야겠다는 생각이 들었습니다. .
오늘은 도서 대출 시스템인 작은 Java 연습입니다.
사용자의 도서 대출 필요 여부 판단
사용자가 도서 대출을 선택하면 도서 목록이 표시됩니다
-
도서 목록에는 도서 일련번호, 도서 제목, 대출 가격, 저자가 포함됩니다.
대출할 도서 수를 선택하고 해당 도서를 선택합니다. 및 빌릴 수 있는 일수
#🎜🎜 #- 사용자가 지불해야 하는 금액 계산
package com.imooc;/** * 图书类 包含图书序号 名称 价格 * */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("~~~~~~~欢迎使用图书借阅系统~~~~~~~~ "); System.out.println("您是否要借书:1.是 >> 点击其他键退出"); BorrowBooks test = new BorrowBooks(); while (test.test1()) { System.out.println(">>>您可选择图书及其价目表:"); System.out.println("-------------------------------------------"); Book[] books = { new Book(0, "红楼梦", 12, "曹雪芹"), new Book(1, "西游记", 12, "吴承恩"), new Book(2, "汉乡", 12, "孑与2"), new Book(3, "大魏宫廷", 12, "贱宗首席"), new Book(4, "三国演义", 12, "罗贯中"), new Book(5, "水浒传", 12, "施耐庵") }; System.out.println("序号" + " " + "\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("-->请输入你要借书的数量:"); 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) + "本书的序号:"); 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("您输入的图书序号不正确"); i = i - 1; BookNum = BookNum; } } System.out.println("->请输入借阅的天数:"); Scanner g = new Scanner(System.in); int bookDay = g.nextInt(); bookPrice = bookPrice * bookDay; System.out.println("------------借阅选书完成------------" + "\n" + "下面开始统计数据.........."); 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();//定义差价 while (bookPrice != x.nextInt()) System.out.println("------------" + "\n" + "输入错误,请重新输入金额!"); /* while (bookPrice != x.nextInt()) { if (bookPrice > x.nextInt()) { int priceSpread = bookPrice - x.nextInt();//定义差价 System.out.println("------------" + "\n" + "您已付款" + x.nextInt() + "元,还需支付" + priceSpread + "元"); } if (bookPrice <x.nextInt()) { int priceSpread = x.nextInt()-bookPrice ;//定义差价 System.out.println("------------" + "\n" + "您已付款" + x.nextInt() + "元,找您" + priceSpread + "元"); } */ System.out.println("------------"); System.out.println(" 交易成功!"); System.out.println(); System.out.println("------------感谢您的使用--------------"); System.out.println("………………继续借书请按1,退出请按其他键………………"); } else { System.out.println("您输入的借书数量为“0”,自动为您退出系统"); System.exit(0); } } } private static Object bookPrice(int nextInt) { // TODO Auto-generated method stub return null; } // 捕获输入参数不正确异常 public boolean test1() { try { Scanner z = new Scanner(System.in); if (z.nextInt() == 1) { return true; } else { return false; } } catch (Exception e1) { return false; } } }#🎜🎜 #렌더링 실행
다음이 있습니다. 문제
Class BorrowBooks.java에서 다음 코드는 사용자가 입력한 금액이 지불 금액과 일치하는지 판단하고, 일치하지 않는 경우 다른 응답을 주고 싶었지만 시도해 보았습니다. 많은 방법이 있지만 그 중 어느 것도 구현되지 않았거나 제가 아는 바가 너무 적습니다:
while (bookPrice != x.nextInt()) { if (bookPrice > x.nextInt()) { int priceSpread = bookPrice - x.nextInt();//定义差价 System.out.println("------------" + "\n" + "您已付款" + x.nextInt() + "元,还需支付" + priceSpread + "元"); } if (bookPrice <x.nextInt()) { int priceSpread = x.nextInt()-bookPrice ;//定义差价 System.out.println("------------" + "\n" + "您已付款" + x.nextInt() + "元,找您" + priceSpread + "元"); } }
관련 기사:
책을 시뮬레이션하는 단계에 대한 자세한 설명 Java 예외 메커니즘을 사용하는 대출 시스템 도서관 시스템에 초보자, 질문하기위 내용은 자바 실무 공유 - 도서 대출 시스템의 운영 효과와 기존 문제점의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
