Results 1 to 4 of 4
  1. #1
    tdhubb2012 is offline Member
    Join Date
    Mar 2015
    Posts
    2
    Rep Power
    0

    Default I need help with writing this program!!!

    The code I have now is:

    import java.util.Scanner;

    public class Lab6
    {
    public static void main(String [] args)
    {
    Scanner scan = new Scanner (System.in);
    String age;
    int money;
    Double change;
    Double years;
    System.out.println("Please type customer's age: "+ age);
    Double DoubleAge= Double.parseDouble(age);
    Double DoubleMoney= Double.parseDouble(money);
    years = (DoubleAge - 21);
    change = (DoubleMoney - 5);

    if (DoubleAge >= 21)

    {
    if (DoubleMoney >= 5.00)
    {
    System.out.println("Congratulations, you can have some beer.");
    System.out.println("Thank you for your patronage.");
    }
    else
    {
    System.out.println("Sorry, you need $"+change+"more");
    System.out.println("Thank you for your patronage.");
    }
    }
    else
    {
    System.out.println("No Bear for you!");
    System.out.println("Come back in" +years+ "years");
    System.out.println("Thank you for your patronage.");

    }
    }
    }

    My question is HOW CAN I DEFINE age AND money so this will work?


    Write a Java program to help a convenience store clerk decide whether or not to sell beer to a customer. Beer can only be sold to somebody who is 21 years old or more, and has enough money (beer costs $5.00). If the customer is too young, tell them how many years they must wait before returning. If they have too little money, tell them how much more is needed.

    Here is a sample run of the program:

    Please type customer age: 25
    Type customer cash amount: 3.25
    Sorry, you need $1.75 more.
    Thank you for your patronage.

    Here is another sample run:

    Please type customer age: 9
    No beer for you!
    Come back in 12 years.
    Thank you for your patronage.

    Here is yet another sample run:

    Please type customer age: 102
    Type customer cash amount: 6.75
    Congratulations, you can have some beer.
    Thank you for your patronage.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: I need help with writing this program!!!

    Your code is difficult to read. Pleas place the code between [code][/code] tags to preserve formatting.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    tdhubb2012 is offline Member
    Join Date
    Mar 2015
    Posts
    2
    Rep Power
    0

    Default Re: I need help with writing this program!!!

    Java Code:
    import java.util.Scanner;
    
    public class Lab6
    {
        public static void main(String [] args)
        {
    		Scanner scan = new Scanner (System.in);
            String age;
            int money;
            Double change;
            Double years;
            System.out.println("Please type customer's age: "+ age);
            Double DoubleAge= Double.parseDouble(age);
            Double DoubleMoney= Double.parseDouble(money);
            years = (DoubleAge - 21);
            change = (DoubleMoney - 5);
    
            if (DoubleAge >= 21)
    
                {
                if (DoubleMoney >= 5.00)
                    {
                    System.out.println("Congratulations, you can have some beer.");
                    System.out.println("Thank you for your patronage.");
                    }
                else
                    {
                    System.out.println("Sorry, you need $"+change+"more");
                    System.out.println("Thank you for your patronage.");
                    }
                }
            else
                {
                System.out.println("No Bear for you!");
                System.out.println("Come back in" +years+ "years");
                System.out.println("Thank you for your patronage.");
    
                }
        }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: I need help with writing this program!!!

    Quote Originally Posted by tdhubb2012 View Post
    I need help with writing this program!!!
    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. HELP :( I am writing a NewtonRaphson program.
    By sithclone3 in forum New To Java
    Replies: 12
    Last Post: 07-17-2014, 07:10 AM
  2. help in writing a program?
    By baldy100 in forum New To Java
    Replies: 3
    Last Post: 01-10-2013, 04:06 PM
  3. Help with writing my own program
    By DMarsh12 in forum New To Java
    Replies: 4
    Last Post: 12-30-2011, 03:34 AM
  4. Writing a program(HELP!! It's due tommorrow!!!!!)
    By mk3823 in forum New To Java
    Replies: 9
    Last Post: 10-24-2008, 11:13 AM
  5. how begin with writing a new program ?
    By dimitrist in forum New To Java
    Replies: 11
    Last Post: 05-13-2008, 03:49 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
  •