In: Computer Science
How can I print the sales reports grouped by the room grades using the java code below:
-----------------------------------------------------------------------------------------------------------------------------------
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;
   }
}
Answer.
To print the sales reports grouped by the room grades, we can add the fllowing function in our program-
we can use three static variable to keep tracking the count of booked rooms. Every time when a room is booked, corresponding varibale will be increased by 1.
public class Book {
   String bookno;
   int ff;
   Customer cust;
static int standardCount, deluxCount, suiteCount;
// here we are declaring the global
variable to track booked // rooms
  standardCount=deluxCount=suiteCount=0;
   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);
standardCount++; // for standard room is
booked
      
      
   }
  
   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);
       }
deluxCount++; // delux room is booked
   }
  
   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);
          
           }
          
suiteCount++; // suite room is booked
           }
   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;
   }
// adding a new function to print the sales report
void salesReport(int type)
{
int totalSale=0;
switch(type)
{
case 1:
Fare f=new Fare();
totalSale=(totalSale * standardCount);
System.out.println("total sales for Standard type rooms are:
"+totalSale);
  case 2:
Fare f=new Fare();
totalSale=(totalSale * deluxCount);
System.out.println("total sales for Delux type rooms are:
"+totalSale);
case 3:
Fare f=new Fare();
totalSale=(totalSale * suiteCount);
System.out.println("total sales for Suite type rooms are:
"+totalSale);
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
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;
   }
}