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.
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
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){...
Write a java code snippet that allows a teacher to track her students’ grades. Use a...
Write a java code snippet that allows a teacher to track her students’ grades. Use a loop to prompt the user for each student’s name and the grade they received. Add these values to two separate parallel ArrayLists. Use a sentinel to stop. Output a table listing each of the student’s names in one column and their associated grades in the second column.
Please I can get a flowchart and a pseudocode for this java code. Thank you //import...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT