|
|
| Demonstrating how to print in Java. |
| sillySentances | Tuesday, April 15, 2003, 2002 | By Wulf |
Untitled Document
/* Programmer : Amanda */
/* User ID : abc */
/* Section : 6 */
/* Assignment : Program 4 */
/* Due Date : 04/01/03 */
/* Purpose : Using counters and if/else statements.
import javax.swing.JOptionPane;
public class DecisionsRepetitions
{
public static void main (String args[])
{
/* Get and print the information from the user. */
String input1 =JOptionPane.showInputDialog("Enter a room number:");
int room_num;
room_num = Integer.parseInt(input1);
System.out.println(" \nThe room number is : " + room_num);
String input2 =JOptionPane.showInputDialog("Enter the total amount of
seats available:");
int capacity;
capacity = Integer.parseInt(input2);
System.out.println("The total amount of seats available is : " +
capacity);
String input3 =JOptionPane.showInputDialog("Enter the current amount of
people in the class:");
int size;
size = Integer.parseInt(input3);
System.out.println("The current amount of people in the class is : " + size);
/*Determining what message to print out.*/
int seats_left;
seats_left = capacity - size;
if (size < capacity)
{
System.out.println("There is/are " + seats_left + " seat(s) left
in this class.\n");
/*Counting loop to figure the number of seats available*/
for (int x = size; x < capacity; x++)
System.out.println("Time is short.Register NOW!");
}
else if (size == capacity)
{
System.out.println( " \nSorry, there are no more seats available
for this class.");
}
else if (size > capacity)
{
System.out.println( " \nSorry, that means the class is
overflowing.");
}
System.exit(0);
}
}
|
| Output |
If the user input the room number as 33, the seats available as 25, and
the current amount as 22.
The room number is : 33
The total amount of seats available is : 25
The current amount of people in the class is : 22
There is/are 3 seat(s) left in this class.
Time is short.Register NOW!
Time is short.Register NOW!
Time is short.Register NOW!
|
|
|
|
|