So very lost =( trying to get a total

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 3
Reputation: silentone190 is an unknown quantity at this point 
Solved Threads: 0
silentone190 silentone190 is offline Offline
Newbie Poster

So very lost =( trying to get a total

 
0
  #1
Oct 1st, 2008
Hello. I am new at this and I'm having trouble getting a total from multiple data. What i need is a total for a final summary. How do i calculate this? i have searched and read many text on this subject, but have had no luck... some how i get the feeling i have over looked some thing. this is an assignment, but it was due earlier today, so any help would be strictly for my information.

i know i have to create classes for:
System.out.println("\tROOM ......" +customer.getTotAmD());
System.out.println("\tPHONE ....." + nf.format(customer.getTotPhC()));
System.out.println("\tPHONE ....." + nf.format(customer.getTotmlC()));
System.out.println("\tTIP ......." + nf.format(customer.getTottip()));
System.out.println("\tTAX ......." +nf.format(customer.getTottax()));
but what would the calculations look like?

so far i have the following:

1.)class customer
  1. package Hotel;
  2.  
  3. /**
  4.  *
  5.  * @author silentone190
  6.  */
  7. public class customer
  8.  
  9. { private static final double RmR = 79.95;
  10. private static final double TxR = 6.5;
  11. private static final double PhC = 5.75;
  12. private static final double mlC = 12.95;
  13. private static final double tipRate = .075;
  14.  
  15. private String roomNum;
  16. private int guestNum;
  17. private int nightNum;
  18. private double AmDue;
  19. private double ml;
  20. private double tx;
  21. private double subTot;
  22. private double tot;
  23. private double tip;
  24.  
  25. public double TotAmD;
  26.  
  27. public customer(String rmN)
  28. { roomNum = rmN;
  29. guestNum = 1;
  30. nightNum = 1;
  31. }
  32.  
  33. public customer(String rmN, int night)
  34. { this(rmN);
  35. nightNum = night;
  36. }
  37.  
  38. public customer(String rmN, int night, int guest)
  39. { this(rmN, night);
  40. guestNum = guest;
  41. }
  42.  
  43. public void add(int night)
  44. { nightNum = nightNum + night;
  45. }
  46.  
  47. public void calculate()
  48. { AmDue = RmR*nightNum*guestNum;
  49. tx = AmDue*TxR/100;
  50. subTot = AmDue+tx;
  51. ml = mlC*(nightNum*guestNum);
  52. tip = tipRate*(subTot+ml+PhC);
  53. tot = subTot+PhC+ml+tip;
  54.  
  55. }
  56.  
  57. public void TotAmD()
  58. { TotAmD = +AmDue;
  59. }
  60.  
  61. public double getAmDue()
  62. { return AmDue;
  63. }
  64.  
  65. public double getTxD()
  66. { return tx;
  67. }
  68.  
  69. public double getTxR()
  70. { return TxR;
  71. }
  72.  
  73. public double getsubTot()
  74. { return subTot;
  75. }
  76.  
  77. public double gettot()
  78. { return tot;
  79. }
  80.  
  81. public double gettip()
  82. { return tip;
  83. }
  84.  
  85. public double getMl()
  86. { return ml;
  87. }
  88.  
  89. public double getRmR()
  90. { return RmR;
  91. }
  92.  
  93. public double getPhC()
  94. { return PhC;
  95. }
  96.  
  97. public String getTheRmN()
  98. { return roomNum;
  99. }
  100.  
  101. public int getNn()
  102. { return nightNum;
  103. }
  104.  
  105. public int getGn()
  106. { return guestNum;
  107. }
  108.  
  109. public double getTotAmD()
  110. { return TotAmD;
  111. }
  112.  
  113. }
  114.  
  115. and 2.) class myHotel
  116.  
  117. package Hotel;
  118.  
  119. import java.util.Date;
  120. import java.text.DateFormat;
  121. import java.text.NumberFormat;
  122. import java.util.Locale;
  123.  
  124. public class myHotel
  125. {
  126.  
  127. public static void main(String[] args)
  128. { NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
  129.  
  130.  
  131. // Create customer objects, calculate amounts, display receipts
  132. customer c1 = new customer("12 - B");
  133. c1.calculate();
  134. displayReceipt(c1, nf);
  135.  
  136. customer c2 = new customer("12 - C", 2);
  137. c2.calculate();
  138. displayReceipt(c2, nf);
  139.  
  140. customer c3 = new customer("12 - D", 2, 2);
  141. c3.calculate();
  142. displayReceipt(c3, nf);
  143.  
  144. // Call method to print summary information
  145. summary(nf);
  146.  
  147. }
  148. static void displayReceipt(customer h, NumberFormat f)
  149. {
  150. // Set up and display heading and date for each receipt
  151. System.out.println("\tThe ABC Cheap Lodging, Inc");
  152. Date d = new Date();
  153. DateFormat df = DateFormat.getDateInstance();
  154. System.out.println("\tDate: \t" + df.format(d));
  155.  
  156. // Disply expenses line by line including subtotal
  157. System.out.println("Room# \t\t" + h.getTheRmN());
  158. System.out.println("Room Rate: \t" + f.format(h.getRmR()));
  159. System.out.println("Length of stay\t" + h.getNn() + " nights");
  160. System.out.println("No. of guests: \t" + h.getGn());
  161. System.out.println("Room cost: \t" + f.format(h.getAmDue()));
  162. System.out.println("Tax : " + h.getTxR() + "%\t" + f.format(h.getTxD()));
  163. System.out.println("\tSubtotal \t" + f.format(h.getsubTot()));
  164. System.out.println("Telephone \t" + f.format(h.getPhC()));
  165. System.out.println("Meal charges \t" + f.format(h.getMl()));
  166. System.out.println("Tip \t\t" + f.format(h.gettip()));
  167. //Display to total
  168. System.out.println("\nTOTAL AMOUNT DUE\t" + f.format(h.gettot()));
  169.  
  170. // Display thank you message
  171. System.out.println("\nThanks for staying at The ABC Cheap Lodging, Inc" );
  172. System.out.println("\tPlease come again !!!");
  173. System.out.println("\n");
  174. }
  175.  
  176. static void summary(NumberFormat nf)
  177. {
  178. System.out.println("\n\n\tOfficial Use Only\n\n\tToday's Summary");
  179. System.out.println("\tROOM ......" +customer.getTotAmD());
  180. System.out.println("\tPHONE ....." + nf.format(customer.getTotPhC()));
  181. System.out.println("\tPHONE ....." + nf.format(customer.getTotmlC()));
  182. System.out.println("\tTIP ......." + nf.format(customer.getTottip()));
  183. System.out.println("\tTAX ......." +nf.format(customer.getTottax()));
  184.  
  185. // Complete this method that prints the summary
  186. System.out.println("\t__________________");
  187. }
  188. }
Last edited by cscgal; Oct 1st, 2008 at 11:39 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: So very lost =( trying to get a total

 
0
  #2
Oct 3rd, 2008
if you are trying to get (for instance) the total of amount for the customers, just insert your customers in an array and loop over that array getting the amount you want

for instance:
  1.  
  2. double total = 0;
  3. for( int i = 0; i < customers.length(); i++ )
  4. total = customers[i].getAmount();
  5. // I'm not sure what field you want to put together, just looked at your code briefly, but
  6. // this (I think) is what you're looking for
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: So very lost =( trying to get a total

 
0
  #3
Oct 3rd, 2008
Originally Posted by stultuske View Post
if you are trying to get (for instance) the total of amount for the customers, just insert your customers in an array and loop over that array getting the amount you want

for instance:
  1.  
  2. double total = 0;
  3. for( int i = 0; i < customers.length(); i++ )
  4. total = customers[i].getAmount();
  5. // I'm not sure what field you want to put together, just looked at your code briefly, but
  6. // this (I think) is what you're looking for
Don't forget to add each time the new amount to the total. This will give you the sum:

total = total + customers[i].getAmount()
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: So very lost =( trying to get a total

 
0
  #4
Oct 3rd, 2008
Originally Posted by javaAddict View Post
Don't forget to add each time the new amount to the total. This will give you the sum:

total = total + customers[i].getAmount()
mjah, typo

meant to put it as

  1. total += customers[i].getAmount();
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: silentone190 is an unknown quantity at this point 
Solved Threads: 0
silentone190 silentone190 is offline Offline
Newbie Poster

Re: So very lost =( trying to get a total

 
0
  #5
Oct 3rd, 2008
i see... i will try it with the proper values.

the variables of which i need totals are found in the calculate object (ln#133,137 and 141) of each new customer (c1,2,and3). the trouble i am having is getting each value from its location within each customer.

ie: System.out.println("\tROOM ......" +customer.getTotAmD());
where getTotAmD= (sum total AmD of each customer)

for the sake of turning in a completed assignment i simply entered the values in println ("text") format.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: silentone190 is an unknown quantity at this point 
Solved Threads: 0
silentone190 silentone190 is offline Offline
Newbie Poster

Re: So very lost =( trying to get a total

 
0
  #6
Oct 3rd, 2008
i'm sorry , i mean in the calculate class (47-53). calculate is used in each new customer.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 581 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC