From fe60d7e4ccca7649ac91403bfde2680879ab2aaf Mon Sep 17 00:00:00 2001 From: tongkahpauu <110804459+tongkahpauu@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:46:04 +0800 Subject: [PATCH 1/5] Add files via upload --- Java Code/SimpleCalculator.java | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Java Code/SimpleCalculator.java diff --git a/Java Code/SimpleCalculator.java b/Java Code/SimpleCalculator.java new file mode 100644 index 0000000..8f81a7b --- /dev/null +++ b/Java Code/SimpleCalculator.java @@ -0,0 +1,56 @@ +import java.util.Scanner; + +class Main { + public static void main(String[] args) { + + char operator; + Double number1, number2, result; + + // create an object of Scanner class + Scanner input = new Scanner(System.in); + + // ask users to enter operator + System.out.println("Choose an operator: +, -, *, or /"); + operator = input.next().charAt(0); + + // ask users to enter numbers + System.out.println("Enter first number"); + number1 = input.nextDouble(); + + System.out.println("Enter second number"); + number2 = input.nextDouble(); + + switch (operator) { + + // performs addition between numbers + case '+': + result = number1 + number2; + System.out.println(number1 + " + " + number2 + " = " + result); + break; + + // performs subtraction between numbers + case '-': + result = number1 - number2; + System.out.println(number1 + " - " + number2 + " = " + result); + break; + + // performs multiplication between numbers + case '*': + result = number1 * number2; + System.out.println(number1 + " * " + number2 + " = " + result); + break; + + // performs division between numbers + case '/': + result = number1 / number2; + System.out.println(number1 + " / " + number2 + " = " + result); + break; + + default: + System.out.println("Invalid operator!"); + break; + } + + input.close(); + } +} \ No newline at end of file From 7881047f29a633cfc75097e477ad5911da8b6b6d Mon Sep 17 00:00:00 2001 From: tongkahpauu <110804459+tongkahpauu@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:54:38 +0800 Subject: [PATCH 2/5] Add files via upload From c003b7dd274d82063376c4d529cf48aa549cd15c Mon Sep 17 00:00:00 2001 From: tongkahpauu <110804459+tongkahpauu@users.noreply.github.com> Date: Sat, 3 Sep 2022 02:00:02 +0800 Subject: [PATCH 3/5] Update SimpleCalculator.java --- Java Code/SimpleCalculator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Java Code/SimpleCalculator.java b/Java Code/SimpleCalculator.java index 8f81a7b..5040ebb 100644 --- a/Java Code/SimpleCalculator.java +++ b/Java Code/SimpleCalculator.java @@ -1,6 +1,6 @@ import java.util.Scanner; -class Main { +public class Main { public static void main(String[] args) { char operator; @@ -53,4 +53,4 @@ public static void main(String[] args) { input.close(); } -} \ No newline at end of file +} From c3bfb334fa2935919ec93a59fb2f74fd55065685 Mon Sep 17 00:00:00 2001 From: tongkahpauu <110804459+tongkahpauu@users.noreply.github.com> Date: Sat, 3 Sep 2022 02:18:04 +0800 Subject: [PATCH 4/5] added area rectangle function --- Java Code/areaRectangle.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Java Code/areaRectangle.java diff --git a/Java Code/areaRectangle.java b/Java Code/areaRectangle.java new file mode 100644 index 0000000..f980859 --- /dev/null +++ b/Java Code/areaRectangle.java @@ -0,0 +1,14 @@ +import java.util.Scanner; +class AreaOfRectangle { + public static void main (String[] args) + { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter the length of Rectangle:"); + double length = scanner.nextDouble(); + System.out.println("Enter the width of Rectangle:"); + double width = scanner.nextDouble(); + //Area = length*width; + double area = length*width; + System.out.println("Area of Rectangle is:"+area); + } +} \ No newline at end of file From 84e6a7e5e5ae2feca0c0b3c5177dd29d21c32b88 Mon Sep 17 00:00:00 2001 From: tongkahpauu <110804459+tongkahpauu@users.noreply.github.com> Date: Sat, 3 Sep 2022 02:19:01 +0800 Subject: [PATCH 5/5] Update areaRectangle.java --- Java Code/areaRectangle.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Java Code/areaRectangle.java b/Java Code/areaRectangle.java index f980859..92af50a 100644 --- a/Java Code/areaRectangle.java +++ b/Java Code/areaRectangle.java @@ -1,5 +1,5 @@ import java.util.Scanner; -class AreaOfRectangle { +public class AreaOfRectangle { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); @@ -11,4 +11,4 @@ public static void main (String[] args) double area = length*width; System.out.println("Area of Rectangle is:"+area); } -} \ No newline at end of file +}