I have a question. I'm parallel array in my program. One is for keeping track of customer name and the other is for their tip.
So do I store the Customer name into an array that I am able to recall from Salon to Stylist and be able to call back?
package labs;
public class Stylist
{
private String name;
private double wage, hours, totalTip;
private int numCustomers;
private final int MINWAGE = 11, MAXWAGE = 25, MINHOURS = 1, MAXHOURS = 60;
private final double MINTIP = 0.1, MAXTIP =100;
private String [] cusName = new String[100];
private double [] tips = new double[cusName.length];
public Stylist ()
{
numCustomers = 0;
wage = MINWAGE;
}
public Stylist (String n)
{
this();
name = n;
}
public Stylist (String n, double w)
{
this(n);
wage = w;
}
public boolean addCustomer(double t)
{
if (!valid(t,MINTIP, MAXTIP))
return false;
numCustomers++;
totalTip += t;
return true;
}
public boolean setHours (double h)
{
if (!valid(h, MINHOURS, MAXHOURS))
return false;
hours = h;
return true;
}
public boolean setWage(double w)
{
if (!valid (w, MINWAGE,MAXWAGE))
return false;
wage = w;
return true;
}
public boolean valid(double value, double min, double max)
{
return (value >= min && value <= max);
}
public void setName(String n)
{
name = n;
}
public void setCusName(String cn){
int i;
cusName[i] = cn;
i++;
}
public void setCusTip(double [] t){
tips = t;
}
public double salary() {return hours*wage;}
public double getWage() {return wage; }
public double getTotalTip() {return totalTip;}
public String getName(){return name;}
public int getNumCustomer(){return numCustomers; }
public double getHours() {return hours; }
public String[] getCusName(){ return cusName;}
public double[] getCusTip(){return tips;}
public String toString()
{
return "\nStylist: "+name + " earned a salary of: $"+salary()+" and tips $" + totalTip + "\nTotal Pay: $" + (salary()+totalTip) + "\nAverage tip: $" + totalTip/numCustomers ;
}
}
package labs;
import javax.swing.JOptionPane;
public class Salon
{
public static void main (String [] args)
{
String summary = "Information from all Stylists: \n";
int numStylists=0;
double totalSalary=0, allTips=0;
Stylist oneStylist;
do {
oneStylist = fillStylist();
totalSalary+=oneStylist.salary();
processStylist(oneStylist);
allTips += oneStylist.getTotalTip();
summary += oneStylist.toString();
numStylists++;
JOptionPane.showMessageDialog(null, oneStylist.toString());
}while (JOptionPane.showConfirmDialog(null, "Another Stylist?")==JOptionPane.YES_OPTION);
display(summary + "\n\n Total Salary paid: $"+totalSalary+"\nTotal Tips earned: $"+allTips);
}
public static void display(String allInfo)
{
JOptionPane.showMessageDialog(null,allInfo);
}
public static Stylist fillStylist()
{
Stylist oneStylist = new Stylist(JOptionPane.showInputDialog("Enter stylist's name:"));
double wage, hours;
do {
wage = Double.parseDouble(JOptionPane.showInputDialog("What is "+oneStylist.getName()+"'s hourly wage?"));
} while (!oneStylist.setWage(wage));
do {
hours = Double.parseDouble(JOptionPane.showInputDialog("How many hours did "+oneStylist.getName()+" work this week?"));
} while (!oneStylist.setHours(hours));
return oneStylist;
}
public static void customer(Stylist one)
{
// I am planning to pass three arguments in this method. One will be the String array(customer name)
// The other will be the customer array and the third will the index of where to do the customer.
String cName;
double tip;
cName = JOptionPane.showInputDialog("Enter name of customer:");
tip = Double.parseDouble(JOptionPane.showInputDialog("What was the tip amount left by "+cName));
if (!one.addCustomer(tip))
JOptionPane.showMessageDialog(null, "No tip!!!");
}
public static void processStylist(Stylist one)
{
do {
customer(one);
}while (JOptionPane.showConfirmDialog(null, "Did "+one.getName()+" have another customer?")==JOptionPane.YES_OPTION);
}
}

New Topic/Question
Reply
MultiQuote












|