Results 1 to 10 of 10
  1. #1
    kliane's Avatar
    kliane is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default geting user input (number)

    hey? 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");
    }
    }
    }
    Last edited by kliane; 01-15-2010 at 06:42 PM.

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

    Default

    hey? 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");
    }
    }
    }

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

    Default

    So what have you tried?

    Have a look in your textbook/notes etc for the classes Scanner, Console and BufferedReader: all of which provide methods for reading numeric input from the user at the command line.

  4. #4
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    Okay here you go. I cleaned it up and such as well.


    /*

    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;
    int NumOfPeopleEx=0;
    int NumOfPeopleAttended;

    System.out.println("How many people will attend?")
    NumOfPeopleAttended = one.nextInt();


    //CALCULATIONS

    if(NumOfPeopleAttended>MaxRoomCapacity)
    {

    NumOfPeopleEx=NumOfPeopleAttended-MaxRoomCapacity;

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

    else
    {
    NumOfPeopleNeeded=MaxRoomCapacity-NumOfPeopleAttended;


    System.out.println("The maximum room capacity is " + MaxRoomCapacity);
    System.out.print(NumOfPeopleAttended+" people will be attending.");
    System.out.println("ANNOUNCEMENT: It is legal to hold the meeting.");
    System.out.println(NumOfPeopleNeeded + " more people may legally attend");
    }
    }
    }
    Last edited by Syntax; 01-15-2010 at 10:17 PM.
    11th Grade | Beginner Programmer | Looking into College

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

    Default

    Great. What happens when you compile that, any helpful messages?

    If you can't understand the compiler message, post it here.

  6. #6
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    Give me a second let me try it :p
    11th Grade | Beginner Programmer | Looking into College

  7. #7
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    Thanks i found some problems. The imports were not imported and a scanner was not created.

    Here you go:

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.Scanner;
    
    /*
    
    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;
    int NumOfPeopleEx=0;
    int NumOfPeopleAttended;
    
    Scanner one = new Scanner(System.in);
    System.out.println("How many people will attend?");
    NumOfPeopleAttended = one.nextInt();
    
    
    //CALCULATIONS
    
    if(NumOfPeopleAttended>MaxRoomCapacity)
    {
    
    NumOfPeopleEx=NumOfPeopleAttended-MaxRoomCapacity;
    
    System.out.println("The maximum room capacity is " + MaxRoomCapacity);
    System.out.println(NumOfPeopleAttended+" people will be attending.");
    System.out.println("ANNOUNCEMENT: The meeting cannot be held as planned due to fire regulations.");
    System.out.println(NumOfPeopleEx + " people must be excluded in order to meet the maximum room capacity");
    }
    
    else
    {
    NumOfPeopleNeeded=MaxRoomCapacity-NumOfPeopleAttended;
    
    
    System.out.println("The maximum room capacity is " + MaxRoomCapacity);
    System.out.println(NumOfPeopleAttended+" people will be attending.");
    System.out.println("ANNOUNCEMENT: It is legal to hold the meeting.");
    System.out.println(NumOfPeopleNeeded + " more people may legally attend");
    }
    }
    }
    11th Grade | Beginner Programmer | Looking into College

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

    Default

    Thanks i found some problems. The imports were not imported and a scanner was not created.

    Well done - it seems to be giving sensible output now. (Well, unless the user enters a negative number. But in that case they deserve what they get...)

    Actually you don't need the java.swing and java.util imports.

  9. #9
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    oh okay :)
    i'm not really sure what they do, i just add them to all my programs lol.
    better safe than sorry eh?
    11th Grade | Beginner Programmer | Looking into College

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

    Default

    hey hey hey thanx to all of you guyz.. you helped me a lot.. mwuah

Similar Threads

  1. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  2. Replies: 1
    Last Post: 08-07-2009, 01:14 PM
  3. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 05:47 AM
  4. who to take user input ,not by console...
    By Shyam Singh in forum New To Java
    Replies: 3
    Last Post: 06-13-2008, 11:09 PM
  5. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 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
  •