In: Computer Science
How can I make a method to check out a customer given their name and booking number in Java.
I have provided the Book class as well as the customer class. I have done the method to add a customer into the array however im failng to implement a method that checks out the customer.
If you need more classes associated with the system please let me know ASAP and I will provide them,
-----------------------------------------------------------------------------------------------------------------------------------
public class Book{
String bookno;
int ff;
Customer cust;
public String getBookingNumber()
{
return bookno;
}
public void BookNew(Customer c,Standard stand,Deluxe
dx,Suite suite,int iStandard,int flag1,int iDelux,int flag2,int
isdx,int flag3)
{
cust=c;
Fare f=new Fare();
int no,i;
if(c.type==1)
{
if(flag1==0)
{
System.out.println("No
Standard Rooms Available");
Scanner in5=new
Scanner(System.in);
System.out.println("Book any
other room? Deluxe(2) or Suite(3) ");
int g=in5.nextInt();
if(g==2)
BookDeluxe(c,dx,g,iDelux,c.ld,c.d);
if(g==3)
BookSuite(c,suite,g,isdx,c.ld,c.d);
}
if(flag1==1)
BookStandard(c,
stand,c.type,iStandard,c.ld,c.d);
}
if(c.type==2)
{
if(flag2==0)
{
System.out.println("No Deluxe
Room Available");
Scanner in6=new
Scanner(System.in);
System.out.println("Book any
other room? Standard(1) or Suite(3) ");
int g=in6.nextInt();
if(g==2)
BookStandard(c,stand,g,iStandard,c.ld,c.d);
if(g==3)
BookSuite(c,suite,g,isdx,c.ld,c.d);
}
if(flag2==1)
BookDeluxe(c,dx,c.type,iDelux,c.ld,c.d);
}
if(c.type==3)
{
if(flag3==0)
{
System.out.println("No Suite Room
Available");
Scanner in5=new Scanner(System.in);
System.out.println("Book any other room?
Deluxe(2) or Standard(3) ");
int g=in5.nextInt();
if(g==2)
BookDeluxe(c,dx,g,iDelux,c.ld,c.d);
if(g==1)
BookStandard(c,stand, g,
iStandard, c.ld, c.d);
}
if(flag3==1)
BookSuite(c, suite, c.type,
isdx, c.ld, c.d);
}
}
public void BookStandard(Customer c,Standard ly,int
type,int iStandard,int ld,int d)
{
Fare f=new Fare();
ly.statuschange();
System.out.println("Single Standard
Room is booked");
ff=
f.farecalculator(d,ly.rate,ld);
iStandard++;
bookno = "STA0" + iStandard;
BookDisplay(ff,c.name,bookno);
}
public void BookDeluxe(Customer c,Deluxe dx,int
type,int iDelux,int ld,int d)
{
dx.statuschange();
Fare f=new Fare();
if(ld==1)
{
System.out.println("Single Deluxe Room is booked");
ff=
f.farecalculator(d,dx.rate,ld);
bookno=iDelux+"dx1";
BookDisplay(ff,c.name, bookno);
}
if(ld==2)
{
System.out.println("Double Deluxe Room is booked");
ff=
f.farecalculator(d,dx.rate,ld);
bookno=iDelux+"dx2";
BookDisplay(ff,c.name,bookno);
}
}
public void BookSuite(Customer c,Suite sdx,int
type,int isdx,int ld,int d)
{
Fare f=new Fare();
sdx.statuschange();
if(ld==1)
{
System.out.println("Single Suite Room is booked");
ff=
f.farecalculator(d,sdx.rate,ld);
bookno=isdx+"sdx1";
BookDisplay(ff,c.name,bookno);
}
if(ld==2)
{
System.out.println("Double Suite Room is
booked");
ff=
f.farecalculator(d,sdx.rate,ld);
bookno=isdx+"sdx2";
BookDisplay(ff,c.name,bookno);
}
}
public void BookDisplay(int ff,String name, String
b)
{
System.out.println();
System.out.println("Booking number
"+bookno);
System.out.println("Customer number
"+ cust.no);
System.out.println("Customer Name:
" + name);
System.out.println("Fare is: "+
ff);
System.out.println();
}
public int getFare()
{
return ff;
}
public String getName()
{
return cust.name;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Customer {
int no;
String name = " ";
String bookingno;
int nod, type, ld, d;
boolean status;
Customer()
{
no =- 1;
name = null;
bookingno = null;
nod=type=ld=d =-1;
status = false;
}
public void setInitialDetails(int c)
{
no=c;
Scanner in = new
Scanner(System.in);
System.out.print("Enter name:
");
name = in.nextLine();
System.out.println("Enter room
type:: (1) for Standard | (2) for Deluxe | (3) for Suite
::");
type = in.nextInt();
// System.out.print("Enter occupancy: (1/2): ");
ld = 1;
d = 1;
}
public void setBookingNo(String b)
{
bookingno = b;
}
}
Hey, as far as I have understood , you need to check whether their is a customer with the particular name and booking number. So, what you can do is you can store all the customer objects which are made in an ArrayList of type customers, and when you need to find a customer you can simply just traverse that list and compare if the name and the booking number of a customer matches, then you have the customer, else not.
Do tell me in comments if you have any doubt. :)
Here, below, I have provided the code for the method name checkCustomer().
checkCustomer(int bookingNo, String name){
//Assuming that evertime you create a new customer, you are storing that in the arrayList (this is a global arrayList i.e it can be accessed in any function).
for(int i=0;i<customers.size();i++){
Customer c=customers.get(i);
if(c.name==name && c.bookingNo==bookingNo){
System.out.println("Customer is present");
return;
}
}
System.out.println("Customer is not present");
}