Results 1 to 8 of 8
  1. #1
    Alvaro is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default how to get input from User

    Hello,

    well. I used years ago the Savitch class to get input from the user. but it was working on a Unix system which should not make any difference if working with windows at all. I have now my own class to compile plus the Savitch.java file both in the very same folder. I compiled the Savitch java of course, but my file called FirstProgram.java will keep on saying that Error(14,24): SavitchIn not found in class oracle.FirstProgram but if it has it in its same folder.! I have also included the import SavitchIn.*; statement at the beginning.

    I heard that after JDK 5 there is a standard way to get input from the user. In any case, how can I get that?

    I am using the Jdeveloper 11 from Oracle, as an editor ( a very good one by the way)

  2. #2
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    I dont know if this is the answer youre looking for but in our programs ONE way of getting user input would be to use the JOptionPane

    First you would have to import it at the top of your program:

    Java Code:
    javax.swing.JOptionPane;
    (It might be a little different than that)

    Then you could get input like:

    Java Code:
    String holdInputHere = JOptionPane.showInputDialog(null, "Please enter your name here")
    Thats an example, read about the JOptionPane to be sure though.

  3. #3
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    You can use the scanner class..
    Java Code:
    import java.util.Scanner;
    then in the program:
    Java Code:
    public void scanInput() {
         Scanner scan = new Scanner(System.in);
         String usrInput;
    
         System.out.print("Enter the input");
         usrInpt = scan.next();
    }
    The Java Docs for Scanner class are located here.
    You just got T4NK3D!
    Adonrcicg to rcesraeh the haumn mnid is clbapae of rdanieg tihs. -Jvaa Sun Moricyssemts-

  4. #4
    Alvaro is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    thank you, yes I managed to do it both ways. One through Scanner and the other through the Savitch class. The problem was that the IDE did not have the console enabled and it was not straightforward were to activate it.
    As per the other error I got that it could not find the class etc, it needed to be added the oracle word, so as to import oracle.SavitchIn.*;

    As per the OptionPane, yes, that is, as the name says :) an option. Thank you both for your help.
    (definitively it is a hard earned way this programming learning...)
    Alvaro

  5. #5
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    How about the console? and notepad/kwriter?
    freedom exists in the world of ideas

  6. #6
    kliane's Avatar
    kliane is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    same prob in here.. pls help me with my code..

    geting user input (number)


    im new to java.. i need help in getting the user's input.
    i need that Number that the user will input for me to use it for calculation.. pls do help me now..

    my code is here,..

    thanks..

    u can send me msgs at klianelics08@gmail.com

    i need replies now ryt here.. thanx a lot..

    /*

    Program Name : Fire law regulations
    Description : This program will determine whether a meeting room is in violation of fire law regulation. maximum room capacity is 50.
    */


    class Fire
    {
    public static void main(String[] args)
    {

    //DECLARATION OF VARIABLES


    int MaxRoomCapacity=50;
    int NumOfPeopleNeeded; // in case the ppol attended is less than the max rum capacity
    int NumOfPeopleEx; // number of ppol that will be excluded in case ppol attended is more than max rum capacity.


    //GET INPUT

    //cant right something in here.. help me pls


    //CALCULATIONS

    if(NumOfPeopleAttended>=MaxRoomCapacity)
    {

    NumOfPeopleEx=NumOfPeopleAttended-MaxRoomCapacity;

    System.out.println(" ");
    System.out.println("\tThe maximum room capacity is " + MaxRoomCapacity);
    System.out.print("\t");
    System.out.print(NumOfPeopleAttended);
    System.out.println(" people will be attending.");
    System.out.println(" ");
    System.out.println("\tANNOUNCEMENT!!!");
    System.out.println("\tThe meeting cannot be held as planned due to fire regulations.");
    System.out.print("\t");
    System.out.println(NumOfPeopleEx + " people must be excluded in order to meet the maximum room capacity");

    }

    else
    {
    NumOfPeopleNeeded=MaxRoomCapacity-NumOfPeopleAttended;

    System.out.println(" ");
    System.out.println("\tThe maximum room capacity is " + MaxRoomCapacity);
    System.out.print("\t");
    System.out.print(NumOfPeopleAttended);
    System.out.println(" people will be attending.");
    System.out.println(" ");
    System.out.println("\tANNOUNCEMENT!!!");
    System.out.println("\tIt is legal to hold the meeting.");
    System.out.print("\t");
    System.out.println(NumOfPeopleNeeded + " people may legally attend");
    }
    }
    }

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Also posted in his own thread geting user input (number)

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

Similar Threads

  1. Making arrays by reading user input
    By apfroggy0408 in forum New To Java
    Replies: 23
    Last Post: 04-30-2008, 02:23 AM
  2. Prompting user input of a string.
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 03-09-2008, 07:23 PM
  3. Creating a dialog to input user/password
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 08:03 AM
  4. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 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
  •