Results 1 to 17 of 17
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Program about choosing category

  1. #1
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Program about choosing category

    Hi all !
    I'm putting the code:

    import java.util.Scanner;

    public class Custom {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Select category: \n 1- Salads \n 2-Soups \n 3-Hot Dishes \n 4-Dessert \n 5-Juices");

    }
    }

    The user presses corresponding number 1, 2, 3, ... then must be downloaded another list. How must I do it?

    Thank you in advance !!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    What have you tried? Where are you stuck? Check out the API for useful functions.

    Java Platform SE 6
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    Thanks for your reply.
    I've tried to create Keyboard event, but no result.
    What do you suggest to do?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    I suggest you go to the link I gave you, navigate to the Scanner class, then read up on the methods you have at your disposal. Try something out and write some code.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    Ok, thanks so much.
    What about KeyListener?? Is it useful in this case?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    Quote Originally Posted by moony View Post
    Ok, thanks so much.
    What about KeyListener?? Is it useful in this case?
    KeyListeners are used with a GUI. The code you provided does not create a gui; it is run via the command prompt. You can't add a KeyListener to the system command prompt.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    Ok, thanks for you attention !!!
    I'll do as you said - using Scanner, then I'll put the code.

    Thanks so much.

  8. #8
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    Hi all.
    These days I've tried Scanner methods, but I didn't find any method, which can solve my problem.
    What can I do??
    Please help me.

    Best regards,
    moony

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    Please provide an SSCCE along with a specific technical question. I really have no idea what you've tried or where you're stuck, so I'd just be guessing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    Thanks for your attention ! I really need your help, because I haven't anyone who can help me with java.
    I'm going to try explain my problem once more.

    My program must display the following, for example:

    Select category:
    1-Fruits
    2-Vegetables
    3-meat
    4-juice
    The user press 1 or 2 or 3 or 4, then is displayed corresponding database of category. For example, if is pressed 1, then it is displayed the following database from SQL:

    1 Apple 5$ 1kg
    2 Apricot 10$ 1kg
    3 Pear 7$ 1kg
    . . .
    . . .
    .
    .
    .
    .

    And so on.
    What do you suggest?

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    You've posted your assignment, but you haven't actually posted any useful code. I'd recommend googling something like "java scanner tutorial" if you don't understand how to use it. Then make an attempt and post an SSCCE here along with what you expected to happen versus what is actually happening.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    I've looked some scanner tutorials, but I don't find such method, which allow to create Keyboard event on 1, 2, ... .
    I just need to know which code create an event on pressing 1, 2, ... ??

    Thanks in advance.

  13. #13
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    You don't create events for a Scanner like you do with a KeyListener. You have to read in the input and check it yourself. Surely the tutorials covered that?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #14
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    As I understood it's possible to use if statement as this:

    import java.util.Scanner;

    public class Custom {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Select category: \n 1- Salads \n 2-Soups \n 3-Hot Dishes \n 4-Dessert \n 5-Juices");
    int cg = scanner.nextInt();
    if (cg==1) System.out.println("You choose 1st category");
    }
    }

    Am I in the right way??

  15. #15
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    And if this is right, then I must create each statement for 1, 2, 3, ... keyboard event. In other words, if user press 1, I must write code to import database from SQL.

    Waiting for your comments, then I try to write code.

  16. #16
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,940
    Rep Power
    8

    Default Re: Program about choosing category

    What happened when you ran that code?

    Quote Originally Posted by moony View Post
    Waiting for your comments, then I try to write code.
    This is backwards. Code first, try something out, then ask questions when you get stuck.
    Fubarable likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #17
    moony is offline Member
    Join Date
    May 2012
    Posts
    23
    Rep Power
    0

    Default Re: Program about choosing category

    OK, next I'll put the code. Thanks so much and excuse me, if I ask very elementary questions...
    I want to be very good in java...

    Thanks once more, you help me so much !!

Similar Threads

  1. Choosing db option
    By Levian in forum JDBC
    Replies: 6
    Last Post: 03-17-2012, 02:21 AM
  2. Need guidance in choosing the appropriate technology
    By mstaszew in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 10-20-2011, 05:25 AM
  3. Replies: 0
    Last Post: 07-15-2010, 01:23 PM
  4. Need advise for choosing book
    By Teodor__b in forum New To Java
    Replies: 2
    Last Post: 02-19-2010, 01:13 PM

Posting Permissions

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