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