From 05d2d0de26ff11d0a6b5d1dd9ac5ee29f060c99f Mon Sep 17 00:00:00 2001 From: LiviMcK <137836813+LiviMcK@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:11:32 -0700 Subject: [PATCH 1/3] I tried my best to finish this lab, I couldn't finish the code and make it work past this point. --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..1ce6e7f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index 0b6e780..e0e214c 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -2,6 +2,22 @@ public class ArchimedesPiMethod { public static void main(String[] args) { + int n = 8; + double angleB = 360.0 / n; + System.out.println("Angle B for a " + n + "-sided polygon is: " + angleB + " degrees"); + double angleA = 0.5 * angleB; + System.out.println("Angle A is: " + angleA + " degrees"); + double s = 2.0 * Math.sin(Math.toRadians(angleA)); + System.out.println("Length of the triangle base (s) is: " + s); + class PolygonPerimeterCalculator { + public static void main(String[] args) { + int n = 6; + double s = 0.7653668647301796; + double perimeter = n * s; + + System.out.println(n * s); + } + } } } From c4282ffd4749d48679d231dfa30b3568fcb0d4c7 Mon Sep 17 00:00:00 2001 From: LiviMcK <137836813+LiviMcK@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:46:16 -0700 Subject: [PATCH 2/3] I tried my best to finish this lab, I couldn't finish the code and make it work past this point. --- src/ArchimedesPiMethod.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index e0e214c..e7f935c 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -1,5 +1,3 @@ -import java.util.Scanner; - public class ArchimedesPiMethod { public static void main(String[] args) { int n = 8; From c504e0747331c3ce2e2999beb3217863a8f6f804 Mon Sep 17 00:00:00 2001 From: LiviMcK <137836813+LiviMcK@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:34:11 -0700 Subject: [PATCH 3/3] I tried my best to finish this lab, I couldn't finish the code and make it work past this point. --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 21 --------------------- src/Main.java | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 22 deletions(-) delete mode 100644 src/ArchimedesPiMethod.java create mode 100644 src/Main.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 1ce6e7f..6a446fe 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java deleted file mode 100644 index e7f935c..0000000 --- a/src/ArchimedesPiMethod.java +++ /dev/null @@ -1,21 +0,0 @@ -public class ArchimedesPiMethod { - public static void main(String[] args) { - int n = 8; - double angleB = 360.0 / n; - System.out.println("Angle B for a " + n + "-sided polygon is: " + angleB + " degrees"); - double angleA = 0.5 * angleB; - System.out.println("Angle A is: " + angleA + " degrees"); - double s = 2.0 * Math.sin(Math.toRadians(angleA)); - System.out.println("Length of the triangle base (s) is: " + s); - class PolygonPerimeterCalculator { - public static void main(String[] args) { - int n = 6; - double s = 0.7653668647301796; - double perimeter = n * s; - - System.out.println(n * s); - } - } - - } -} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..d10a4c9 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,19 @@ +import java.util.Scanner; +public class Main { + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + try { + System.out.println("Please enter the number of sides for a polygon: "); + int numSides = Integer.parseInt(s.nextLine()); // n = numSides, n = 8 was not right + double angleB = 360.0 / numSides; + double angleA = angleB / 2; + double side = 2 * Math.sin(Math.toRadians(Math.toRadians(angleA))); // side = s + double p = numSides * side; // p = perimeter + double myPI= p / 2; + System.out.printf("My estimate for PI: %.15f Real PI: %.15f%n", myPI, Math.PI); + + } catch(NumberFormatException nfe) { + System.out.println("You need to enter a number."); + } + } + }