我正在尝试将顺序搜索功能连接到菜单,以便它接受用户输入并在和中搜索 tpapartA()
数组apartB()
。还有我们如何将报表函数连接到 FunctionsapartA()
和apartB()
.
package jachi;
import java.util.Scanner;
public class Jachi {
public static void main(String[] args) {
menu();
}
public static void menu(){
int j,k,choice;
System.out.println("Menu");
System.out.println("1. Register");
System.out.println("2. Update");
System.out.println("3. Report");
System.out.println("4. Search");
Scanner scan=new Scanner(System.in);
choice=scan.nextInt();
switch(choice) {
case 1:
System.out.println("Select Apartment type");
System.out.println("1. Apartment A");
System.out.println("2. Apartment B.");
choice=scan.nextInt();
if (choice==1)
{
apartA();
}
else if (choice==2)
{
apartB();
}
break;
case 2:
System.out.println("Update the student information");
break;
case 3:
System.out.println("Rooms Available");
report();
break;
case 4:
System.out.print("Search for student. Please enter the TP number:");
break;
default:
System.out.println("Incorrect input");
}
}
public static int apartA()
{
final int a = 9;
//Normal Rooms Arrays
int[] tp;
tp = new int[a];
String[] stname;
stname = new String[a];
String[] mob;
mob = new String[a];
int ttt = get.nextInt();
int test = sequencialSearch(ttt);
Scanner get = new Scanner(System.in);
//Data Entry
for (int index = 0; index < a; index++)
{
System.out.println("Student Information");
System.out.println("Enter the student TP NUMBER:");
tp[index] = get.nextInt();
System.out.println("Enter the STUDENT NAME:");
stname[index] = get.nextLine();
System.out.println("Enter the MOBILE NUMBER:");
mob[index] = get.nextLine();
rent();
}
System.out.println("Rooms Full");
/**Report Data, Test for Data presence
*for(a=0;a<=2;a++)
*{
*System.out.println("TP NUMBER: "+tp[a]+"\t NAME: "+stname[a]+"\t MOBILE: "+mob[a]);
*}*/
return a;
}
public static void apartB(){
System.out.println("Select Room Type");
System.out.println("\t1. Normal Room");
System.out.println("\t2. Master Room");
int choice;
final int j = 6;
final int k = 3;
Scanner get = new Scanner(System.in);
choice = get.nextInt();
Scanner get1 = new Scanner(System.in);
if (choice==1)
{
System.out.println("1. Normal Bedroom");
// Normal Bedroom Arrays
String[] tp;
tp = new String[j];
String[] stname;
stname = new String[j];
String[] mob;
mob = new String[j];
//Data Entry
for (int index = 0; index < j; index++)
{
System.out.println("Student Information");
System.out.println("Enter the student TP NUMBER:");
tp[index] = get1.nextLine();
System.out.println("Enter the STUDENT NAME:");
stname[index] = get1.nextLine();
System.out.println("Enter the MOBILE NUMBER:");
mob[index] = get1.nextLine();
rent();
}
if(j<=5)
{
menu();
}
else
{
System.out.println("All Houses Full");
}
}
else if (choice==2)
{
System.out.println("Master bedroon");
//Master Bedroom Arrays
String[] mastertp;
mastertp = new String[k];
String[] mastername;
mastername = new String[k];
String[] mastermob;
mastermob = new String[k];
//Data Entry
for (int index = 0; index < k; index++)
{
System.out.println("Student Information");
System.out.println("Enter the student TP NUMBER:");
mastertp[index] = get1.nextLine();
System.out.println("Enter the STUDENT NAME:");
mastername[index] = get1.nextLine();
System.out.println("Enter the MOBILE NUMBER:");
mastermob[index] = get1.nextLine();
int x,y,z,pay;
x=100;
pay=300;
y=3*pay;
z=x+y;
System.out.println("Charges to be Paid");
System.out.println("Charges Amount");
System.out.println("Utilities charge: rm100");
System.out.println("Three month rental: rm"+y);
System.out.println("Total: rm"+z);
menu();
}
System.out.println("Full House Man");
}
}
public static void rent(){
int x,y,z,pay;
x=100;
pay=300;
y=3*pay;
z=x+y;
System.out.println("Charges to be Paid");
System.out.println("Charges Amount");
System.out.println("Utilities charge: rm100");
System.out.println("Three month rental: rm"+y);
System.out.println("Total: rm"+z);
menu();
}
public static void report(){
int x,y,z;
x=0;
y=x+1;
z=6-y;
System.out.println("Rooms occupied; "+y);
System.out.println("Rooms available; "+z);
menu();
}
public static int sequencialSearch(int Tnumbr){
int index,
element;
boolean found;
index = 0;
element = 0;
found = false;
while(!found && index == Tnumbr){
/* if(array[index] == 9{
* found = true;
* element = index;
* }
* index++;
*/
}
return element;
}
}