Kancho

House_Party

May 2nd, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class House_Party {
  8. public static void main(String[] args) throws IOException {
  9.  
  10. BufferedReader reader =
  11. new BufferedReader(
  12. new InputStreamReader(System.in));
  13.  
  14.  
  15.  
  16. List<String> names = new ArrayList<>();
  17.  
  18. System.out.println("Enter number of people ");
  19. int number = Integer.parseInt(reader.readLine());
  20. while (number -- > 0 ) {
  21. String[] input = reader.readLine().split("\\s+");
  22.  
  23. if (!input[2].equals("not")) {
  24. if (!names.contains(input[0])) {
  25. names.add(input[0]);
  26. System.out.printf("%s is added in the list, and %s is going to the party.\n", input[0], input[0]);
  27. } else {
  28. System.out.printf("%s is in the list and %s is going to the party.\n", input[0], input[0]);
  29.  
  30. }
  31.  
  32. } else {
  33. if (names.contains(input[0])) {
  34. names.remove(input[0]);
  35. System.out.printf("%s is deleted from the list because %s is not going.\n", input[0], input[0]);
  36.  
  37. } else {
  38. System.out.printf("%s is not going to the party.", input[0]);
  39. }
  40. }
  41. System.out.println(String.join("\n", names));
  42. }
  43. }
Add Comment
Please, Sign In to add comment