From 52647222240ce07dd3c9eedd7f11a1443480d96e Mon Sep 17 00:00:00 2001 From: Ahmad Alsowayan Date: Wed, 6 Mar 2024 19:54:48 +0300 Subject: [PATCH 1/2] Added Code to repo. --- src/App.java | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/App.java b/src/App.java index 0a839f9..0a43870 100644 --- a/src/App.java +++ b/src/App.java @@ -1,5 +1,44 @@ -public class App { +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Main { public static void main(String[] args) throws Exception { - System.out.println("Hello, World!"); + Scanner input = new Scanner(System.in); + boolean flag = true; + while (flag) { + try{ + System.out.println("------------------------------------\n" + + " Please select operation:\n" + + "\t1- C to F\n" + + "\t2- F to C\n" + + " SELECT ANY OTHER NUMBER TO QUIT\n"); + double num; + switch (input.nextShort()) { + case 1: + num = takeNum(); + displayNum(num, (num * 9 / 5.0 + 32)); + break; + case 2: + num = takeNum(); + displayNum(num, ((num - 32) * 5 / 9.0)); + break; + default: + flag = false; + } + } + catch(InputMismatchException e){ + System.err.println("Error: Input is of an incorrect datatype!"); + input.nextLine(); + } + } + } -} + static double takeNum() throws InputMismatchException { + System.out.print("Please insert number: "); + return new Scanner(System.in).nextDouble(); + } + + static void displayNum(double source, double conv){ + System.out.printf("%.2f\t->\t%.2f\n", source, conv); + } +} \ No newline at end of file From 3f01fd917eac675b836ce5d75228ee51e8f528ff Mon Sep 17 00:00:00 2001 From: Ahmad Alsowayan Date: Wed, 6 Mar 2024 19:59:46 +0300 Subject: [PATCH 2/2] changed the class name Main to App for compatibility purposes. --- src/App.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.java b/src/App.java index 0a43870..afd3518 100644 --- a/src/App.java +++ b/src/App.java @@ -1,7 +1,7 @@ import java.util.InputMismatchException; import java.util.Scanner; -public class Main { +public class App { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); boolean flag = true;