I really don't understand why it is giving me an error ive been looking at it for and 2 hour now. I think i need a fresh pair of eye to look at it. I fixed the first problem but how do i add up the total room charges from the three diffrent rooms
CODE
public class Hotel
{// Storat of code
// Class constants
private static final double ROOM_RATE = 79.95;
private static final double TAX_RATE = 6.5;
private static final double TELEPHONE = 5.75;
private static final double MEAL_COST = 12.95;
private static final double TIP_RATE = 0.075;
// Instance variables
private int noOfNights;
private int noOfGuest;
private double amountDue;
private static double meal;
private static double totalmeal;
private static double tax;
private static double totaltax;
private double subtotal;
private double total;
private static double tip;
private static double totaltip;
private String roomNumber;
private static double totalAmount;
public Hotel(String room)
{
roomNumber = room;
noOfGuest = 1;
noOfNights = 1;
}
public Hotel(String room, int nights)
{
this(room);
noOfNights = nights;
}
public Hotel(String room, int nights, int guest)
{
this(room, nights);
noOfGuest = guest;
}
public void add(int nights)
{
noOfNights = noOfNights + nights;
}
public void calculate()
{
amountDue = ROOM_RATE * noOfNights * noOfGuest;
tax = amountDue * TAX_RATE/100;
subtotal = amountDue + tax;
meal = MEAL_COST * noOfNights;
tip = TIP_RATE * (subtotal + meal + TELEPHONE);
total = subtotal + TELEPHONE + meal + tip;
totalAmount = total * 3;
totaltax = tax * 3;
totalmeal = meal * 3;
totaltip = tip*3;
}
public double getAmountDue()
{return amountDue;}
public static double getTaxDue()
{ return tax;}
public double getSubtotal()
{ return subtotal; }
public double getTotal()
{ return total; }
public static double getTip()
{ return tip; }
public static double getMeal()
{ return meal;}
public String getRoomNumber()
{ return roomNumber; }
public double getRoomRate()
{ return ROOM_RATE; }
public int getNumberOfNights()
{ return noOfNights; }
public int getNumberOfGuests()
{ return noOfGuest; }
public static double getPhoneCharges()
{ return TELEPHONE; }
public static double getTaxRate()
{ return TAX_RATE; }
public static double getTotalRoomCharges()
{
return totalAmount;
}
public static double getTotalPhoneCharges()
{ return TELEPHONE*3; }
public static double getTotalTaxRate()
{ return totaltax; }
public static double getTotalTip()
{ return totaltip; }
public static double getTotalMeal()
{ return totalmeal;}
public static double getTotalTaxDue()
{ return totaltax;}
}// end of Code
CODE
import java.util.Date;
import java.text.DateFormat;
import java.text.NumberFormat;
class TestHotel
{
public static void main(String[] arg)
{
NumberFormat nf = NumberFormat.getCurrencyInstance();
// Create customer objects, calculate amounts, display receipts
Hotel customer1 = new Hotel("12 - B");
customer1.calculate();
displayReceipt(customer1, nf);
Hotel customer2 = new Hotel("12 - C", 2);
customer2.calculate();
displayReceipt(customer2, nf);
Hotel customer3 = new Hotel("12 - D", 2, 2);
customer3.calculate();
displayReceipt(customer3, nf);
// Call method to print summary information
summary(nf);
}
static void displayReceipt(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" + h.getRoomNumber());
System.out.println("Room Rate: \t" + f.format(h.getRoomRate()));
System.out.println("Length of stay\t" + h.getNumberOfNights() + " nights");
System.out.println("No. of guests: \t" + h.getNumberOfGuests());
System.out.println("Room cost: \t" + f.format(h.getAmountDue()));
System.out.println("Tax : " + h.getTaxRate() + "%\t" + f.format(h.getTaxDue()));
System.out.println("\tSubtotal \t" + f.format(h.getSubtotal()));
System.out.println("Telephone \t" + f.format(h.getPhoneCharges()));
System.out.println("Meal charges \t" + f.format(h.getMeal()));
System.out.println("Tip \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 summary(NumberFormat nf)
{
System.out.println("\n\n\tOfficial Use Only\n\n\tToday's Summary");
System.out.println("\tRoom ...... " + nf.format(Hotel.getTotalRoomCharges()));
System.out.println("\tTelephone . " + nf.format(Hotel.getTotalPhoneCharges()));
System.out.println("\tMeal ...... " + nf.format(Hotel.getTotalMeal()));
System.out.println("\tTip ....... " + nf.format(Hotel.getTotalTip()));
System.out.println("\ttax ....... " + nf.format(Hotel.getTotalTaxDue()));
// Complete this method that prints the summary
System.out.println("\t__________________");
}
}
This post has been edited by AlphaOmegas: 26 Sep, 2008 - 01:44 PM