Question

In: Computer Science

How can I make a method to check out a customer given their name and booking...

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;
   }
  
}

Solutions

Expert Solution

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");

}


Related Solutions

How can I write a separate java class to change a given name or a given...
How can I write a separate java class to change a given name or a given email of a user that was already saved (keep in mind that there may be numerous names and emails). Note: It should change the name or email that is saved in the txt file. Here is my code so far: User class public class User { private String fName; private String lName; private String UserEmail; public User(String firstName, String lastName, String email) { this.fName...
(JAVA) I was wondering if anyone can check if I am implementing this method correctly based...
(JAVA) I was wondering if anyone can check if I am implementing this method correctly based on the instructions? Here are the instructions: buildShape(String input) In the buildShape() method, you will parse the provided input to determine whether to create a CircleShape or SquareShape. Before you create the shape, you need to determine it's size, location and color. Use TestableRandom to randomly generate an int size ranging from 100-200. Randomly generate an x and y index for its location. X...
Please check it out within 30 minutes. Please provide explanation or working so I can check...
Please check it out within 30 minutes. Please provide explanation or working so I can check with my answer. Question: In a study of the system, Cl2(g) + Br2(g) 2BrCl(g), several different reaction mixtures were prepared, placed in a 15.00 × 10–3 m3 container, and allowed to reach equilibrium at 350 K. Despite having different starting compositions, three of the four mixtures had an identical composition at equilibrium. Which one of the systems has a different equilibrium composition than the...
Given a string like the following one in Java "123+45+678", how can I pull out the...
Given a string like the following one in Java "123+45+678", how can I pull out the characters that make up the separate integers and add them together. I'm not allowed to use parseInt(). So for this one I would need to add 123 + 45 + 678 to get the total(846)
how can i define what the word "customer" means in the context of this chapter and...
how can i define what the word "customer" means in the context of this chapter and discuss the two different kinds of customers that every business has,in 300 words Customer Service, 6th Edition ISBN: 9780133112061 By: Paul R. Timm
Sometimes there can be errors while making change for a customer or recording a check incorrectly....
Sometimes there can be errors while making change for a customer or recording a check incorrectly. What are some of the controls we can put over cash that would help prevent errors?
Sometimes there can be errors while making change for a customer or recording a check incorrectly....
Sometimes there can be errors while making change for a customer or recording a check incorrectly. What are some of the controls we can put over cash that would help prevent errors?
I figured out the weighted average method, but can anyone show me the FIFO and LIFO...
I figured out the weighted average method, but can anyone show me the FIFO and LIFO treatment of this problem???? Timekeeper Inc. manufactures clocks on a highly automated assembly line. Its costing system uses two cost categories, direct materials and conversion costs. Each product must pass through the Assembly Department and the Testing Department. Direct materials are added at the beginning of the production process. Conversion costs are allocated evenly throughout production. Timekeeper Inc. uses weighted-average costing. Data for the...
Question 1 i. Explain briefly with an example how customer complaints can be a source of...
Question 1 i. Explain briefly with an example how customer complaints can be a source of new product idea ii. Using a phone’s battery to illustrate, explain briefly how the mean time between failures (MTBF) can be used as a measure of a product’s reliability
Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT