Assignment 2 - import java

By Jay Carroll,2014-04-24 13:52
53 views 0
Assignment 2 - import java

After answering this assignment you will be able to:

    (a) Distinguish between instance variables and class variables

    (b) Distinguish between instance methods and class methods

    (c) Know how to call class methods and how to call instance methods

    (d) Format numbers to reflect dollar currency

    (e) Format current date

    (f) Understand the concept of overloading

The ABC Cheap Lodging, Inc wants a computerized printed receipt for each of its customer’s transaction,

    and a summary report for all its transactions.

Each input consists of the room number, the number of nights, and the number of customers. A customer

    may request additional night stay after the initial stay has expired. Also, a customer may have other

    members joining at a later time than at the initial registration.

When registering, if customer a simply request a room it is assumed that it’s only one person staying one

    night. On the other hand the customer may specify the length of stay. In this case it is assumed that there

    is only one customer for that many nights; or the customer may specify the length of stay and the number

    of guests. See rate table below for the various charges.

    (a) Use the class Hotel given in the notes as the basis for this assignment. You will have to add the necessary codes (variables and methods) to add more nights and more customers. Refer to the test

    class to see what the names of the methods are.

    (b) Use the test class TestHotel and complete the definition for the overloaded method display that

    prints the summary report. You determine and define the variables and methods necessary in the

    Hotel class that will be used for the summary report.

Note: You must uncomment the statements for the program to compile

//import java.util.Date;

    //import java.text.DateFormat;

    //import java.text.NumberFormat;

//class TestHotel


     //public static void main(String[] arg)


     //NumberFormat f = NumberFormat.getCurrencyInstance();

     // Create customer objects, calculate amounts, display receipts

     //Hotel customer1 = new Hotel("10 - M", 2, 2);

     //Hotel customer2 = new Hotel("12 - B");

     //Hotel customer3 = new Hotel("12 - C", 2);






     //display(customer1, f);

     //display(customer2, f);

     //display(customer3, f);



     //static void display(Hotel h, NumberFormat f)


     // Set up and display heading and date for each receipt

     // System.out.println("\tThe ABC Cheap Lodging, Inc");

     // Date d = new Date();

     // DateFormat df = DateFormat.getDateInstance();

     // System.out.println("\tDate: \t" + df.format(d));

     // Disply expenses line by line including subtotal

     // System.out.println("Room# \t\t\t\t" + h.getRoomNumber());

     // System.out.println("Room Rate\t\t\t" + f.format(h.getRoomRate()));

     // System.out.println("Length of stay\t\t" + h.getNumberOfNights() + " night(s)");

     // System.out.println("No. of guests\t\t" + h.getNumberOfGuests());

     // System.out.println("Room cost\t\t\t" + f.format(h.getAmountDue()));

     // System.out.println("Tax" + h.getTaxRate() + "%\t\t\t\t" + f.format(h.getTaxDue()));

     // System.out.println("\tSubtotal \t\t\t" + f.format(h.getSubtotal()));

     // System.out.println("Telephone \t\t\t" + f.format(h.getPhoneCharges()));

     // System.out.println("Meal charges \t\t" + f.format(h.getMeal()));

     // System.out.println("Tip \t\t\t\t" + f.format(h.getTip()));

     //Display to total

     // System.out.println("\nTOTAL AMOUNT DUE\t.........." + f.format(h.getTotal()));

     // Display thank you message

     // System.out.println("\nThanks for staying at The ABC Cheap Lodging, Inc" );

     // System.out.println("\tPlease come again !!!");

     // System.out.println("\n");


     //static void display(NumberFormat f)


     // Complete this method so that it displays the summary amounts as shown in the output



Figure 1

Report this document

For any questions or suggestions please email