酒店开房系统,java写的哦,不难!大家不要笑话我笨
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了酒店开房系统,java写的哦,不难!大家不要笑话我笨相关的知识,希望对你有一定的参考价值。
package com;
import java.util.Scanner;
/**
* Created by Frankie on 2016/3/28.
*/
public class HotelSys {
public static int h = 5;
public static int w = 15;
public static String[][] rooms = new String[h][w];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.print("请输入操作(1、开房,2、退房 ,3、查看,0、系统退出):");
int k = sc.nextInt();
switch (k) {
case 1:
System.out.print("请输入房间号:");
int rn = sc.nextInt();
System.out.print("请输入姓名:");
String nn = sc.next();
in(rn,nn);
break;
case 2:
System.out.print("请输入房间号:");
int on = sc.nextInt();
out(on);
break;
case 3:
search();
break;
default:
System.out.println("系统退出");
System.exit(0);
break;
}
}
}
public static void in(int roomnum,String name) {
int r = roomnum/100 -1;
int c = roomnum%100 -1;
//System.out.println(r);
//System.out.println(c);
if(r<0 || r>=h || c<0 || c>=w){
System.out.println("该房间号不存在,开房失败");
}else if(rooms[r][c]==null){
System.out.println("恭喜,开房成功,请牢记你的房间号:"+roomnum);
rooms[r][c]=name;
}else{
System.out.println("该房间号有人,开房失败");
}
}
public static void out(int roomnum) {
int r = roomnum/100 -1;
int c = roomnum%100 -1;
if(r<0 || r>=h || c<0 || c>=w){
System.out.println("该房间号不存在,退房失败");
}else if(rooms[r][c]==null){
System.out.println("该房间没有人入住,退房失败");
}else{
rooms[r][c] = null;
System.out.println("退出成功,房间号:"+roomnum+",欢迎下次光临.");
}
}
public static void search() {
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j <rooms[i].length ; j++) {
String info = rooms[i][j]==null ? " " : "有人";
int nn = (i+1)*100+j+1;
//System.out.print("\t"+"["+i+"]["+j+"]="+info);
System.out.print("\t房间号:"+nn+"="+info);
//System.err.print("\t"+"["+i+"]["+j+"]="+rooms[i][j]);
}
System.out.println();
}
}
}
以上是关于酒店开房系统,java写的哦,不难!大家不要笑话我笨的主要内容,如果未能解决你的问题,请参考以下文章