This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes prompting for more input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "prompting for more input" Watch "prompting for more input" New topic
Author

prompting for more input

Dwayne Loving
Greenhorn

Joined: May 22, 2005
Posts: 9
Hello All,
I just posted this question in the wrong forum (advanced...YIKES!!) and need some serious assistance. I need to write a program that recognizes two classes in the same program and also prompt the user for additional input. The two classes (I think I might have) problem is getting it to prompt for additional input. any advice would be appreciated.

Thank You,
Dwayne
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1012
    
    3
Advice:
  • Go over to Java In General(adv) and remove the repeat request right now. People will find it here.
  • Tell us what your program is supposed to do. If the only requirements are what you've said so far, then try to come up with some functionality that would fit the bill. Stuck on even that? Tell us your first couple ideas and we'll try to determine they're too trivial or too adventurous. You have to decide what to do before how to do it.
  • Since, if I assume correctly, this is for a class, try doing as much of it yourself as you can before/between asking questions here. We're happy to help, but requests for someone to do your homework for you will get a chilly reception indeed.
  • Read at least the first post in the top, say, 20 subjects in this forum and see if any ask the same question.


  • Ryan
    [ May 24, 2005: Message edited by: Ryan McGuire ]
    Joe Ess
    Bartender

    Joined: Oct 29, 2001
    Posts: 8935
        
        9

    Dwayne is indeed taking a class. He posted such to the applet forum two days ago. I pointed him to our handy guide about How to Ask Questions the Smart Way, but he insists on asking others to do his work.


    "blabbing like a narcissistic fool with a superiority complex" ~ N.A.
    [How To Ask Questions On JavaRanch]
    Layne Lund
    Ranch Hand

    Joined: Dec 06, 2001
    Posts: 3061
    Originally posted by Dwayne Loving:
    Hello All,
    I just posted this question in the wrong forum (advanced...YIKES!!) and need some serious assistance. I need to write a program that recognizes two classes in the same program and also prompt the user for additional input. The two classes (I think I might have) problem is getting it to prompt for additional input. any advice would be appreciated.

    Thank You,
    Dwayne


    How to implement the requests for input depends a lot on what type of program you are writing. Is this a command-line program or a GUI?

    Layne


    Java API Documentation
    The Java Tutorial
    Pete Tyo
    Ranch Hand

    Joined: May 11, 2005
    Posts: 38
    You can try something like this...


    This is the kind of thing you need to use for cmis141.. okay.

    Pete
    Dwayne Loving
    Greenhorn

    Joined: May 22, 2005
    Posts: 9
    Contrary to what Joe thinks, I DO NOT want others to do my work. I made a mistake and posted the question in the wrong forum. When I realized it was incorrect, I tried correct it, but didn't know how to at the time. Thanks Joe for knowing that ALL beginners know how to do something when the first start out, appearently you did.
    Anyway,
    My program looks similiar to this segment code:
    private double enterDollars;
    //Instance Variables

    public double enterDollars() {
    return enterDollars;
    }
    But again, how would I put a "do-while" loop here or implement an "if/else" statement for it to prompt for additional input? Any GUIDANCE (Joe) would be appreciated.

    Dwayne
    Joe Ess
    Bartender

    Joined: Oct 29, 2001
    Posts: 8935
        
        9

    Originally posted by Dwayne Loving:
    Thanks Joe for knowing that ALL beginners know how to do something when the first start out, appearently you did.


    Woah, there buddy. I had a problem with the KIND of question you were asking. Not with where you were asking it. Your post in the applet forum read in its entirety:

    Need halp with typing a program for my Java class. I'm having a hard time writing the program. I'm going to write out the program and post it tomorrow so ANY ASSISTANCE will be helpful.

    Read your first post in this topic. You don't give us any information and ask for assistance. It looks to me like you are looking for a handout. Now your second post, that's more like it. Take a look at the Java Tutorial chapter on
    Control Flow Statements. It covers all the control statements in the Java language so you can choose the most appropriate.
    Dwayne Loving
    Greenhorn

    Joined: May 22, 2005
    Posts: 9
    Hello All (again),
    I believe I'm making some progress here with my program. I do have a few more questions regarding errors I received when compiling my program. I had a couple of lines that stated that there was an error and a "class" or "interface" expected. How can I find out what it is referring to? Secong error was (Indentifier) expected with an ^ under the parenthesis? Lastly, my segment code has an illegal start type? (ex. of what I wrote(if (int car==dodge) system.out.print("what is the next car:"
    Again any ASSISTANCE would be helpful. Need to figure this out on my own.

    Thanks

    Dwayne
    Nigel Browne
    Ranch Hand

    Joined: May 15, 2001
    Posts: 673
    Please post your code using the UBB code tags provided and also the output from your compilation errors. It makes it alot easier for people to help you that way
    Dwayne Loving
    Greenhorn

    Joined: May 22, 2005
    Posts: 9
    Hey Nigel,
    I guess what you mean by UBB code is to highlight what errors came with the compilation of my program(?).
    OK, the first error was Class or interface expected (Public Class Gift Collection). What is meant by class or Interface expected? Second, (indentifier) expected system.out.print ("enter gift: ");. under the first parenthesis in identifier, it has an ^ under it. Unable to locate where/what that is. Finally, Illegal start type If (int currency==Dollar). Wouldn't 2 equal signs (==) mean true in Boolean? So why would that be Illegal start type?
    Again Nigel, I hope this is what you were referring to, it not, keep in mind, I'm a beginner in Java and the whole computer language world.
    Thanks for your time,
    Dwayne
    [ May 26, 2005: Message edited by: Dwayne Loving ]
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Java is case sensitive, and I'm guessing that the errors you posted above are related to this. For example, "Public Class..." needs to be "public class..." Otherwise, Java won't recognize this as a class definition, and you'll get the error, "class or interface expected."

    "system" needs to be "System" and "If" needs to be "if".

    UBB Code tags are explained here:
    http://faq.javaranch.com/view?UseCodeTags


    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11444
        
      16

    What Nigel means by "UBB code tags" is the following:

    We want to see your source code - i.e. the java code you wrote. don't retype it in, because you're bound to make mistakes in the copying. cut and paste it into a new post in this thread.

    BUT... BEFORE you do that, look below the text box where you'd type this in. there are about 10 buttons below, labeled things like "URL", "EMAIL", etc. the important one here is the "CODE" button. if you click it once, you will see some text pasted into the textbox for you. it should look like
    [ code ][ /code ]

    only without the spaces. paste your code BETWEEN the tags. these basically tells the browser to not reformat what's between them - it will preserve your formatting.

    if you post your code, then post the exact error message, it will be most helpful in determining what the problem is and how to fix it.

    We're happy to help!!!


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Hentay Duke
    Ranch Hand

    Joined: Oct 27, 2004
    Posts: 198
    Again any ASSISTANCE would be helpful. Need to figure this out on my own.

    Interesting!

    But anyway. As everyone else is pointing out you need to post your actual code, "My program looks Similar to this segment code:" does no good. And post the actual error messages and people here will be more than happy to point you in the right direction.
    [ May 27, 2005: Message edited by: Hentay Duke ]
    Dwayne Loving
    Greenhorn

    Joined: May 22, 2005
    Posts: 9
    Fred and Hentay,
    Here's what I wrote for my program. I changed it up from currency to gifts and changed it from if/else to switch case. At the bottom is the error message that keeps coming up when I compile it:
    import java.util.*;

    public class gifts {
    //main(): application entry point
    public static void main(String[] args) {
    final int USDollars = 1;
    final int Euros = 2;
    final int Yen = 3;
    final int TotalSavings = 4;

    //Instance Variables
    public void USDollars() {
    return USDollars;
    }

    public void Euros() {
    return Euros;
    }

    public void Yen() {
    return Yen;
    }

    public double TotalSavings() {
    return TotalSavings;
    }

    //set up input
    Scanner stdin = Scanner.create(system.in);
    }
    //main(): application entry point
    public Class GiftsCollection {
    //get conversion information of interest
    public static void main(String[] args) {
    System.out.println("");
    System.out.print("Enter gift: ");
    int gift = stdin.nextInt();
    System.out.print("Enter Amount: ");
    int amount = stdin.nextInt();
    }

    // Validate Input
    if (int gift < 4) {
    system.out.println("Bad Request: " + cmd);
    System.exit(1);
    }

    //Use gift and Amount to determine dollars
    int gift;
    switch (gift) {
    case USDollars:
    double USDollars = (int amount * 1);
    break;
    case Euros:
    double Euros = (int amount * 1.24);
    break;
    case Yen:
    double Yen = (int amount *.0092);
    break;
    case TotalSavings:
    double TotalSavings = sum(double USDollars, double Euros, double Yen)
    }


    ERROR MESSAGE: illegal start type public void USDollars

    Dwayne
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    You cannot define methods within other methods, as you're trying to do by putting method definitions inside of main. This is why you're getting an "illegal start type."

    Please review the following page regarding UBB code tags for formatting (this will make it much easier for others to read your code and more likely that you'll get a helpful reply):
    http://faq.javaranch.com/view?UseCodeTags
    [ May 28, 2005: Message edited by: marc weber ]
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Dwayne, I'll tell you now: The code you've posted is going to be very difficult to debug and get working.

    The best way to write a program is to start small and compile often. Write a few lines of code, compile it, then fix any problems. When you get it to work, then add a few more lines and compile again. This way, you know exactly where the problem is (and you'll be in a much better position to ask for help).

    For this program, I would start by writing code that asks the user for an integer, then prints out what they input. Maybe 4 lines of code inside a main method. That's all. When you get this to work, then add code that converts the integer to a currency type (USD, Euro, etc.) and displays that. When this works, then add more code...
    [ May 28, 2005: Message edited by: marc weber ]
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: prompting for more input