图书馆购书系统

import java.util.Scanner;


public class goushuxitong {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int i;
int cipher = 123;
String pname = "guanliyuan";
String[] name = new String[100]; //图书名称数组
name[0] = "Java编程思想"; //初始录入图书名称
name[1] = "Spring入门";
double[] price = new double[100]; //图书价钱数组
price[0] = 79.0; //初始录入图书价钱
price[1] = 23.0;
int[] number = new int[100]; //图书库存数组
number[0] = 5; //初始录入图书库困
number[1] = 1;
int choice;
System.out.println("*************************************"); //选择登入身份
System.out.println("请选择您的身份:1.顾客 2.管理员");
choice = input.nextInt();
if(choice==1){ //顾客
System.out.println("*************************************");
System.out.print("欢迎使用图书销售系统~(*^__^*)");
System.out.println("请选择您需要的服务:1.购买图书 2.退出");
choice = input.nextInt();
if(choice==1){ //购买图书
System.out.println("*************************************");
for(i = 0;iif(name[i]==null){
break;
}
else{
System.out.println((i+1)+" "+name[i]+" "+price[i]+"元");
}
}
int j = 0;
while(j >= 0){ //是否继续购买循环
System.out.println("请输入您要购买的图书的编号:");
int num1 = input.nextInt();
System.out.println("请输入您要购买的数量:");
int num2 = input.nextInt();
System.out.println("*************************************");
if(num2 <= number[num1-1]){ //可购买条件
System.out.println("购买成功,金额共计"+(price[num1-1]*num2)+"元");
number[num1-1]--;
System.out.println("是否继续购买?1. yes 2. no");
choice = input.nextInt();
if(choice == 1){ //继续购买 j+1 while循环
j++;
}
else{ //退出购买系统
System.out.println("慢走~ 欢迎您下次光临~ ( ^_^ )/~~");
System.exit(0);
}

}
else{ //未到达购买条件
System.out.println("对不起,您所需要购买的数量大于库存,无法出售!!╯﹏╰ ");
System.out.println(name[num1-1]+"还剩"+number[num1-1]+"本");
System.out.println("是否继续购买?1. yes 2. no"); //继续购买 j+1 while循环
choice = input.nextInt();
if(choice == 1){
j++;
}
else{
System.exit(0);
}
}
}
}
else{ //退出购买系统
System.out.println("*************************************");
System.out.print("谢谢使用~ ( ^_^ )/~~拜拜~");
System.exit(0);
}
}
else{ //下面的你不用看 是我写多了的 管理员修改图书信息的系统
System.out.println("*************************************");
System.out.print("请输入用户名:");
String pname1 = input.next();
System.out.print("请输入用户名密码:");
int cipher1 = input.nextInt();
int k = 0;
while(k >= 0){
if(pname.equals(pname1)&&cipher==cipher1){
System.out.println("选择您所需要的操作: 1. 修改书目 2.修改价格 3.修改库存");
choice = input.nextInt();
if(choice == 1){
System.out.println("请输入图书的名称,以“#”结束");
for(i = 2;i < name.length;i++){
name[i] = input.next();
if(name[i].equals("#")){
break;
}
}
}
for(i = 0;iif(name[i]==null){
break;
}
else{
System.out.println((i+1)+" "+name[i]);
}
}
if(choice == 2){
System.out.println("请输入图书的序号:");
i = input.nextInt();
System.out.println("请输入该图书的价格:");
price[i] = input.nextDouble();
}
if(i == 3){
System.out.println("请输入图书的序号:");
i = input.nextInt();
System.out.println("请输入该图书的库存:");
number[i] = input.nextInt();
}
}
else{
System.out.println("用户名/密码错误,是否重新输入? 1. yes 2. no");
choice = input.nextInt();
if(choice == 1){
k++;

}
else{
System.exit(0);
}
}
}
}
}
}


相关文档
最新文档