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

  • SEARCH
  • Home
  • 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 8808517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:38:39+00:00 2026-06-14T02:38:39+00:00

public static double numBeers() { String numBeersStr; double numBeers; numBeersStr = JOptionPane.showInputDialog(How many beers

  • 0
public static double numBeers()
{
    String numBeersStr;
    double numBeers;

    numBeersStr = JOptionPane.showInputDialog("How many beers would you like?");

    numBeers = Double.parseDouble(numBeersStr);

    if (numBeers < 3 || numBeers > 6)
    {
        numBeersStr = JOptionPane.showInputDialog("You must pick 3-6 beers");
        numBeers = Double.parseDouble(numBeersStr);
    }

    return numBeers;
}

public static double beerPrice(double theBeerBrand)
{

    double beer = 0;
    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 static double beerBrand(double theNumBeers )
{   
    String beerTypeStr;
    double count = 1, total = 0, beerType, beeer = 0;

    while (count <= theNumBeers)
    {    
        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);
            // method to be invoked/called------> beeer = beerPrice(beerType);


        count++;
    }    

    total += beeer;

    return total;

I’m trying to invoke the beerPrice method within the beerBrand method while loop. Each time the program prompts the user what type of beer they would like, that type of beer is added to the total and then the question is asked again for the same amount of times equivalent to the number of beers the user would like. I’m pretty sure I solved the problem of prompting the user the same number of times equivalent to the number of beers they would like, I’m just not getting the output I desire.

It would be much appreciated if anyone had an idea as how to capture that type of beer and add it to the total so then I’m able to work with the total for discount prices and final prices. I do not want to use any arrays or anything more complicated as this is a practice program for a chapter test that hasn’t touched on arrays or the like. Thank you much for any help given.

  • 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-14T02:38:40+00:00Added an answer on June 14, 2026 at 2:38 am

    You can keep that line which is valid:

    beeer = beerPrice(beerType);
    

    However, you need to add the price to your total each time you loop, so bring the corresponding line back into your while:

    while (count <= theNumBeers) {    
        beerTypeStr = JOptionPane.showInputDialog(...);
        beerType = Double.parseDouble(beerTypeStr);
        beeer = beerPrice(beerType);
        total += beeer;
    
        count++;
    }
    

    It is also good practice to limit the scope of your variables as much as possible – and you while is a for really, and I suppose you generally order whole beers, so you could use an int instead of a double for the number of beers. You could therefoer refactor your method like this:

    public static double beerBrand(int theNumBeers) {   
        double total = 0;
    
        for (int count = 0; count < theNumBeers; count++) {    
            String beerTypeStr = JOptionPane.showInputDialog(...);
            double beerType = Double.parseDouble(beerTypeStr);
            total += beerPrice(beerType);
        }
    
        return total;
    }
    

    Note: I have not checked the rest of your code.

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

Sidebar

Related Questions

public static void Main() { Dictionary<string, double> values = new Dictionary<string, double>(); values.Add(a, 0.002);
public static String formatAmountUpToTwoDecimalNumber(String amount) { if(amount==null || .equals(amount)) { return ; } Double
In the following program class ZiggyTest2 { public static void main(String[] args){ double x
What does the following function perform? public static double CleanAngle(double angle) { while (angle
public static class TestTask extends AsyncTask<Void, Integer, Integer> { private String stacktrace; public TestTask
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public static void main(String[] args) { // TODO Auto-generated method stub BufferedReader br1 =
public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);
public static string RatingCalculator(int input) { if (input < 10) { return string.Empty; }
I would like to format numbers of type double with a German locale in

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.