Netbeans The assignment: The ABC Cheap Lodging, Inc wants a computerized printed
ID: 3796872 • Letter: N
Question
Netbeans
The assignment: 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.
Welcome to ABC Cheap Lodging, Inc Rates Table
ROOM ………………$81.95 (per person)
TAX …………………6.5% (applies to room cost only)
TELEPHONE …….... $5.75 (Flat rate)
MEAL ……………... $ 14.95 (per person, per day)
TIP ………………….9.5% (cover all 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: Uncomment the statements for this incomplete test class. When complete, the program should generate out as shown in Figure 1.
//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); //customer1.calculate();
//display(customer1, f);
//Hotel customer2 = new Hotel("12 - B");
//Hotel customer3 = new Hotel("12 - C", 2);
//customer3.calculate();
//customer2.addNights(1);
//customer2.calculate();
//display(customer2, f);
//customer3.addGuest(1);
//customer3.calculate();
//display(customer3, f);
//display(f);
//} //static void display(Hotel h, NumberFormat f)
//{
// Set up and display heading and date for each receipt
// System.out.println(" The ABC Cheap Lodging, Inc");
// Date d = new Date();
// DateFormat df = DateFormat.getDateInstance();
// System.out.println(" Date: " + df.format(d));
// Display expenses line by line including subtotal as shown in the output
//Display to total // System.out.println(" TOTAL AMOUNT DUE .........." + f.format(h.getTotal()));
// Display thank you message
// System.out.println(" Thanks for staying at The ABC Cheap Lodging, Inc" );
// System.out.println(" Please come again !!!"); // System.out.println(" "); }
//static void display(NumberFormat f)
//{
// Complete this method so that it displays the summary amounts as shown in the output
//} /
Explanation / Answer
/**
* The java program TestHotel that tests the Hotel
* class and prints the summary of report of hotel
* to console.
* */
//TestHotel.java
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);
customer1.calculate();
display(customer1, f);
Hotel customer2 = new Hotel("12 - B");
Hotel customer3 = new Hotel("12 - C", 2);
customer3.calculate();
customer2.addNights(1);
customer2.calculate();
display(customer2, f);
customer3.addGuest(1);
customer3.calculate();
display(customer3, f);
display(f);
}
public static void display(Hotel h, NumberFormat f)
{
//Set up and display heading and date for each receipt
System.out.println(" The ABC Cheap Lodging, Inc");
Date d = new Date();
DateFormat df = DateFormat.getDateInstance();
System.out.println(" Date: " + df.format(d));
System.out.printf("%-20s%-10s ","Room#",h.getRoomNumber());
System.out.printf("%-20s$%-5.2f ","Room Rate",Hotel.ROOM_COST);
System.out.printf("%-20s$%-5d ",
"Length of stay",h.getNights());
System.out.printf("%-20s$%-5.2f ","Room cost",h.getRoomCost());
System.out.printf("%-20s$%-5.2f ","Tax 6.5 %",h.getTax());
System.out.printf("%20s%10.2f ","Subtotal$",h.getSubTotal());
System.out.printf("%-20s$%-5.2f ","Telephone",Hotel.TELEPHONE_CHARGE);
System.out.printf("%-20s$%-5.2f ","Meal Charges",h.getMealCost());
System.out.printf("%-20s$%-5.2f ","Tip",h.getTipCost());
System.out.println(" TOTAL AMOUNT DUE .........."
+ f.format(h.getTotal()));
//Display thank you message
System.out.println(" Thanks for staying "
+ "at The ABC Cheap Lodging, Inc" );
System.out.println(" Please come again !!!");
System.out.println(" ");
}
public static void display(NumberFormat f)
{
///summary report print to console
System.out.println(" Today's Summary");
System.out.println(" Room ........." + f.format(Hotel.getTotalRoomCost()));
System.out.println(" Telephone........" + f.format(Hotel.getTotalTelephone()));
System.out.println(" Meal ........." + f.format(Hotel.getTotalMealCost()));
System.out.println(" Tips ........." + f.format(Hotel.getTotalTipCost()));
System.out.println(" Tax ........." + f.format(Hotel.getTotalTax()));
System.out.println(" ______________________________________");
System.out.println(" Gross Transaction......." + f.format(Hotel.getOverallTotal()));
}
}
------------------------------------------------------------------------------------------------------------------------
//Hotel.java
public class Hotel {
//ROOM COST per person
public final static double ROOM_COST=81.95;
// tax rate
public final static double TAX =0.065;
public final static double TELEPHONE_CHARGE=5.75;
public final static double MEAL_PER_DAY=14.95;
//cover all charges
public final static double TIP_RATE=0.095;
//private data members
private double roomCost;
private double tax;
private double subTotal;
private double mealCharges;
private double tipCost;
private double total;
private double telephoneTotal;
//Set zeros to stati variables
static double totalRoomCharges=0;
static double totaltelephoneCharges=0;
static double totalmealChares=0;
static double totaltipsCharges=0;
static double totaltaxTotal=0;
static double allTotal=0;
private String roomNumber;
private int numStays;
private int numGuests;
//constructor that sets room number, nights and guests
public Hotel(String roomNumber,
int numStays,
int numGuests) {
this.roomNumber=roomNumber;
this.numStays=numStays;
this.numGuests=numGuests;
}
public Hotel(String roomNumber,
int numStays) {
this.roomNumber=roomNumber;
this.numStays=numStays;
this.numGuests=0;
}
public Hotel(String roomNumber) {
this.roomNumber=roomNumber;
this.numStays=0;
this.numGuests=0;
}
public String getRoomNumber(){
return roomNumber;
}
public int getNights(){
return numStays;
}
public int getNumGuests(){
return numGuests;
}
//Calculate chages
public void calculate() {
//calcualte chages
roomCost=getNights()*getNumGuests()*ROOM_COST;
tax=roomCost*TAX;
subTotal=roomCost+tax;
telephoneTotal=TELEPHONE_CHARGE;
mealCharges=getNights()*getNumGuests()*MEAL_PER_DAY;
tipCost=(subTotal+TELEPHONE_CHARGE+mealCharges)*TIP_RATE;
total=subTotal+mealCharges+TELEPHONE_CHARGE+tipCost;
//Add to totals static variables
totalRoomCharges+=roomCost;
totaltaxTotal+=tax;
totaltelephoneCharges+=telephoneTotal;
totalmealChares+=mealCharges;
totaltipsCharges+=tipCost;
allTotal+=total;
}
public double getTipCost(){
return tipCost;
}
public double getMealCost(){
return mealCharges;
}
public double getRoomCost(){
return roomCost;
}
public double getTax(){
return tax;
}
public double getSubTotal(){
return subTotal;
}
public double getTelephoneTotal()
{
return telephoneTotal;
}
public static double getTotalTelephone(){
return totaltelephoneCharges;
}
public static double getTotalMealCost(){
return totalmealChares;
}
public static double getTotalTipCost(){
return totaltipsCharges;
}
public static double getTotalTax(){
return totaltaxTotal;
}
public void addNights(int i) {
numStays++;
}
public void addGuest(int i) {
numGuests++;
}
public double getTotal() {
return total;
}
public static double getOverallTotal(){
return allTotal;
}
public static double getTotalRoomCost() {
return totalRoomCharges;
}
}
------------------------------------------------------------------------------------------------------------------------
Sample output:
The ABC Cheap Lodging, Inc
Date: Feb 23, 2017
Room# 10 - M
Room Rate $81.95
Length of stay $2
Room cost $327.80
Tax 6.5 % $21.31
Subtotal$ 349.11
Telephone $5.75
Meal Charges $59.80
Tip $37.37
TOTAL AMOUNT DUE ..........$452.03
Thanks for staying at The ABC Cheap Lodging, Inc
Please come again !!!
The ABC Cheap Lodging, Inc
Date: Feb 23, 2017
Room# 12 - B
Room Rate $81.95
Length of stay $1
Room cost $0.00
Tax 6.5 % $0.00
Subtotal$ 0.00
Telephone $5.75
Meal Charges $0.00
Tip $0.55
TOTAL AMOUNT DUE ..........$6.30
Thanks for staying at The ABC Cheap Lodging, Inc
Please come again !!!
The ABC Cheap Lodging, Inc
Date: Feb 23, 2017
Room# 12 - C
Room Rate $81.95
Length of stay $2
Room cost $163.90
Tax 6.5 % $10.65
Subtotal$ 174.55
Telephone $5.75
Meal Charges $29.90
Tip $18.96
TOTAL AMOUNT DUE ..........$229.16
Thanks for staying at The ABC Cheap Lodging, Inc
Please come again !!!
Today's Summary
Room .........$491.70
Telephone........$23.00
Meal .........$89.70
Tips .........$57.42
Tax .........$31.96
______________________________________
Gross Transaction.......$693.78
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.