TheBulgarianWolf

Types of messages

Apr 3rd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. package softuni;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7.  
  8. public class SoftUni {
  9.    
  10.     static void lineMessage(){
  11.         for(int i =0;i<20;i++){
  12.             System.out.print("=");
  13.         }
  14.         System.out.println();
  15. }
  16.    
  17.     static void showSuccessMessage(String operation,String message){
  18.         System.out.println("Successfully executed " + operation);
  19.         lineMessage();
  20.         System.out.println(message);
  21.     }
  22.      
  23.    
  24.     static void showWarningMessage(String warning){
  25.         System.out.println(warning);
  26.         lineMessage();
  27. }
  28.    
  29.     static void showErrorMessage(String error,String reason,int errorCode){
  30.         System.out.println("Error: Failed to execute" + error);
  31.         lineMessage();
  32.         System.out.println("Reason: " + reason);
  33.         System.out.println("Error code: " + errorCode);
  34.     }
  35.    
  36.     public static void main(String[] args){
  37.         Scanner sc = new Scanner(System.in);
  38.         String type = sc.nextLine().toLowerCase();
  39.         while(type != "success" || type != "warning" || type != "error"){
  40.          if(type.equals("success")){
  41.             System.out.print("Enter the type of the operation: ");
  42.             String operation = sc.nextLine();
  43.             System.out.print("Enter your message: ");
  44.             String message = sc.nextLine();
  45.             showSuccessMessage(operation, message);
  46.          }
  47.          else if(type.equals("warning")){
  48.             System.out.print("Enter your warning");
  49.             String warning = sc.nextLine();
  50.             showWarningMessage(warning);
  51.          }
  52.          else if(type.equals("error")){
  53.             System.out.print("Enter the type of error: ");
  54.             String error = sc.nextLine();
  55.             System.out.print("Enter the reason for the error: ");
  56.             String reason = sc.nextLine();
  57.             System.out.print("Enter the error code: ");
  58.             int errorCode = Integer.parseInt(sc.nextLine());
  59.             showErrorMessage(error, reason, errorCode);
  60.          }
  61.         }
  62.     }
  63.    
  64. }
Add Comment
Please, Sign In to add comment