Write a Java program that determines whether a meeting room is in violation of f
ID: 3875637 • Letter: W
Question
Write a Java program that determines whether a meeting room is in violation of fire law regulations regarding the maximum room capacity. The program will read in the maximum room capacity and the number of people to attend the meeting. If the number of people is less than or equal to the maximum room capacity, the program announces that it is legal to hold the meeting and tells how many additional people may legally attend. If the number of people exceeds the maximum room capacity, the program announces that the meeting cannot be held as planned due to fire regulations and tells how many people must be excluded in order to meet the fire regulations.(Please include comments)
Explanation / Answer
import java.util.Scanner;
public class alpha {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // Scanner object to take user input
System.out.println("Enter the total capacity of room :");
int capacity = sc.nextInt(); // Input from user taken as capacity of room
System.out.println("Enter the number of people attending the meeting :");
int attending = sc.nextInt(); // Input from user taken as people attending the meeting
int dif;
if(attending<=capacity) //Checking if capacity is greater than attending
{ //If yes print appropriate messages
System.out.println("It is legal to hold the meeting according to Fire law regulations .");
dif=capacity-attending; //Compute how many more people can fit in
System.out.println(dif+" people may additionally attend the meeting");
}
if(attending>capacity) //Checking if capacity is less than attending
{ //If yes printing appropriate messages
System.out.println("The meeting cannot be held as per Fire law regulations .");
dif=attending-capacity; // Computing how many people are to be excluded
System.out.println(dif+" people must be excluded from the meeting");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.