Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Notifications5 {
- public static void main(String[] args) {
- readAndProcessMessage();
- }
- private static void showSuccessMessage(String operation, String message) {
- System.out.printf("Successfully executed %s.%n", operation);
- char[] row = new char[operation.length()];
- Arrays.fill(row, '=');
- System.out.println(row);
- System.out.printf("%s.%n", message);
- System.out.println();
- }
- private static void showWarningMessage(String message) {
- message = "Warning: " + message + '.';
- System.out.println(message);
- char[] row = new char[message.length()];
- Arrays.fill(row, '=');
- System.out.println(row);
- System.out.println();
- }
- private static void showErrorMessage(String operation, String message, int errorCode) {
- System.out.printf("Failed to execute %s.%n", operation);
- char[] row = new char[operation.length()];
- Arrays.fill(row, '=');
- System.out.println(row);
- System.out.printf("Reason: %s.%n", message);
- System.out.printf("Error code: %d.%n", errorCode);
- System.out.println();
- }
- private static void readAndProcessMessage() {
- Scanner scanner = new Scanner(System.in);
- int messagesNumber = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < messagesNumber; i++) {
- String messageType = scanner.nextLine();
- switch (messageType) {
- case "success":
- String operation = scanner.nextLine();
- String message = scanner.nextLine();
- showSuccessMessage(operation, message);
- break;
- case "warning":
- message = scanner.nextLine();
- showWarningMessage(message);
- break;
- case "error":
- operation = scanner.nextLine();
- message = scanner.nextLine();
- int errorCode = Integer.parseInt(scanner.nextLine());
- showErrorMessage(operation, message, errorCode);
- break;
- default:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement