desislava_topuzakova

Untitled

Oct 18th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P06_CinemaTickets {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. int students = 0;
  7. int standard = 0;
  8. int kids = 0;
  9.  
  10. String filmName = scan.nextLine();
  11. while (!"Finish".equals(filmName)) {
  12. int places = Integer.parseInt(scan.nextLine());
  13. int people = 0;
  14. for (int i = 0; i < places; i++) {
  15. String command = scan.nextLine();
  16. if ("student".equals(command)) {
  17. students++;
  18. } else if ("standard".equals(command)) {
  19. standard++;
  20. } else if ("kid".equals(command)) {
  21. kids++;
  22. } else if ("End".equals(command)) {
  23. break;
  24. }
  25. people++;
  26. }
  27. System.out.println(String.format("%s - %.2f%% full.", filmName, people * 1.0 / places * 100));
  28. filmName = scan.nextLine();
  29. }
  30. int totalTickets = standard + students + kids;
  31. System.out.println(String.format("Total tickets: %d", totalTickets));
  32. System.out.println(String.format("%.2f%% student tickets.", (students * 1.0 / totalTickets * 100)));
  33. System.out.println(String.format("%.2f%% standard tickets.", (standard * 1.0 / totalTickets * 100)));
  34. System.out.println(String.format("%.2f%% kids tickets.", (kids * 1.0 / totalTickets * 100)));
  35. }
  36. }
Add Comment
Please, Sign In to add comment