| | |
So very lost =( trying to get a total
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 3
Reputation:
Solved Threads: 0
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
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
java Syntax (Toggle Plain Text)
package Hotel; /** * * @author silentone190 */ public class customer { private static final double RmR = 79.95; private static final double TxR = 6.5; private static final double PhC = 5.75; private static final double mlC = 12.95; private static final double tipRate = .075; private String roomNum; private int guestNum; private int nightNum; private double AmDue; private double ml; private double tx; private double subTot; private double tot; private double tip; public double TotAmD; public customer(String rmN) { roomNum = rmN; guestNum = 1; nightNum = 1; } public customer(String rmN, int night) { this(rmN); nightNum = night; } public customer(String rmN, int night, int guest) { this(rmN, night); guestNum = guest; } public void add(int night) { nightNum = nightNum + night; } public void calculate() { AmDue = RmR*nightNum*guestNum; tx = AmDue*TxR/100; subTot = AmDue+tx; ml = mlC*(nightNum*guestNum); tip = tipRate*(subTot+ml+PhC); tot = subTot+PhC+ml+tip; } public void TotAmD() { TotAmD = +AmDue; } public double getAmDue() { return AmDue; } public double getTxD() { return tx; } public double getTxR() { return TxR; } public double getsubTot() { return subTot; } public double gettot() { return tot; } public double gettip() { return tip; } public double getMl() { return ml; } public double getRmR() { return RmR; } public double getPhC() { return PhC; } public String getTheRmN() { return roomNum; } public int getNn() { return nightNum; } public int getGn() { return guestNum; } public double getTotAmD() { return TotAmD; } } and 2.) class myHotel package Hotel; import java.util.Date; import java.text.DateFormat; import java.text.NumberFormat; import java.util.Locale; public class myHotel { public static void main(String[] args) { NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); // Create customer objects, calculate amounts, display receipts customer c1 = new customer("12 - B"); c1.calculate(); displayReceipt(c1, nf); customer c2 = new customer("12 - C", 2); c2.calculate(); displayReceipt(c2, nf); customer c3 = new customer("12 - D", 2, 2); c3.calculate(); displayReceipt(c3, nf); // Call method to print summary information summary(nf); } static void displayReceipt(customer 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.getTheRmN()); System.out.println("Room Rate: \t" + f.format(h.getRmR())); System.out.println("Length of stay\t" + h.getNn() + " nights"); System.out.println("No. of guests: \t" + h.getGn()); System.out.println("Room cost: \t" + f.format(h.getAmDue())); System.out.println("Tax : " + h.getTxR() + "%\t" + f.format(h.getTxD())); System.out.println("\tSubtotal \t" + f.format(h.getsubTot())); System.out.println("Telephone \t" + f.format(h.getPhC())); System.out.println("Meal charges \t" + f.format(h.getMl())); System.out.println("Tip \t\t" + f.format(h.gettip())); //Display to total System.out.println("\nTOTAL AMOUNT DUE\t" + f.format(h.gettot())); // 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 ......" +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())); // Complete this method that prints the summary System.out.println("\t__________________"); } }
Last edited by cscgal; Oct 1st, 2008 at 11:39 pm. Reason: Added code tags
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:
for instance:
Java Syntax (Toggle Plain Text)
double total = 0; for( int i = 0; i < customers.length(); i++ ) total = customers[i].getAmount(); // I'm not sure what field you want to put together, just looked at your code briefly, but // this (I think) is what you're looking for
•
•
•
•
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:
Java Syntax (Toggle Plain Text)
double total = 0; for( int i = 0; i < customers.length(); i++ ) total = customers[i].getAmount(); // I'm not sure what field you want to put together, just looked at your code briefly, but // this (I think) is what you're looking for
total = total + customers[i].getAmount()
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
•
•
Don't forget to add each time the new amount to the total. This will give you the sum:
total = total + customers[i].getAmount()

meant to put it as
Java Syntax (Toggle Plain Text)
total += customers[i].getAmount();
•
•
Join Date: Oct 2008
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- im lost and need help (Computer Science)
- I'm lost and need some help (C++)
- CPU usage 100%!!! (Windows NT / 2000 / XP)
- Total Newbie Could Use A Pointer In The Right Direction (C++)
- Lost Partitions (Storage)
- lost on writing a Java class (Java)
- Lost my monitoring Index view window!!!! (PHP)
- Converting Struct to class lost with pointers (C++)
- Compaq Lost Files? (Troubleshooting Dead Machines)
Other Threads in the Java Forum
- Previous Thread: Canvas, pain() and playing sound
- Next Thread: Trouble with classes
Views: 581 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider detection draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle os plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree windows






