Java练习——图书借阅系统
自己一直在自学Java基础,期望向JavaWeb方向发展。自学了好长时间,每次基本上都不会怎么记录,昨天看了GitChat的推送,觉着应当把自己每天的学习记录下来,这样可以做到监督的作用。 今天这个是一个Java小练习,一个图书借阅系统,需要实现的功能有:
Book.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
存在问题
在BorrowBooks.java这个Class中,下面这段代码本想实现判断用户输入的金额是否和应付金额一致,不一致时给出不同的回复,但是自己试了好多种方法,都没有实现,还是自己懂得太少:
while (bookPrice != x.nextInt()) { if (bookPrice > x.nextInt()) { int priceSpread = bookPrice - x.nextInt();//定义差价 System.out.println("------------" + " " + "您已付款" + x.nextInt() + "元,还需支付" + priceSpread + "元"); } if (bookPrice <x.nextInt()) { int priceSpread = x.nextInt()-bookPrice ;//定义差价 System.out.println("------------" + " " + "您已付款" + x.nextInt() + "元,找您" + priceSpread + "元"); } }
上一篇:
IDEA上Java项目控制台中文乱码