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

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__________________");
  }
}

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:

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:

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

Don't forget to add each time the new amount to the total. This will give you the sum:

total = total + customers.getAmount()

Don't forget to add each time the new amount to the total. This will give you the sum:

total = total + customers.getAmount()

mjah, typo :)

meant to put it as

total += customers[i].getAmount();

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.

i'm sorry , i mean in the calculate class (47-53). calculate is used in each new customer.

This article has been dead for over six months. Start a new discussion instead.