Welcome to Dream.In.Code
Become a Java Expert!

Join 150,197 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,033 people online right now. Registration is fast and FREE... Join Now!




Hotel

 
Reply to this topicStart new topic

Hotel, Hotel Total not compiling

AlphaOmegas
25 Sep, 2008 - 04:14 PM
Post #1

New D.I.C Head
*

Joined: 25 Sep, 2008
Posts: 4

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
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Hotel
25 Sep, 2008 - 04:25 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
the method getTotalRoom() is not defined in your Hotel class, you cannot call methods that do not exist.
User is offlineProfile CardPM
+Quote Post

AlphaOmegas
RE: Hotel
25 Sep, 2008 - 07:05 PM
Post #3

New D.I.C Head
*

Joined: 25 Sep, 2008
Posts: 4

Wow i cant believe i missed that. thanxs. how would i add the total for each room?

This post has been edited by AlphaOmegas: 25 Sep, 2008 - 07:39 PM
User is offlineProfile CardPM
+Quote Post

bbq
RE: Hotel
25 Sep, 2008 - 07:58 PM
Post #4

D.I.C Head
Group Icon

Joined: 15 May, 2008
Posts: 200



Thanked: 17 times
Dream Kudos: 50
My Contributions
In your calculate function you have
java
total = subtotal + TELEPHONE + meal + tip;

So i am assuming thats the total cost for each room ? hence a function to return total might do it.
User is offlineProfile CardPM
+Quote Post

AlphaOmegas
RE: Hotel
26 Sep, 2008 - 05:44 AM
Post #5

New D.I.C Head
*

Joined: 25 Sep, 2008
Posts: 4

yes, but im not sure how to add up the the total for each room i only get the total for the last room any link to show me how to do that would be a big help

This post has been edited by AlphaOmegas: 26 Sep, 2008 - 05:47 AM
User is offlineProfile CardPM
+Quote Post

bbq
RE: Hotel
26 Sep, 2008 - 05:57 AM
Post #6

D.I.C Head
Group Icon

Joined: 15 May, 2008
Posts: 200



Thanked: 17 times
Dream Kudos: 50
My Contributions
Ah well i just noticed in your class Hotel

you have 2 functions
public void calculate()
and
public double getTotal()

So if you do
java
customer1.calculate();
//then
customer1.getTotal();


and repeat that for each customer using customer2.calculate(); then customer2.getTotal()

That should get you all the prices for each room, unless i have missed something

This post has been edited by bbq: 26 Sep, 2008 - 05:58 AM
User is offlineProfile CardPM
+Quote Post

RETNE
RE: Hotel
26 Sep, 2008 - 01:30 PM
Post #7

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 22


My Contributions
wow that is alot of code. Seriously cut it down
User is offlineProfile CardPM
+Quote Post

AlphaOmegas
RE: Hotel
26 Sep, 2008 - 01:46 PM
Post #8

New D.I.C Head
*

Joined: 25 Sep, 2008
Posts: 4

im kinda new so i dont know how yet. thanx bbq i have the display parts working now but can someone show me a link for a tutorial of how to add the cost of the cost at the end.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:45AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month