学习Java的第一个小系统(数组的调用和方法的使用)
package com.face;import java.util.Scanner;
public class Practis {static int floor = 9;static int room = 9;static String[][] rooms = new String[floor][room];static String[][] names = new String[floor][room];static Scanner key = new Scanner(System.in);public static void main(String[] args) {for (int i = 0; i < rooms.length; i++) {for (int j = 0; j < names.length; j++) {rooms[i][j] = "empty";}}boolean flag = true;while (flag) {help();String con = key.next();if (con.equals("search")) {searchRoom();} else if (con.equals("in")) {inTheRoom();} else if (con.equals("out")) {outTheRoom();} else if (con.equals("exit")) {System.out.println("官人请走好,欢迎下次体验呐~~");break;}}}public static void help() {System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~欢迎来到迷人哥的小黑屋大酒店~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~~请选择你要查询的信息~~~~~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~输入 search 查询房间是否有美女~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~~~~~输入 in 预定房间~~~~~~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~~~~~~输入 out 退房~~~~~~~~~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~输入 exit 退出当前操作系统~~~~~~~~~~~~~~~~");System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");System.out.println("请输入指令:");}public static void searchRoom() {for (int i = 0; i < rooms.length; i++) {for (int j = 0; j < rooms[i].length; j++) {System.out.print((i + 1) * 1000 + (j + 1) + "\t");}System.out.println();for (int j = 0; j < rooms[i].length; j++) {System.out.print(rooms[i][j] + "\t");}System.out.println();System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");}}public static void inTheRoom() {System.out.println("请输入你要预定的小黑屋号码");int num = key.nextInt();int floor= num / 1000 - 1;int room = num % 1000-1;if(rooms[floor][room].equals("empty")) {System.out.println("此房间没有美女,赶快报上名来:");String name = key.next();rooms[floor][room]="****";names[floor][room]=name;System.out.println("您已成功入住小黑屋,请保管好您的包包单单~~");}else {System.out.println("想偷看美女洗澡吗,"+num+"号小黑屋已经有人入住了,请重新预定");}}public static void outTheRoom() {System.out.println("大官人,退房请输入房间号哟");int num = key.nextInt();int floor= num / 1000 - 1;int room = num % 1000-1;if(rooms[floor][room].equals("empty")) {System.out.println("此号房间是人家美女的,你想帮人家结账退房吗?");}else {System.out.println("大官人,留个名呗,日后好联系呀");String name = key.next();System.out.println(names[floor][room]);if(names[floor][room].equals(name)) {rooms[floor][room]="empty";names[floor][room]="null";System.out.println(num+"号小黑屋已回归美女的名下,欢迎下次光临!");}else {System.out.println("大款啊,别人还住着呢,你要给人家续房钱也是可以的!");}}}}