I've created a class (haven't touched it in a wk) but I'm not sure how the set and get method work. I know you have to call them from the application (the set method first) but what do you do with the getMethods?
I'm not sure if posting my code will help, but here it is:
Code:import javax.swing.JOptionPane;
import java.text.*;
import java.util.*;
public class CandyClass
{
private double dumdums;
private double snickerballs;
private double sweettarts;
private double skittles;
private final Double tax;
private double subtotal;
private double total;
private double price;
private int qtyWanted;
private int quantity;
//private double order1, order2, order3;
private DecimalFormat decimalf = new DecimalFormat("$##.##");
private NumberFormat money = NumberFormat.getCurrencyInstance(Locale.US);
public CandyClass()
{
dumdums = 1.50;
snickerballs = 3.00;
sweettarts = 2.00;
skittles = 2.75;
tax = .06;
}
//Mutators: set/calculate methods
public void setDumdums(double inDumdums)
{
dumdums = inDumdums;
}
public void setSnickerballs(double inSnickerballs)
{
snickerballs = inSnickerballs;
}
public void setSweettarts(double inSweettarts)
{
sweettarts = inSweettarts;
}
public void setSkittles(double inSkittles)
{
skittles = inSkittles;
}
public void setQuantity(int inQuantity)
{
quantity = inQuantity;
}
public double calcPrice(double candy, int quantity) // calculates a single order
{
price = candy * quantity;
return price;
}
public double calcTotal(double one, double two, double three) //calculates the total order, which will include taxes
{
subtotal = (one + two + three) * tax;
total = one + two + three + subtotal;
return total;
}
//Accessors: get/display methods
public double getDumdums()
{
return dumdums;
}
public double getSnickerballs()
{
return snickerballs;
}
public double getSweettarts()
{
return sweettarts;
}
public double getSkittles()
{
return skittles;
}
public int getQuantity() //gets how many pounds a customer wants
{
return qtyWanted;
}
public void displayMsg()
{
JOptionPane.showMessageDialog(null, "Tax for all items is: " + decimalf.format(tax));
JOptionPane.showMessageDialog(null,"Your total is: " + money.format (total));
JOptionPane.showMessageDialog(null, "Thank you for shopping at CandyLand!\n\t"
+ "Tell a friend!");
}
}

