import javax.swing.JOptionPane;
public class BeerStoreBP
{
private String name;
private double custAge;
private double numBeers = 0;
private double beerDisc = 0;
private double beerType = 0;
private double theBeerBrand;
private double total = 0;
private double beer = 0;
public void setAge(double theAge)
{
custAge = theAge;
}
public void setName(String theName)
{
name = theName;
}
public void setNumBeers(double theNumBeers)
{
numBeers = theNumBeers;
}
public void setBeerType(double theBeerType)
{
beerType = theBeerType;
}
public double getAge()
{
return custAge;
}
public String getName()
{
return name;
}
public double getNumBeers()
{
return numBeers;
}
public double calcNumBeersValid()
{
String numBeersStr;
while (numBeers < 3 || numBeers > 6)
{
numBeersStr = JOptionPane.showInputDialog("You must pick 3-6 " +
"beers");
numBeers = Double.parseDouble(numBeersStr);
}
return numBeers;
}
public double calcBeerPrice()
{
final double LAGIMRED = 1.90;
final double DESINIPA = 2.00;
final double BELBEBRN = 1.80;
final double SCHOATST = 2.50;
final double BOULFHSAISN = 2.75;
final double GANDANCPRTR = 1.75;
if (theBeerBrand == 1)
beer = LAGIMRED;
else if (theBeerBrand == 2)
beer = DESINIPA;
else if (theBeerBrand == 3)
beer = BELBEBRN;
else if (theBeerBrand == 4)
beer = SCHOATST;
else if (theBeerBrand == 5)
beer = BOULFHSAISN;
else
beer = GANDANCPRTR;
return beer;
public double calcBeerTotal()
{
String beerTypeStr;
double count = 1;
while (count <= numBeers)
{
beerTypeStr = JOptionPane.showInputDialog("Please choose between "
+ "these fine selections:\n1 - Lagunitas Imperial Red - " +
"$1.90\n2 - Deschutes Inversion IPA - $2.00\n3 - " +
"Bell's Best Brown Ale - $1.80\n4 - Schlafly's Oatmeal " +
"Stout - $2.50\n5 - Boulevard's Farmhouse Saison - $2.75"
+ "\n6 - Gandy Dancer Porter - $1.75");
beerType = Double.parseDouble(beerTypeStr);
beerType = theBeerBrand;
total += beer;
count++;
}
return total;
}
public double getBeerTotal()
{
double theTotal;
theTotal = total;
return theTotal;
}
public double calcBeerDisc()
{
if (numBeers == 6)
beerDisc = .10;
else if (numBeers >= 4)
beerDisc = .05;
else
beerDisc = .00;
return beerDisc;
}
public double calcFinalPrice()
{
double finalPrice;
finalPrice = total-(total * beerDisc);
return finalPrice;
}
Noob here, so please shed some mercy. The point of the above program is to gather the amount of beers(must be 3-6), provide the customer with a choice for each beer, calculate the total amount of beers, and apply a discount(depends on # of beers). Pretty simple stuff, yet I’ve hit a brick wall.
My problem lies with calculating the final price. I can’t seem to figure out why nothing from by calcBeerTotal method is getting passed to my calcFinalPrice method. My output displays the amount of beers just not the final price.
So my main question is: do I need some sort of setter and getter method for my calc methods? I’ve tried some setter and getter methods and I still wasn’t getting a final price (method located above calcBeerDisc). I’m of limited programming knowledge so please keep from getting any more complicated than what I’ve written. If it’s something aside from setters and getters please keep away from arrays and the like as I do not fully understand them either. Any help is much appreciated!
Rewritten:
This is in a working state, but may I recommend you take the UI portions out of this class and include them elsewhere.