Advertisement
Anton0093

JAVA_1

Feb 21st, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. import java.util.Scanner;
  2. import static java.lang.Math.*;
  3. class CaseMenuTest {
  4.     public static void main(String[] args) {
  5.         System.out.println("Реализация меню на языке джава");
  6.         new CaseMenu (new Scanner(System.in)).start();
  7.     }
  8. }
  9.  
  10. //////////////////////////////////
  11. class CaseMenu {
  12.     private final Scanner scanner;
  13.  
  14.     public CaseMenu(Scanner scanner) {
  15.         this.scanner = scanner;
  16.     }
  17.     private void printMenu() {
  18.         System.out.println("1. Вывод Hello world ;");
  19.         System.out.println("2. Подсчет формулы (y-(sqrt(x)/z);");
  20.         System.out.println("3. .....");
  21.     }
  22.  
  23.     public void start() {
  24.         if (this.scanner != null) {
  25.             do {
  26.                 double a = 0.0;
  27.                 double b = 0.0;
  28.                 double c = 0.0;
  29.                 printMenu();
  30.                 System.out.print("Введите номер меню: ");
  31.                 while (!this.scanner.hasNextInt()) {
  32.                     System.out.println("Введите число 0,1,2");
  33.                     this.scanner.next();
  34.                 }
  35.                 int key = this.scanner.nextInt();
  36.                 switch (key) {
  37.                     case 0:
  38.                         return;
  39.                     case 1:
  40.                         print_hello();
  41.                         break;
  42.                     case 2:
  43.                         formula(this.scanner, a, b , c);
  44.                         break;
  45.                     case 3:
  46.                         //
  47.                         break;
  48.                     default:
  49.                         System.out.println("Вы ввели неверное значение меню...\n");
  50.                 }
  51.             } while (true);
  52.         }
  53.     }
  54.  
  55.     public void print_hello() {
  56.         System.out.println("Hello world");
  57.  
  58.     }
  59.  
  60.     public void formula(Scanner in, double x, double y, double z) {
  61.         double k=0;
  62.         System.out.print("Введите x: ");
  63.         while (in.hasNext()) {
  64.             if (in.hasNextDouble()) {
  65.                 if ((k = in.nextDouble()) >= 0) {
  66.                     x = k;
  67.                     break;
  68.                 } else
  69.                     System.out.println("Введите положительное число");
  70.             } else {
  71.                 System.out.println("Введите число типа double");
  72.             }
  73.             in.nextLine();
  74.         }
  75.  
  76.         System.out.print("Введите y: ");
  77.         while (in.hasNext()) {
  78.             if (in.hasNextDouble()) {
  79.                 if ((k = in.nextDouble()) >= 0) {
  80.                     y = k;
  81.                     break;
  82.                 } else
  83.                     System.out.println("Введите положительное число");
  84.             } else {
  85.                 System.out.println("Введите число типа double");
  86.             }
  87.             in.nextLine();
  88.         }
  89.  
  90.         System.out.print("Введите z: ");
  91.         while (in.hasNext()) {
  92.             if (in.hasNextDouble()) {
  93.                 if ((k = in.nextDouble()) > 0) {
  94.                     z = k;
  95.                     break;
  96.                 } else
  97.                     System.out.println("Введите положительное число");
  98.             } else {
  99.                 System.out.println("Введите число типа double");
  100.             }
  101.             in.nextLine();
  102.         }
  103.         double F=(y-(sqrt(x)/z));
  104.         //System.out.println(F);
  105.         System.out.printf("Ответ: %.3f %n", F);
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement