今天什么新的知识都没有学,老师让我们把之间做过的项目使用 方法+数组在做一遍
首先是吃货联盟订餐系统,这是使用变量和数组做的,怎么做的呢?我乱做,就做出来了。首先呢,我使用的是数组,写起来还是很简单的。在后面的选择结构中,我使用了一个死循环,并且在每个里面都套入了循环,只有在输入数字6的时候才能跳出这个循环,并且结束这个程序。
中间呢有几个输出的判断,比如订单状态,首先我是用的int类型的数据,这个int类型的默认值是0,当它的值为0时,输出的就是已预定,当确认订单之后值从0变成1,输出的就是已完成。
import java.util.Scanner;
public class Project01 {
public static void main(String[] args) {
String[] name = new String[20];// 用户姓名
int[] state = new int[20];// 状态
double[] total = new double[20];// 总金额
String[] address = new String[20];// 地址
String[] dishMag = new String[20]; // 菜品信息
int tip = 6;
int[] additional = new int[20];// 份数
int[] time = new int[20];// 时间
int[] sequence = new int[20];// 订单序号
int[] dishSerial = { 1, 2, 3, 4 };// 菜品序号
String[] dishName = { "地三鲜", "黄焖鸡", "酸菜鱼", "佛跳墙" };// 菜品名字
double[] price = { 24, 30.5, 30.5, 80 };// 菜品单价
int[] alike = { 0, 0, 0, 0 };// 点赞
sequence[0] = 1;
name[0] = "马力";
dishMag[0] = "地三鲜";
additional[0] = 2;
address[0] = "六安市裕安区";
total[0] = price[0] * additional[0];
state[0] = 0;
time[0] = 12;
sequence[1] = 2;
name[1] = "马力";
dishMag[1] = "地三鲜";
additional[1] = 2;
address[1] = "六安市裕安区";
total[1] = price[0] * additional[1];
state[1] = 0;
time[1] = 13;
Scanner sc = new Scanner(System.in);
a: for (int i = 0;;) {
if (name[i] != null) {
i++;
continue;
}
System.out.println("欢迎使用“吃货联盟订餐系统”");
System.out.println("*************************************");
System.out.println("1.我要订餐");
System.out.println("2.查看餐袋");
System.out.println("3.签收订单");
System.out.println("4.删除订单");
System.out.println("5.我要点赞");
System.out.println("6.退出系统");
System.out.println("*************************************");
int input = sc.nextInt();
switch (input) {
case 1:
System.out.println("***我要订餐***");
System.out.println("菜品序号tt菜品信息tt单价tt");
for (int j = 0; j < dishSerial.length; j++) {
System.out.println(dishSerial[j] + "tt" + dishName[j]
+ "tt" + price[j]);
}
if (name[i] != null) {
i++;
continue;
}
sequence[i] = i + 1;// 订单序号
System.out.println("请输入您的姓名");// 用户姓名
String userName = sc.next();
name[i] = userName;
System.out.println("请输入你要点的菜品序号");
int dishInput = sc.nextInt();
switch (dishInput) {
case 1:
dishMag[i] = dishName[0];
total[i] = price[0];
break;
case 2:
dishMag[i] = dishName[1];
total[i] = price[1];
break;
case 3:
dishMag[i] = dishName[2];
total[i] = price[2];
break;
case 4:
dishMag[i] = dishName[3];
total[i] = price[3];
break;
}
System.out.println("请输入您需要几份");
int additionalInput = sc.nextInt();
additional[i] = additionalInput;
total[i] *= additional[i];
if (total[i] < 50) {
total[i] += tip;
}
for (;;) {
System.out.println("请输入送餐时间(12-20)");
int timeInput = sc.nextInt();
if (timeInput >= 12 && timeInput <= 20) {
time[i] = timeInput;
break;
} else {
System.out.println("时间输入错误,请重新输入");
i--;
continue;
}
}
System.out.println("请输入送餐地址");
String addressInput = sc.next();
address[i] = addressInput;
System.out.println("订餐完成!");
System.out.println("输入0返回主页");
int input_1 = sc.nextInt();
if (input_1 == 0) {
break;
}
continue;
case 2:
System.out.println("***查看餐袋***");
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i; j++) {
String stateStr = "已预定";
if (state[j] == 0) {
stateStr = "已预定";
} else {
stateStr = "已完成";
}
System.out.println(sequence[j] + "tt" + name[j] + "t"
+ dishMag[j] + "*" + additional[j] + "tt"
+ time[j] + "t" + address[j] + "tt" + total[j]
+ "t" + stateStr);
}
System.out.println("输入0返回主页");
int input_2 = sc.nextInt();
if (input_2 == 0) {
break;
}
continue;
case 3:
c: for (;;) {
System.out.println("***订单签收***");
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i; j++) {
String stateStr = "已预定";
if (state[j] == 0) {
stateStr = "已预定";
} else {
stateStr = "已完成";
}
System.out.println(sequence[j] + "tt" + name[j]
+ "t" + dishMag[j] + "*" + additional[j]
+ "tt" + time[j] + "t" + address[j] + "tt"
+ total[j] + "t" + stateStr);
}
System.out.println("请输入您要签收的订单序号/输入0取消");
int seqInput = sc.nextInt();// 要签收的订单序号
if (seqInput == 0) {
break c;
}
state[seqInput - 1] = 1;
}
System.out.println("输入0返回主页");
int input_3 = sc.nextInt();
if (input_3 == 0) {
break;
}
case 4:
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i; j++) {
String stateStr = "已预定";
if (state[j] == 0) {
stateStr = "已预定";
} else {
stateStr = "已完成";
}
System.out.println(sequence[j] + "tt" + name[j] + "t"
+ dishMag[j] + "*" + additional[j] + "tt"
+ time[j] + "t" + address[j] + "tt" + total[j]
+ "t" + stateStr);
}
d: for (;;) {
System.out.println("请输入您要删除的订单序号/输入0返回");
int deleteInput = sc.nextInt();
if (deleteInput == 0) {
break d;
}
if (state[deleteInput - 1] == 0) {
System.out.println("不可以删除未完成订单");
continue;
}
for (int j = deleteInput - 1; j < i; j++) {
name[j] = name[j + 1];
dishMag[j] = dishMag[j + 1];
additional[j] = additional[j + 1];
time[j] = time[j + 1];
address[j] = address[j + 1];
total[j] = total[j + 1];
state[j] = state[j + 1];
}
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i - 1; j++) {
String stateStr = "已预定";
if (state[j] == 0) {
stateStr = "已预定";
} else {
stateStr = "已完成";
}
System.out.println(sequence[j] + "tt" + name[j]
+ "t" + dishMag[j] + "*" + additional[j]
+ "tt" + time[j] + "t" + address[j] + "tt"
+ total[j] + "t" + stateStr);
}
}
continue;
case 5:
e: for (;;) {
System.out.println("菜品序号tt菜品信息tt单价tt点赞");
for (int j = 0; j < dishSerial.length; j++) {
System.out.println(dishSerial[j] + "tt" + dishName[j]
+ "tt" + price[j] + "tt" + alike[j]);
}
System.out.println("请输入您要点赞的菜品/输入0返回主页");
int alikeInput = sc.nextInt();
if (alikeInput == 0) {
break e;
}
alike[alikeInput - 1] += 1;
}
System.out.println("再按一次确认返回");
int input_5 = sc.nextInt();
if (input_5 == 0) {
break;
}
case 6:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
default:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
}
}
}
}
使用方法+数组改写这个程序
这是food类
//1.我要订餐
public class Food {
//展示菜单 菜品序号 菜品信息 单价 点赞
private int dishSerial;//菜品序号
private String dishMag; // 菜品信息
private double price;//单价
private int alike;//点赞
//订餐部分 用户姓名 订餐份数 时间 地址
private String name;//用户姓名
private int additional;//订餐份数
private int time;//送餐时间
private String address;//送餐地址
public Food() {
super();
}
public Food(int dishSerial, String dishMag, double price, int alike) {
super();
this.dishSerial = dishSerial;
this.dishMag = dishMag;
this.price = price;
this.alike = alike;
}
public int getDishSerial() {
return dishSerial;
}
public void setDishSerial(int dishSerial) {
this.dishSerial = dishSerial;
}
public String getDishMag() {
return dishMag;
}
public void setDishMag(String dishMag) {
this.dishMag = dishMag;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getAlike() {
return alike;
}
public void setAlike(int alike) {
this.alike = alike;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAdditional() {
return additional;
}
public void setAdditional(int additional) {
this.additional = additional;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return dishSerial + "tt" + dishMag
+ "tt" + price + "tt" + alike;
}
}
这是view类
//查看餐袋
//订单序号 用户姓名 餐品信息 送餐时间 送餐地址 总金额 订单状态
public class View {
private int sequence;// 订单序号
// 需要输入的信息
private String name;// 用户姓名
private int additional;// 订餐份数
private int time;// 送餐时间
private String address;// 送餐地址
//
private String dishName;// 订单菜品信息
private double total;// 总金额
private int state;// 订单状态 0/1;
public View() {
super();
}
public View(int sequence, String name, int additional, int time,
String address, String dishName, double total, int state) {
super();
this.sequence = sequence;
this.name = name;
this.additional = additional;
this.time = time;
this.address = address;
this.dishName = dishName;
this.total = total;
this.state = state;
}
public int getSequence() {
return sequence;
}
public void setSequence(int sequence) {
this.sequence = sequence;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAdditional() {
return additional;
}
public void setAdditional(int additional) {
this.additional = additional;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDishName() {
return dishName;
}
public void setDishName(String dishName) {
this.dishName = dishName;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
@Override
public String toString() {
String stateStr = "已预定";
for (int j = 0; j < 9; j++) {
if (getState() == 0) {
stateStr = "已预定";
} else {
stateStr = "已完成";
}
}
return sequence + "tt" + name + "tt" + dishName + "*" + additional
+ "tt" + time + "tt" + address + "tt" + total + "tt"
+ stateStr;
}
}
import java.util.Scanner;
public class OrderMeal {
public static void main(String[] args) {
Food[] food = new Food[4];
Food food1 = new Food(1, "黄焖鸡", 28.5, 0);
Food food2 = new Food(2, "酸菜鱼", 25.5, 0);
Food food3 = new Food(3, "佛跳墙", 55.5, 0);
Food food4 = new Food(4, "地三鲜", 12.5, 0);
food[0] = food1;
food[1] = food2;
food[2] = food3;
food[3] = food4;
// 查看餐袋原始信息
View[] view = new View[4];
View view1 = new View(1, "马力", 2, 13, "北大青鸟", food1.getDishMag(), 50, 0);
View view2 = new View(2, "马力", 2, 13, "清华青鸟", food1.getDishMag(), 50, 0);
View view3 = new View();
View view4 = new View();
view[0] = view1;
view[1] = view2;
view[2] = view3;
view[3] = view4;
a: for (int i = 0;;) {
// 判断餐袋中有多少菜品
if (view[i].getSequence() != 0) {
i++;
continue;
}
Scanner sc = new Scanner(System.in);
System.out.println("欢迎使用“吃货联盟订餐系统”");
System.out.println("*************************************");
System.out.println("1.我要订餐");
System.out.println("2.查看餐袋");
System.out.println("3.签收订单");
System.out.println("4.删除订单");
System.out.println("5.我要点赞");
System.out.println("6.退出系统");
System.out.println("*************************************");
int input = sc.nextInt();
switch (input) {
case 1:
System.out.println("菜品序号tt菜品信息tt单价tt点赞数");
for (int j = 1; j <= 4; j++) {
System.out.println(food[j - 1].toString());
}
// 向餐袋中输入数据
view[i].setSequence(i + 1);// 订单序号
System.out.println("请输入您的姓名");// 用户姓名
view[i].setName(sc.next());
System.out.println("请输入你要点的菜品序号");
int dishInput = sc.nextInt();
switch (dishInput) {
case 1:
view[i].setDishName(food[i].getDishMag());
view[i].setTotal(food[1].getPrice());
break;
case 2:
view[i].setDishName(food[i].getDishMag());
view[i].setTotal(food[1].getPrice());
break;
case 3:
view[i].setDishName(food[i].getDishMag());
view[i].setTotal(food[1].getPrice());
break;
case 4:
view[i].setDishName(food[i].getDishMag());
view[i].setTotal(food[1].getPrice());
break;
}
// 输入餐品亻分数
System.out.println("请输入您需要几份");
int additionalInput = sc.nextInt();
view[i].setAdditional(additionalInput);
view[i].setTotal((view[i].getTotal())
* (view[i].getAdditional()));
if (view[i].getTotal() < 50) {
view[i].setTotal((view[i].getTotal()) * 6);
}
// 输入送餐时间
for (;;) {
System.out.println("请输入送餐时间(12-20)");
int timeInput = sc.nextInt();
if (timeInput >= 12 && timeInput <= 20) {
view[i].setTime(timeInput);
break;
} else {
System.out.println("时间输入错误,请重新输入");
continue;
}
}
//
System.out.println("请输入送餐地址");
String addressInput = sc.next();
view[i].setAddress(addressInput);
System.out.println("订餐完成!");
System.out.println("输入0返回主页");
int input_1 = sc.nextInt();
if (input_1 == 0) {
break;
}
case 2:
System.out.println("***查看餐袋***");
System.out
.println("序号tt订餐人tt餐品信息tt送餐日期tt送餐地址tt总金额tt订单状态");
for (int j = 0; j < i; j++) {
System.out.println(view[j].toString());
}
continue;
case 3:
c: for (;;) {
System.out.println("***订单签收***");
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i; j++) {
System.out.println(view[j].toString());
}
System.out.println("请输入您要签收的订单序号/输入0取消");
int seqInput = sc.nextInt();// 要签收的订单序号
if (seqInput == 0) {
break c;
}
view[seqInput - 1].setState(1);
}
System.out.println("输入0返回主页");
int input_3 = sc.nextInt();
if (input_3 == 0) {
break;
}
case 4:
System.out
.println("序号tt订餐人tt餐品信息tt送餐日期tt送餐地址tt总金额tt订单状态");
for (int j = 0; j < i; j++) {
System.out.println(view[j].toString());
}
d: for (;;) {
System.out.println("请输入您要删除的订单序号/输入0返回");
int deleteInput = sc.nextInt();
if (deleteInput == 0) {
break d;
}
if (view[deleteInput - 1].getState() == 0) {
System.out.println("不可以删除未完成订单");
continue;
}
for (int j = deleteInput - 1; j < i; j++) {
view[j].setName(view[j + 1].getName());
view[j].setDishName(view[j + 1].getDishName());
view[j].setAdditional(view[j + 1].getAdditional());
view[j].setTime(view[j + 1].getTime());
view[j].setAddress(view[j + 1].getAddress());
view[j].setTotal(view[j + 1].getTotal());
view[j].setState(view[j + 1].getState());
}
System.out
.println("序号tt订餐人t餐品信息tt送餐日期t送餐地址ttt总金额t订单状态");
for (int j = 0; j < i - 1; j++) {
System.out.println(view[j].toString());
}
}
continue;
case 5:
e: for (;;) {
System.out.println("菜品序号tt菜品信息tt单价tt点赞数");
for (int j = 1; j <= 4; j++) {
System.out.println(food[j - 1].toString());
}
System.out.println("请输入您要点赞的菜品/输入0返回主页");
int alikeInput = sc.nextInt();
if (alikeInput == 0) {
break e;
}
food[alikeInput - 1].setAlike(food[alikeInput - 1]
.getAlike() + 1);
}
System.out.println("再按一次确认返回");
int input_5 = sc.nextInt();
if (input_5 == 0) {
break;
}
case 6:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
default:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
}// switch
}// for
}
}
我的思路是把整个框架放进一个大循环中,而且是死循环,给for一个标记,特定条件下break a;而循环的i+1是订单的序号,当第i+1个订单为空时,i++并且continue结束下面的操作直接进入接下来的循环,在订餐之后也进行i++;删除订单,是把对应的订单的所有属性赋值为默认值,之后给i赋值0;让大循环从头开始,我没有选择移动数组元素,而是让新订单属性赋值给默认值的订单中。当输入数字为6-9的数字时,结束大循环。这就是整个框架。
这个改写还是很简单的,也是使用的数组,在使用的时候要注意空指针异常,在循环里面判断的时候, 会因为声明的数组长度比较大,所以在循环的时候就会因为在这个数组的元素并没有声明而出现空指针异常(我猜的),所以需要把声明多个变量来接收数组中的元素
就像这样,数组的第一个和第二个元素是本来就有的,后面可以需要加上几个,里面可以什么东西都不写,因为有无参构造方法的存在,所以是没有错误的,并且这样也不会出现空指针异常的情况。并且这些元素可以通过数组下标和getter and setter方法来赋值或着是判断,至于输出,我选择的是重写tostring的方法,从而达到输出的目的。
第二题:图书管理系统
public class BookMal {
//图书名称 借阅状态 借出日期 借出次数
private String bookName;//图书名称
private int lendState;//借出状态 0/1
private int lendDate;//借出日期
private int lendCount;//借出次数
public BookMal() {
super();
}
public BookMal(String bookName, int lendState, int lendDate, int lendCount) {
super();
this.bookName = bookName;
this.lendState = lendState;
this.lendDate = lendDate;
this.lendCount = lendCount;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getLendState() {
return lendState;
}
public void setLendState(int lendState) {
this.lendState = lendState;
}
public int getLendDate() {
return lendDate;
}
public void setLendDate(int lendDate) {
this.lendDate = lendDate;
}
public int getLendCount() {
return lendCount;
}
public void setLendCount(int lendCount) {
this.lendCount = lendCount;
}
@Override
public String toString() {
String strLend;
if(getLendState()==0){
strLend = "可借阅";
}else {
strLend="已借出";
}
String strDate=null;
if(getLendDate()==0){
strDate = " ";
}else{
strDate=getLendDate()+"日";
}
return "t" +strLend+"t" + bookName
+ "tt" + strDate + "t" + lendCount+"次";
}
}
import java.util.Scanner;
public class BookSystem {
public static void main(String[] args) {
BookMal[] bookmal = new BookMal[6];
BookMal bookmal1 = new BookMal("马力自传", 0, 0, 0);
BookMal bookmal2 = new BookMal("圆圈正义", 1, 2, 1002);
BookMal bookmal3 = new BookMal("三国演义", 0, 0, 15);
BookMal bookmal4 = new BookMal();
BookMal bookmal5 = new BookMal();
BookMal bookmal6 = new BookMal();
bookmal[0] = bookmal1;
bookmal[1] = bookmal2;
bookmal[2] = bookmal3;
bookmal[3] = bookmal4;
bookmal[4] = bookmal5;
bookmal[5] = bookmal6;
Scanner sc = new Scanner(System.in);
a:for (int i = 0;;) {
if (bookmal[i].getBookName() != null && i < 5) {
i++;
continue;
}
System.out.println("欢迎使用迷你图书管理器");
System.out.println("-------------------------");
System.out.println("1.新增图书");
System.out.println("2.查看图书");
System.out.println("3.删除图书");
System.out.println("4.借出图书");
System.out.println("5.归还图书");
System.out.println("6.退出图书");
System.out.println("-------------------------");
System.out.println("请选择:");
int choose = sc.nextInt();
switch (choose) {
case 1:
System.out.println("-->新增图书n");
System.out.println("请输入图书名称:");
String BookName = sc.next();
// 判断添加书是否成功
boolean flag2 = false;
// 循环查找图书馆里的可存放书的地方
for (int j = i; j <7; j++) {
// 判断某个位置是否能存放书
if (bookmal[j].getBookName() == null) {
bookmal[j].setBookName(BookName);
System.out.println("新增《" + BookName + "》成功!");
flag2 = true;
break;
}
}
if (!flag2) {
System.out.println("抱歉,新增《" + BookName + "》失败!货架已满!");
}
System.out.println("*****************************************");
continue;
case 2:
System.out.println("---------查看图书---------");
System.out.println("序号t状态t名称tt借出日期t借出次数");
for (int j = 0; j < i; j++) {
System.out.print(j + 1);
System.out.println(bookmal[j].toString());
}
continue;
case 3:
System.out.println("---------删除图书---------");
System.out.println("请输入你要删除的图书名称");
String delete = sc.next();
boolean flag3 = false;
int index = -1; // 记录要删除图书的位置
for (int j = 0; j < i+1; j++) {
// 删除的图书存在、状态处于可借阅状态
if (bookmal[j].getBookName() != null && delete.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 0) {
flag3 = true;
index = j;
System.out.println("图书删除成功!");
break;
} else if (bookmal[j].getBookName() != null && delete.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 1) {
flag3 = true;
System.out.println("该图书已被借出,目前无法删除!");
break;
}
}
// 根据记录下来的删除图书的位置进行删除工作
if (index != -1) {
for (int j = index; j < i+1; j++) {
if (j != i+1 - 1) {
bookmal[j].setBookName(bookmal[j+1].getBookName());
bookmal[j].setLendState(bookmal[j+1].getLendState());
bookmal[j].setLendDate(bookmal[j+1].getLendDate());
}
bookmal[i].setBookName(null);
i-=1;
}
}
if (!flag3) {
System.out.println("没有找到匹配信息!");
}
System.out.println("*****************************************");
break;
case 4:
System.out.println("-->借出图书n");
System.out.print("请输入图书名称:");
String want = sc.next(); // 要借出的图书名称
for (int j = 0; j < i+1; j++) {
if (bookmal[j].getBookName() == null) { // 无匹配
System.out.println("没有找到匹配信息!");
break;
} else if (want.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 0) { // 找到匹配可借
bookmal[j].setLendState(1); // 将此图书置于借出状态
System.out.print("请输入借出日期:");
bookmal[j].setLendDate(sc.nextInt());
while (bookmal[j].getLendDate() < 1 || bookmal[j].getLendDate() > 31) { // 当输入借出的日期不满足1-31时
System.out.println("必须输入大于等于1且小于等于31的数字,请重新输入:");
bookmal[j].setLendDate(sc.nextInt());
}
System.out.println("借出《" + want + "》成功!");
bookmal[j].setLendCount(bookmal[j].getLendCount()+1);
break;
} else if (want.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 1) { // 找到匹配已被借出
System.out.println("《" + want + "》已被借出!");
break;
}
}
System.out.println("*****************************************");
break;
case 5:
// 归还图书
System.out.println("-->归还图书n");
int charge = 0; // 租金
System.out.print("请输入归还图书名称:");
want = sc.next();
for (int j = 0; j < i; j++) {
if (bookmal[j].getBookName() == null) { // 无匹配
System.out.println("没有找到匹配信息!");
break;
} else if (want.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 1) {// 找到匹配
bookmal[j].setLendState(0); // 将借阅状态修改为可借阅
System.out.print("请输入归还日期:");
int redate = sc.nextInt();
while (redate < bookmal[j].getLendDate() || redate > 31) { // 归还日期不能小于借出日期,也不能大于31
if (redate < bookmal[j].getLendDate()) {
System.out.println("归还日期不能小于借出日期,请重新输入:");
} else {
System.out.println("一个月只有31天,请重新输入:");
}
redate = sc.nextInt();
}
charge = redate - bookmal[j].getLendDate();
System.out.println("n归还《" + want + "》成功!");
System.out.println("借出日期为:" + bookmal[j].getLendDate() + "日");
System.out.println("归还日期为:" + redate + "日");
System.out.println("应付租金(元):" + charge);
bookmal[j].setLendDate(0);
break;
} else if (want.equals(bookmal[j].getBookName()) && bookmal[j].getLendState() == 0) {// 找到匹配但没有借出
System.out.println("该图书没有被借出!无法进行归还操作。");
break;
}
}
System.out.println("*****************************************");
break;
case 6:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
default:
System.out.println("*******谢谢使用,欢迎下次光临*********");
break a;
}// switch结束
}
}
}
这个小项目是根据老师的源码改的,老师发的是用数组和变量写的,让我们改写为对象和方法,主要的代码没有怎么改动,就是吧几个数组改成了一个对象数组,调用时,改为调用对象属性。然后把一些代码存入方法中,然后在业务类中调用



