Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import static java.lang.Math.*;
- class CaseMenuTest {
- public static void main(String[] args) {
- System.out.println("Реализация меню на языке джава");
- new CaseMenu (new Scanner(System.in)).start();
- }
- }
- //////////////////////////////////
- class CaseMenu {
- private final Scanner scanner;
- public CaseMenu(Scanner scanner) {
- this.scanner = scanner;
- }
- private void printMenu() {
- System.out.println("1. Вывод Hello world ;");
- System.out.println("2. Подсчет формулы (y-(sqrt(x)/z);");
- System.out.println("3. .....");
- }
- public void start() {
- if (this.scanner != null) {
- do {
- double a = 0.0;
- double b = 0.0;
- double c = 0.0;
- printMenu();
- System.out.print("Введите номер меню: ");
- while (!this.scanner.hasNextInt()) {
- System.out.println("Введите число 0,1,2");
- this.scanner.next();
- }
- int key = this.scanner.nextInt();
- switch (key) {
- case 0:
- return;
- case 1:
- print_hello();
- break;
- case 2:
- formula(this.scanner, a, b , c);
- break;
- case 3:
- //
- break;
- default:
- System.out.println("Вы ввели неверное значение меню...\n");
- }
- } while (true);
- }
- }
- public void print_hello() {
- System.out.println("Hello world");
- }
- public void formula(Scanner in, double x, double y, double z) {
- double k=0;
- System.out.print("Введите x: ");
- while (in.hasNext()) {
- if (in.hasNextDouble()) {
- if ((k = in.nextDouble()) >= 0) {
- x = k;
- break;
- } else
- System.out.println("Введите положительное число");
- } else {
- System.out.println("Введите число типа double");
- }
- in.nextLine();
- }
- System.out.print("Введите y: ");
- while (in.hasNext()) {
- if (in.hasNextDouble()) {
- if ((k = in.nextDouble()) >= 0) {
- y = k;
- break;
- } else
- System.out.println("Введите положительное число");
- } else {
- System.out.println("Введите число типа double");
- }
- in.nextLine();
- }
- System.out.print("Введите z: ");
- while (in.hasNext()) {
- if (in.hasNextDouble()) {
- if ((k = in.nextDouble()) > 0) {
- z = k;
- break;
- } else
- System.out.println("Введите положительное число");
- } else {
- System.out.println("Введите число типа double");
- }
- in.nextLine();
- }
- double F=(y-(sqrt(x)/z));
- //System.out.println(F);
- System.out.printf("Ответ: %.3f %n", F);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement