Question

In: Computer Science

The following Java code is set up to ask how many people are attending a meeting...

The following Java code is set up to ask how many people are attending a meeting and checks these user generate responses with replies, using the do while setup. To end the loop you type 0, change this to accept the answer "Y" to continue the loop after every response and "N" to end the loop with every case type. (Y,y,N,n)

Meeting.java
------
import java.util.Scanner;

public class Meeting {
   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       final int ROOM_CAPACITY = 100;
       int numPeople, diff;
       String name;
       System.out.println("****** Meeting Organizer ******");
      
       System.out.print("Enter your name: ");
       name = input.nextLine();
       System.out.println("Welcome " + name);
       do{
           System.out.print("\nHow many people would attend the meeting? (type 0 to quit): ");
           numPeople = input.nextInt();
           if(numPeople < 0)
               System.out.println("Invalid input!");
           else if(numPeople != 0)
           {
               if(numPeople > ROOM_CAPACITY)
               {
                   diff = numPeople - ROOM_CAPACITY;
                   System.out.println("Sorry! The room can only accommodate " + ROOM_CAPACITY +" people. ");
                   System.out.println(diff + " people have to drop off");
               }
               else if(numPeople < ROOM_CAPACITY)
               {
                   diff = ROOM_CAPACITY - numPeople;
                   System.out.println("The meeting can take place. You may still invite " + diff + " people");
               }
               else
               {
                   System.out.println("The meeting can take place. The room is full");
               }
           }
       }while(numPeople != 0);
       System.out.println("Goodbye!");   }
}

Solutions

Expert Solution

Program:

import java.util.Scanner;

public class Meeting {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int ROOM_CAPACITY = 100;
int numPeople, diff;
String name;
char c;
System.out.println("****** Meeting Organizer ******");
  
System.out.print("Enter your name: ");
name = input.nextLine();
System.out.println("Welcome " + name);

do{
System.out.print("\nHow many people would attend the meeting?: ");
numPeople = input.nextInt();
if(numPeople < 0)
System.out.println("Invalid input!");
else if(numPeople != 0)
{
if(numPeople > ROOM_CAPACITY)
{
diff = numPeople - ROOM_CAPACITY;
System.out.println("Sorry! The room can only accommodate " + ROOM_CAPACITY +" people. ");
System.out.println(diff + " people have to drop off");
}
else if(numPeople < ROOM_CAPACITY)
{
diff = ROOM_CAPACITY - numPeople;
System.out.println("The meeting can take place. You may still invite " + diff + " people");
}
else
{
System.out.println("The meeting can take place. The room is full");
}
}

System.out.print("Are you want to continue? (Y/N): ");

c = input.next().charAt(0);

if(c=='N' || c=='n') break;
  
}while(c=='y' || c=='Y');

System.out.println("Goodbye!"); }
}

Output:


****** Meeting Organizer ******
Enter your name: abc
Welcome abc

How many people would attend the meeting?: 10
The meeting can take place. You may still invite 90 people
Are you want to continue? (Y/N): y

How many people would attend the meeting?: 20
The meeting can take place. You may still invite 80 people
Are you want to continue? (Y/N): y

How many people would attend the meeting?: 30
The meeting can take place. You may still invite 70 people
Are you want to continue? (Y/N): n
Goodbye!


Related Solutions

What are some question to ask the Auditor general and client if attending meeting regarding the...
What are some question to ask the Auditor general and client if attending meeting regarding the integrity of management(client). How to assess a firm’s competence to perform the audit.
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
In Java, I need a program that will ask a user to input how many tests...
In Java, I need a program that will ask a user to input how many tests they want the average of. For example, It needs to ask the user how many tests would you like the average of? When the user enters the amount of tests they want the average score of, the program needs to give them that many test scores to input. Then with the average, determine what their grade is, if 90-100=A if 80-90 = B etc....
Write a java code to find the following. For numbers 501 to 999, how many numbers...
Write a java code to find the following. For numbers 501 to 999, how many numbers will have the sum of the digits equal to 10. 501, sum of digits=6 502, sum of digits=7 503, sum of digits=8 504, sum of digits=9 505, sum of digits=10 506, sum of digits=11
Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
Write a java code to ask the user for a string, and assuming the user enters...
Write a java code to ask the user for a string, and assuming the user enters a string containing character "a", your java program must convert all "a" to "b" in the string so for example if user types : "AMAZON" , your program must convert it to "BMBZON" the driver program must ask : enter a string containing "a" or "A" --------- (user enters string) then it should say; HERE IS YOUR NEW STRING ---------- (string with all a's...
Sample 8 people and ask how many hours of sleep they got last night. Then conduct...
Sample 8 people and ask how many hours of sleep they got last night. Then conduct a hypothesis test if the mean hours of sleep last night is less than 8 hours. Use significance levels of ? = 0.05, 0.01, and 0.10. 1. List the data values, sample mean and sample standard deviation. 2. Conduct a Hypothesis Test including each of the four steps.
you are attending a meeting of healthcare professionals. What do you do in the following situations?...
you are attending a meeting of healthcare professionals. What do you do in the following situations? a. You cannot hear the president of the organization as she is stating the motion that is being presented to the membership. b. the president states a motion has passed after a voice vote, but you do not think it passed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT