Results 1 to 10 of 10
  1. #1
    prendergast36 is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default I cant figure out my "if "else" statements any help?

    //*In the process of selling lemonade, you have three possibilities:

    Enough glasses of lemonade are already available to fill the request. In this case, simply adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, but have enough ingredients to make more lemonade... In this case, makeLemonade() and then adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, and do not have enough ingredients to make more lemonade... In this case, do not make any adjustments to the fields and do not sell any lemonade.
    *//

    Java Code:
    public class LemonadeStand
    {
         // instance variables - During the day, you will make lemonade by the gallon and sell lemonade by the glass. 
        //You will also need to set a price for a glass of lemonade each day (hot days might mean higher prices!). 
        //As you make and sell lemonade through the day, you need to keep up with how many glasses of lemonade you 
        //have available to sell, make adjustments to the amount of the ingredients and empty glasses, and keep up
        //with how much money you have received. That's the general idea, now let's get started one step at a time.
        //replace the example below with your own
            private int lemons;
            private int water;
            private int sugar;
            private int emptyGlass;
            private int pricePerSale;
            private int cents;   
            private int fullGlass;
    
        /**
         * Constructor for objects of class lemonadeStand
         */
        public LemonadeStand(int numOfLemons, int galOfWater, int cupsOfSugar, 
        int cupsOfWater,int emptyGlasses, int totalPrice)
            {
                lemons= numOfLemons;
                water= galOfWater;
                sugar= cupsOfSugar;
                emptyGlass= emptyGlasses;
                pricePerSale= totalPrice;
                cents= totalPrice-cents;
        
            }
    
        public int totalPrice()
            {
                return fullGlass;
            }
    
      // method to make lemonade
      
     
        public int makeLemonade ()
            {
                if (lemons>=6 && water>=1 && sugar>= 1 && emptyGlass>=8 && fullGlass<=8)
          {     
               lemons = lemons - 6;
               water = water-1;
               sugar = sugar-1;
               emptyGlass = emptyGlass-8;
               fullGlass= fullGlass+8;
            }
           
               
                    {System.out.println ("You need more supplies");
                    
                    }
    
                    System.out.println ("you have " + emptyGlass +"  full glasses to sell");
    
            }
    
                     
        // method to sell lemonade
                      
        public int sellLemonade(int numberOfGlasses)
            {
               if (fullGlass>=8){
                   //math for creating price of total sale
                   fullGlass = fullGlass - numberOfGlasses;
                   pricePerSale= numberOfGlasses+fullGlass* cents;
                   return pricePerSale;
                }       
                else makeLemonade(lemons>=6 && water>=1 && sugar>= 1 && emptyGlass>=8 && fullGlass<=8);
                {
                         return makeLemonade;
                        }
                        
                        
               
            
    
                 System.out.println  ("You have " + fullGlass + " full glasses available, Remaining Balance is ."+ balance +" cents");
                }
            }
    Last edited by Fubarable; 09-16-2011 at 11:39 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: I cant figure out my "if "else" statements any help?

    Quote Originally Posted by prendergast36 View Post
    //*In the process of selling lemonade, you have three possibilities:

    Enough glasses of lemonade are already available to fill the request. In this case, simply adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, but have enough ingredients to make more lemonade... In this case, makeLemonade() and then adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, and do not have enough ingredients to make more lemonade... In this case, do not make any adjustments to the fields and do not sell any lemonade.
    *//

    Java Code:
    public class LemonadeStand
    {
         // instance variables - During the day, you will make lemonade by the gallon and sell lemonade by the glass. 
        //You will also need to set a price for a glass of lemonade each day (hot days might mean higher prices!). 
        //As you make and sell lemonade through the day, you need to keep up with how many glasses of lemonade you 
        //have available to sell, make adjustments to the amount of the ingredients and empty glasses, and keep up
        //with how much money you have received. That's the general idea, now let's get started one step at a time.
        //replace the example below with your own
            private int lemons;
            private int water;
            private int sugar;
            private int emptyGlass;
            private int pricePerSale;
            private int cents;   
            private int fullGlass;
    
        /**
         * Constructor for objects of class lemonadeStand
         */
        public LemonadeStand(int numOfLemons, int galOfWater, int cupsOfSugar, 
        int cupsOfWater,int emptyGlasses, int totalPrice)
            {
                lemons= numOfLemons;
                water= galOfWater;
                sugar= cupsOfSugar;
                emptyGlass= emptyGlasses;
                pricePerSale= totalPrice;
                cents= totalPrice-cents;
        
            }
    
        public int totalPrice()
            {
                return fullGlass;
            }
    
      // method to make lemonade
      
     
        public int makeLemonade ()
            {
                if (lemons>=6 && water>=1 && sugar>= 1 && emptyGlass>=8 && fullGlass<=8)
          {     
               lemons = lemons - 6;
               water = water-1;
               sugar = sugar-1;
               emptyGlass = emptyGlass-8;
               fullGlass= fullGlass+8;
            }
           
               
                    {System.out.println ("You need more supplies");
                    
                    }
    
                    System.out.println ("you have " + emptyGlass +"  full glasses to sell");
    
            }
    
                     
        // method to sell lemonade
                      
        public int sellLemonade(int numberOfGlasses)
            {
               if (fullGlass>=8){
                   //math for creating price of total sale
                   fullGlass = fullGlass - numberOfGlasses;
                   pricePerSale= numberOfGlasses+fullGlass* cents;
                   return pricePerSale;
                }       
                else makeLemonade(lemons>=6 && water>=1 && sugar>= 1 && emptyGlass>=8 && fullGlass<=8);
                {
                         return makeLemonade;
                        }
                        
                        
               
            
    
                 System.out.println  ("You have " + fullGlass + " full glasses available, Remaining Balance is ."+ balance +" cents");
                }
            }

    What's your specific question? Are you getting a compiler error? Is part of the code not working? All I see is an assignment and a code dump. The more useful information you can tell us, the better we'll be able to understand your problem and be able to help you. A rule of thumb is to try to put as much effort into asking your question as you'd like a volunteer to put in helping you.
    Last edited by Fubarable; 09-16-2011 at 11:40 PM.

  3. #3
    prendergast36 is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default Re: I cant figure out my "if "else" statements any help?

    Sorry Yes im getting a method makeLemonade in class lemonadeStand cannot be applied to given types;
    required: no arguments found" boolean reason: actual and formal argument lists differ in length.

    im new to programming and having a world of difficulties

  4. #4
    prendergast36 is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default Re: I cant figure out my "if "else" statements any help?

    ERROR: method makeLemonade in class LemonadeStand cannot be applied to given types;
    required: no arguments found: boolean reason: actual and formal argument lists differ in length.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: I cant figure out my "if "else" statements any help?

    Quote Originally Posted by prendergast36 View Post
    Sorry Yes im getting a method makeLemonade in class lemonadeStand cannot be applied to given types;
    required: no arguments found" boolean reason: actual and formal argument lists differ in length.

    im new to programming and having a world of difficulties
    The error is telling you what is wrong with that part of your program. The makeLemonade method is defined to take no parameters, but you're trying to call it by passing in a boolean parameters. You can only call a method the same way it's defined. If it is defined to take an int parameter, you must pass an int in when calling it. If it's defined to take in no parameters, then you must call it with no parameters. If it is overloaded and may or may not take parameters, then you have more flexibility, but that's not the case here.

    Other suggestions: fix your formatting as your indentation and brace use is awful and is just making it harder for you and others to understand your code.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: I cant figure out my "if "else" statements any help?

    Going through your code, it all looks a bit confused. Which part of the code was given to you by your instructor and which part is your code that you've created? Are you sure that the two methods makeLemonade and sellLemonade are supposed to return ints? Where's your main method? Where's your full assignment instructions?

  7. #7
    prendergast36 is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default Re: I cant figure out my "if "else" statements any help?

    I had to write the code, directions are:

    Develop the LemonadeStand constructor
    Description of the LemonadeStand

    A LemonadeStand object will represent one day of activities. In your lemonade stand, you start each day with some number of lemons, several gallons of water, several cups of sugar, and lots of empty glasses. Obviously, you will need fields in your class for each of these items. You also need a field for the price for a glass of lemonade each day. Money will be stored in cents.

    As lemonade is sold through the day, your class will need to keep up with how many glasses of lemonade are available to sell. Lemonade will be made by the gallon but sold in 16-ounce glasses (a gallon is 128 ounces). The easiest way to represent how much lemonade you have available for sale is to create a field that represents the number of glasses of lemonade that are currently made, the unit of measure being a "16-ounce glass". Being a wise, cost-conscious business person, you will make lemonade only when you sell a glass that is not already made.

    Finally, your class should keep up with how much money you have made during the day.

    Write a method to makeLemonade.
    Activity Procedure

    Your recipe for lemonade is: mix 6 squeezed lemons, one gallon of water, and one cup of sugar. Your method should subtract from the number of lemons, the amount of water, the amount of sugar, and the number of empty glasses. Also, this method should add to the number of glasses of lemonade available for sale.
    makeLemonade should make sure that you have enough ingredients (lemons, water, sugar, empty glasses) to make a gallon of lemonade before attempting to update the fields. If you do have the ingredients, make a gallon of lemonade; otherwise, make no lemonade.
    makeLemonade should return the number of lemonade glasses that are available for sale after making (or not making) more lemonade.
    Test makeLemonade() thoroughly to make sure it works.
    To test a method, you start with "normal" data. For example, construct a Lemonade Stand with 18 lemons, 5 gallons of water, 8 cups of sugar, 100 empty glasses, and sell lemonade for 50 cents/glass. Open the Object Inspector for this stand to see if the constructor did it's job correctly. Then, invoke the makeLemonade() method. The Object Inspector should show you that you have 12 lemons, 4 gallons of water, 7 cups of sugar, and 92 empty glasses left. How many glasses of lemonade were produced? Is that correct?
    Continue invoking makeLemonade() until the number of lemons is 6 and make sure the results are correct each time.
    The next step in testing a method is to try "boundary" data with the method. "Boundary" data is valid data that may be special cases. In this case, having 6 lemons is a good "boundary" condition. Why?
    The last step in testing a method is to use "invalid" data. For example, you can't make lemonade with no lemons. 0 lemons should be the state of your lemonade stand now. Invoke makeLemonade() and see what happens.
    Remove that LemonadeStand object and create a new one of your choosing. Go through a similar testing process to see if you get correct results.

    Write a method to sellLemonade
    Activity

    Write a method named sellLemonade that adjusts the number of available glasses of lemonade and updates your bank when someone buys lemonade. Pass a parameter for how many glasses the customer is purchasing. You may assume that the customer will not buy more than 8 glasses of lemonade at a time.

    In the process of selling lemonade, you have three possibilities:

    Enough glasses of lemonade are already available to fill the request. In this case, simply adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, but have enough ingredients to make more lemonade... In this case, makeLemonade() and then adjust the number of glasses available and the amount of money you have made.
    You do not have enough glasses of lemonade made to fill the request, and do not have enough ingredients to make more lemonade... In this case, do not make any adjustments to the fields and do not sell any lemonade.
    Your method should return the actual number of glasses sold.

    Test the method thoroughly to make sure it works.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: I cant figure out my "if "else" statements any help?

    Suggestion: you may want to start over as it may be quicker and cleaner this way. If you do, be sure to do each method one at a time and to make sure that the method just created works and works well before working on the next. In fact you should compile your code after adding each line and fix all compilation errors before adding any new lines. Make sure you understand each bit of instruction before trying to code it. If you are confused about a step, come on back and we can help clarify it for you.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: I cant figure out my "if "else" statements any help?

    Also, if it were my program, I'd get all println's out of the two methods, makeLemonade and sellLemonade. I'd just return the ints as instructed and let whatever code that calls these methods interact with the user with println's or whatever. Also, don't forget that if your method says it is going to return an int, it *must* return an int.

  10. #10
    prendergast36 is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default Re: I cant figure out my "if "else" statements any help?

    Okay, Thank you very much for looking over this. It was working until I added this last "if" "else" section.

Similar Threads

  1. Replies: 0
    Last Post: 06-24-2011, 08:14 PM
  2. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •