Question

In: Computer Science

How can I print the sales reports grouped by the room grades using the java code...

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

Solutions

Expert Solution

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



Related Solutions

I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
IN JAVA: I am using binary and linear search methods in java. How can I Generate...
IN JAVA: I am using binary and linear search methods in java. How can I Generate a new array with 10000 elements, and initialize the elements to random values using Math.random() and how can i sort the array using Arrays.sort(). I just need examples, no exact code is necessary. The array must be of doubles.
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1....
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1. It is compiled and runs natively 2. It is interpreted but not compiled 3. It is compiled into byte code and executed by the Java Virtual Machine 4. It is magic Please enter your answer 1 Sorry that answer is not correct. The correct answer is 3 Correct output: How is a Java source file executed? 1. It is compiled and runs natively 2....
How do I code a pyramid and a row (reference shapes below) into JAVA using user...
How do I code a pyramid and a row (reference shapes below) into JAVA using user prompts (asking for different dimensions)? I am trying to make a nested loop code and keep running into these syntax issues. Will rate for proofed code!!! Please try to leave lots of explanation. Pyramid: ---*--- --**-- -***- **** Row: ---***--- This is what I have so far: public static void main(String[] args) {        // TODO Auto-generated method stub              ...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
Code in java, A class allows students to drop their lowest of 7 quiz grades at...
Code in java, A class allows students to drop their lowest of 7 quiz grades at the end of the semester. Prompt the user for these values and add them to an array of integer type. Sort the array using the sort method from the standard Java library. Output the student’s average with the lowest score dropped
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT