Results 1 to 11 of 11
  1. #1
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default Help with this test class

    I am trying to find out what I did wrong with this test class. I tried getting help from my professor but he is showing no effort in helping me understand the actual work. Perhaps you gents could help me understand what I have done wrong. I got everything in the test class right except for the final part. In the final part of the test class I am supposed to have it be a summary of the three previous customers before hand. I'm pasting what I have for the test class below. Any input would be useful.

    import java.util.Date;
    import java.text.DateFormat;
    import java.text.NumberFormat;

    class TestHotel
    {
    public static void main(String[] arg)
    {
    NumberFormat f = NumberFormat.getCurrencyInstance();


    Hotel customer1 = new Hotel("10 - M", 2, 2);
    Hotel customer2 = new Hotel("12 - B");
    Hotel customer3 = new Hotel("12 - C", 2);

    customer2.addNights(1);
    customer3.addGuest(1);

    customer1.calculate();
    customer2.calculate();
    customer3.calculate();

    display(customer1, f);
    display(customer2, f);
    display(customer3, f);

    display(f);
    }

    static void display(Hotel h, NumberFormat f)
    {
    System.out.println("\tThe ABC Cheap Lodging, Inc");
    Date d = new Date();
    DateFormat df = DateFormat.getDateInstance();
    System.out.println("\tDate: \t" + df.format(d));

    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()));

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

    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)
    {
    System.out.println( 10 + 20 + " Hi hello " + (10 + 20));
    System.out.println("\tOfficial Use Only");

    System.out.println("\tTodays Summary");
    System.out.println("\tRoom ...." + f.format(h.getAmountDue()));
    System.out.println("\tTelephone .." + f.format(h.getPhoneCharges()));
    System.out.println("\tMeal ...." + f.format(h.getMeal()));
    System.out.println("\tTips ...." + f.format(h.getTip()));
    System.out.println("\tTax ...." + f.format(h.getTaxDue()));
    System.out.println("\t_____________________");
    System.out.println("\tGross Transaction " + f.format(h.getTotal()));

    }
    }
    Last edited by fsuarjun03; 03-09-2010 at 07:36 PM.

  2. #2
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    This is the main class in case anyone was wondering.


    public class Hotel
    {
    private static final double RoomRate = 79.95;
    private static final double TaxRate = 6.5;
    private static final double PhoneCharges = 5.75;
    private static final double MealCost = 12.95;
    private static final double TipRate = 0.075;

    private int NumberOfNights;
    private int NumberOfGuests;
    private double AmountDue;
    private double Meal;
    private double TaxDue;
    private double Subtotal;
    private double Total;
    private double tip;
    private String RoomNumber;

    public Hotel(String room)
    {
    RoomNumber = room;
    NumberOfGuests = 1;
    NumberOfNights = 1;
    }

    public Hotel(String room, int nights)
    {
    this(room);
    NumberOfNights = nights;
    }

    public Hotel(String room, int nights, int guest)
    {
    this(room, nights);
    NumberOfGuests = guest;
    }
    public void addNights(int nights)
    {
    NumberOfNights = NumberOfGuests + nights;
    }
    public void addGuest(int guests)
    {
    NumberOfGuests = 1 + guests;
    }

    public void calculate()
    {
    AmountDue = RoomRate * NumberOfNights * NumberOfGuests;
    TaxDue = AmountDue * TaxRate/100;
    Subtotal = AmountDue + TaxDue;
    Meal = MealCost * (NumberOfNights * NumberOfGuests);
    tip = TipRate * (Subtotal + Meal + PhoneCharges);
    Total = Subtotal + PhoneCharges + Meal + tip;
    }
    public String getRoomNumber()
    {
    return RoomNumber;
    }
    public static final double getRoomRate()
    {
    return RoomRate;
    }
    public static final double getTaxRate()
    {
    return TaxRate;
    }
    public static final double getPhoneCharges()
    {
    return PhoneCharges;
    }
    public static final double getMeal()
    {
    return MealCost;
    }
    public int getNumberOfNights()
    {
    return NumberOfNights;
    }
    public int getNumberOfGuests()
    {
    return NumberOfGuests;
    }
    public double getAmountDue()
    {
    return AmountDue;
    }
    public double getTaxDue()
    {
    return TaxDue;
    }
    public double getSubtotal()
    {
    return Subtotal;
    }
    public double getTotal()
    {
    return Total;
    }
    public double getTip()
    {
    return tip;
    }
    }

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    First of all use CODE tags when posting code. What is the problem? Compiler errors? Exceptions? Stack trace? What output do you get? What do you expect?
    There's no way helping you if you don't provide more information.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    Sorry. I just joined the forum and I wasn't sure how to post properly. I just really want to learn Java. I'll post as CODE tag next time.

    The error I get is as follows.

    Java Code:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
            Official Use Only
            at TestHotel.display(TestHotel.java:60)
            at TestHotel.main(TestHotel.java:27)
            Todays Summary
    Java Result: 1
    The code below is wrong but this is what I typed in. I got all of my assignment correct up until this final section of my test class.

    Java Code:
    static void display(NumberFormat f)
            {
                    System.out.println("\tOfficial Use Only");
    
                    System.out.println("\tTodays Summary");
                    System.out.println("\tRoom     ...." + f.format(h.getAmountDue()));
                    System.out.println("\tTelephone  .." + f.format(h.getPhoneCharges()));
                    System.out.println("\tMeal     ...." + f.format(h.getMeal()));
                    System.out.println("\tTips     ...." + f.format(h.getTip()));
                    System.out.println("\tTax      ...." + f.format(h.getTaxDue()));
                    System.out.println("\t_____________________");
                    System.out.println("\tGross Transaction    " + f.format(h.getTotal()));
    
    	}
    What I am supposed to have for the final part of the assignment is as follows. (It is supposed to be a summary of the three customers purchases at a hotel.)

    " Official Use Only

    Today's Summary

    Room ........$799.50
    Telephone ..$17.25
    Meal..........$129.50
    Tips...........$74.87
    Tax............$51.97
    _________________
    Gross transaction.....$1,073.08"

    Should I have put a formula or something into the main class?

    If you need anymore information let me know.

    Thanks.



    P.S. I am a pretty big newbie to Java so any tips for understanding it better is gladly welcome.
    Last edited by fsuarjun03; 03-08-2010 at 08:54 PM.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    What is 'h' in the body of that method? It isn't defined anywhere so your compiler complained about it but you were still trying to run your incorrect code. Fix those compilation errors first before you try anything else.

    kind regards,

    Jos

  6. #6
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    My teacher provided the original test class and I was supposed to add on the final part which I put below. He put the "h" in for the beginning part of the test class and I just followed suit by putting it in below.

    How do I get the previous totals for customer1, customer2, and customer3 to add up into the summary?

    For example, I got this whole thing to the point where customer1, customer2, and customer3 each have their own expenses for the Room, Telephone, Meal, Tip, and Tax due. I'm at the final part where I want to add the room charges up for each customer and find what the final room charge is, for the day, for all three customers.

    Java Code:
    {
                    System.out.println("\tOfficial Use Only");
    
                    System.out.println("\tTodays Summary");
                    System.out.println("\tRoom     ...." + f.format(h.getAmountDue()));
                    System.out.println("\tTelephone  .." + f.format(h.getPhoneCharges()));
                    System.out.println("\tMeal     ...." + f.format(h.getMeal()));
                    System.out.println("\tTips     ...." + f.format(h.getTip()));
                    System.out.println("\tTax      ...." + f.format(h.getTaxDue()));
                    System.out.println("\t_____________________");
                    System.out.println("\tGross Transaction    " + f.format(h.getTotal()));
    
    	}

  7. #7
    fsuarjun03 is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    Never mind guys. I got it figured out. Thanks for the help.

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Great! Glad you've found out yourself.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    yasmonz is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default

    i have the same problem with the above situation (@ fsuarjun03's) can someone help with a solution

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Don't hijack other threads, especially old ones. You should start your own thread, post your code, include error messages and ask a specific question.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 2
    Last Post: 12-31-2009, 01:45 PM
  2. *TEST* --ignore this--
    By angryboy in forum Reviews / Advertising
    Replies: 5
    Last Post: 05-01-2009, 09:15 AM
  3. JUnit Test Help!
    By pharo in forum New To Java
    Replies: 0
    Last Post: 04-10-2009, 06:15 PM
  4. Replies: 0
    Last Post: 06-24-2008, 12:16 AM
  5. Replies: 0
    Last Post: 04-05-2008, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •