Results 1 to 10 of 10
Thread: geting user input (number)
- 01-15-2010, 05:38 PM #1
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 05:42 PM.
- 01-15-2010, 05:41 PM #2
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");
}
}
}
- 01-15-2010, 06:47 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.
- 01-15-2010, 09:08 PM #4
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 09:17 PM.
11th Grade | Beginner Programmer | Looking into College
- 01-15-2010, 09:22 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Great. What happens when you compile that, any helpful messages?
If you can't understand the compiler message, post it here.
- 01-15-2010, 09:41 PM #6
Give me a second let me try it :p
11th Grade | Beginner Programmer | Looking into College
- 01-15-2010, 09:48 PM #7
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
- 01-15-2010, 10:34 PM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.
- 01-15-2010, 10:40 PM #9
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
- 01-17-2010, 12:25 PM #10
Similar Threads
-
how to get input from User
By Alvaro in forum New To JavaReplies: 7Last Post: 01-15-2010, 11:02 PM -
Geting Mobile Number, Mobile Operator, Location and Mobile Serial Number by J2ME.
By maruffaiz in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 12:14 PM -
User input- Pop Up Box
By dedachi in forum AWT / SwingReplies: 3Last Post: 03-23-2009, 04:47 AM -
who to take user input ,not by console...
By Shyam Singh in forum New To JavaReplies: 3Last Post: 06-13-2008, 10:09 PM -
cant take input from user
By new_1 in forum New To JavaReplies: 6Last Post: 12-25-2007, 07:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks