• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prompting for more input

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
     
    Bartender
    Posts: 9626
    16
    Mac OS X Linux Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 3061
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
     
    Ranch Hand
    Posts: 38
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You can try something like this...


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

    Pete
     
    Dwayne Loving
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 9626
    16
    Mac OS X Linux Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Ranch Hand
    Posts: 704
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 ]
     
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    lowercase baba
    Posts: 13089
    67
    Chrome Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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!!!
     
    Ranch Hand
    Posts: 198
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 ]
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic