Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:04:48+00:00 2026-06-15T13:04:48+00:00

import javax.swing.JOptionPane; public class BeerStoreBP { private String name; private double custAge; private double

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:04:49+00:00Added an answer on June 15, 2026 at 1:04 pm

    Rewritten:

    import javax.swing.JOptionPane;
    
    public class BeerStoreBP {
    
    private String name;
    
    private double custAge;
    
    private double numBeers = 0;
    
    private double beerDisc = 0;
    
    private double total = 0;
    
    // This only exists in one method.  There is no need for it to be global
    //private double beerType = 0;
    
    // This only exists in one method.  There is no need for it to be global    
    //private double theBeerBrand;
    
    // This only exists in one method.  There is no need for it to be global    
    //private double total = 0;
    
    // This only exists in one method.  There is no need for it to be global
    //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;
    }
    
    // Your functionality is parsed by your dialog.  There is no need for this.
    //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(int beerBrand)
    {
    
        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;
    
    
        double beerPrice;
    
           if (beerBrand == 1)
               beerPrice = LAGIMRED;
    
           else if (beerBrand == 2)
               beerPrice = DESINIPA;
    
           else if (beerBrand == 3)
               beerPrice = BELBEBRN;
    
           else if (beerBrand == 4)
               beerPrice = SCHOATST;
    
           else if (beerBrand == 5)
               beerPrice = BOULFHSAISN;
    
           else 
               beerPrice = GANDANCPRTR;        
    
           return beerPrice;
    
    }
    
    public void calcBeerTotal()
    {
        String beerTypeStr;
        double count = 1;
        double beerPrice;
        // No need to be double
        int beerBrand;
    
        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");
            beerBrand = Integer.parseInt(beerTypeStr);
            beerPrice = calcBeerPrice(beerBrand);
            total += beerPrice;
            count++; 
    
        }
    
    }
    
    public double getBeerTotal()
    {
        return total;
    }
    
    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;
    
    }
    
    
    }
    

    This is in a working state, but may I recommend you take the UI portions out of this class and include them elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import javax.swing.JOptionPane; public class RotateArrayCircularLL { private Node head=null; public void init() { int
import java.util.scanner; import javax.swing.JOptionPane; public class FirstHomeJavaApplet{ public static void main(String[] args){ int num1=2;
import java.io.*; import javax.swing.JOptionPane; import java.util.*; public class lesson { static void printAll(ArrayList<String> names,
import javax.swing.JOptionPane; public class PredefinedClass { public static void main(String[] args){ do{ String input
import javax.swing.JOptionPane; public class Mate { double suma (double x1,double x2) {return x1+x2;} double
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class CandleLine { public static void main(String[] args) {
import javax.swing.JOptionPane; public class Insurance { final static String INPUT_GENDER = Please enter your
Here is my code... import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class
import javax.swing.*; public class test { public static void main(String[] args) throws Exception {
//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.