grodek118

Conversion Program

May 31st, 2023
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner input = new Scanner(System.in);
  9.  
  10.         System.out.print("Podaj odległość w metrach: ");
  11.         double meters = input.nextDouble();
  12.  
  13.         if(meters < 0)
  14.         {
  15.             System.out.println("BLAD");
  16.             System.exit(0);
  17.         }
  18.  
  19.  
  20.        do
  21.         {
  22.             menu();
  23.             int choice = input.nextInt();
  24.             switch (choice)
  25.             {
  26.                 case 1:
  27.                     showKilometres(meters);
  28.                     break;
  29.  
  30.                 case 2:
  31.                     showInches(meters);
  32.                     break;
  33.  
  34.                 case 3:
  35.                     showFeet(meters);
  36.                     break;
  37.  
  38.                 case 4:
  39.                     System.exit(0);
  40.                     break;
  41.  
  42.                 default:
  43.                     System.out.println("BLAD");
  44.             }
  45.         } while (true);
  46.  
  47.     }
  48.  
  49.     public static void showKilometres(double meters)
  50.     {
  51.         System.out.println("Kilometry = " + (meters * 0.001));
  52.     }
  53.  
  54.     public static void showInches(double meters)
  55.     {
  56.         System.out.println("Cale = " + (meters * 39.37));
  57.     }
  58.  
  59.     public static void showFeet(double meters)
  60.     {
  61.         System.out.println("Stopy = " + (meters * 3.281));
  62.     }
  63.  
  64.     public static void menu()
  65.     {
  66.         System.out.println("1. Przelicz na kilometry");
  67.         System.out.println("2. Przelicz na cale");
  68.         System.out.println("3. Przelicz na stopy");
  69.         System.out.println("4. Zamknij program");
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment