Results 1 to 11 of 11
Thread: Help with this test class
- 03-08-2010, 07:28 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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 06:36 PM.
- 03-08-2010, 07:29 PM #2
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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;
}
}
- 03-08-2010, 07:36 PM #3
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
- 03-08-2010, 07:52 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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.
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: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
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.)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())); }
" 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 07:54 PM.
- 03-08-2010, 08:29 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
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
- 03-09-2010, 12:41 AM #6
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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())); }
- 03-09-2010, 06:37 PM #7
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
Never mind guys. I got it figured out. Thanks for the help.
- 03-09-2010, 06:42 PM #8
Great! Glad you've found out yourself.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 06-20-2011, 03:45 AM #9
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
i have the same problem with the above situation (@ fsuarjun03's) can someone help with a solution
- 06-20-2011, 03:50 AM #10
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.
-
Agree with Junky and locking this thread. Start your own thread and provide the details.
Similar Threads
-
Help please! .class expected when compiling JUnit test?
By tfitz666 in forum New To JavaReplies: 2Last Post: 12-31-2009, 12:45 PM -
*TEST* --ignore this--
By angryboy in forum Reviews / AdvertisingReplies: 5Last Post: 05-01-2009, 08:15 AM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 05:15 PM -
A simple application to test the functionality of the OvalIcon class
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:16 PM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM


LinkBack URL
About LinkBacks

Bookmarks