Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CinemaTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int standardTickets = 0, studentTickets = 0, kidTickets = 0;
- String movie;
- while (!(movie = scanner.nextLine()).equals("Finish")) {
- int seats = Integer.parseInt(scanner.nextLine()),
- counter = 0;
- String category;
- while (counter != seats && !(category = scanner.nextLine()).equals("End")) {
- if (category.equals("standard")) {
- standardTickets++;
- } else if (category.equals("student")) {
- studentTickets++;
- } else {
- kidTickets++;
- }
- counter++;
- }
- System.out.printf("%s - %.2f%% full.\n", movie, 1.0 * counter / seats * 100);
- }
- int totalTickets = studentTickets + standardTickets + kidTickets;
- System.out.printf("Total tickets: %d\n", totalTickets);
- System.out.printf("%.2f%% student tickets.\n", 1.0 * studentTickets / totalTickets * 100);
- System.out.printf("%.2f%% standard tickets.\n", 1.0 * standardTickets / totalTickets * 100);
- System.out.printf("%.2f%% kids tickets.\n", 1.0 * kidTickets / totalTickets * 100);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class CinemaTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int standardTickets = 0, studentTickets = 0, kidTickets = 0;
- String movie;
- while (!(movie = scanner.nextLine()).equals("Finish")) {
- int seats = Integer.parseInt(scanner.nextLine()),
- counter = 0;
- String category;
- while (counter != seats && !(category = scanner.nextLine()).equals("End")) {
- int i = category.equals("standard") ? standardTickets++ :
- category.equals("student") ? studentTickets++ : kidTickets++;
- counter++;
- }
- System.out.printf("%s - %.2f%% full.\n", movie, 1.0 * counter / seats * 100);
- }
- int totalTickets = studentTickets + standardTickets + kidTickets;
- System.out.printf("Total tickets: %d\n", totalTickets);
- System.out.printf("%.2f%% student tickets.\n", 1.0 * studentTickets / totalTickets * 100);
- System.out.printf("%.2f%% standard tickets.\n", 1.0 * standardTickets / totalTickets * 100);
- System.out.printf("%.2f%% kids tickets.\n", 1.0 * kidTickets / totalTickets * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement