diff --git a/T2Q1-1/src/CircleApp.java b/T2Q1-1/src/CircleApp.java index bfd1443..d63e52e 100644 --- a/T2Q1-1/src/CircleApp.java +++ b/T2Q1-1/src/CircleApp.java @@ -26,7 +26,6 @@ public class CircleApp else if (option == 2) { cir.printArea(); - } else if (option == 3) { diff --git a/T2Q1-2/src/CircleApp.java b/T2Q1-2/src/CircleApp.java index 3ea97f6..c9e7bb8 100644 --- a/T2Q1-2/src/CircleApp.java +++ b/T2Q1-2/src/CircleApp.java @@ -26,7 +26,6 @@ public class CircleApp else if (option == 2 && cir != null) { cir.printArea(); - } else if (option == 3 && cir != null) { diff --git a/T2Q1-3/src/CircleApp.java b/T2Q1-3/src/CircleApp.java index d0b9448..3af137c 100644 --- a/T2Q1-3/src/CircleApp.java +++ b/T2Q1-3/src/CircleApp.java @@ -25,7 +25,8 @@ public class CircleApp } else if (option == 2) { - if (cir == null) { + if (cir == null) + { System.out.println("Create a circle first."); } else @@ -35,7 +36,8 @@ public class CircleApp } else if (option == 3) { - if (cir == null) { + if (cir == null) + { System.out.println("Create a circle first."); } else diff --git a/T2Q1-4/src/CircleApp.java b/T2Q1-4/src/CircleApp.java index 90b4803..83ccb23 100644 --- a/T2Q1-4/src/CircleApp.java +++ b/T2Q1-4/src/CircleApp.java @@ -19,7 +19,8 @@ public class CircleApp } else if (option == 2) { - if (cir == null) { + if (cir == null) + { System.out.println("Create a circle first."); } else @@ -29,7 +30,8 @@ public class CircleApp } else if (option == 3) { - if (cir == null) { + if (cir == null) + { System.out.println("Create a circle first."); } else diff --git a/T2Q1-5/src/CircleApp.java b/T2Q1-5/src/CircleApp.java index cbbc11a..e005c9a 100644 --- a/T2Q1-5/src/CircleApp.java +++ b/T2Q1-5/src/CircleApp.java @@ -27,10 +27,9 @@ public class CircleApp } private static Circle createCircle(Scanner scanner) { - double radius = 0.0; Circle circle; System.out.println("Enter the radius to compute the area and circumference"); - radius = scanner.nextDouble(); + double radius = scanner.nextDouble(); circle = new Circle(radius); System.out.println("A new circle is created"); return circle; diff --git a/T2Q1-extra1/src/CircleApp.java b/T2Q1-extra1/src/CircleApp.java index 389c665..e470af8 100644 --- a/T2Q1-extra1/src/CircleApp.java +++ b/T2Q1-extra1/src/CircleApp.java @@ -11,7 +11,7 @@ public class CircleApp do { printMenu(); option = scanner.nextInt(); - if (option == 1) circle = createCircle(scanner); + if (option == 1) createCircle(scanner); else if (option == 2) printArea(); else if (option == 3) printCircumference(); } while (option < 4); @@ -28,14 +28,11 @@ public class CircleApp else circle.printArea(); } - private static Circle createCircle(Scanner scanner) { - double radius = 0.0; - Circle circle; + private static void createCircle(Scanner scanner) { System.out.println("Enter the radius to compute the area and circumference"); - radius = scanner.nextDouble(); + double radius = scanner.nextDouble(); circle = new Circle(radius); System.out.println("A new circle is created"); - return circle; } private static void printMenu() { diff --git a/T2Q1-extra2/src/CircularApp.java b/T2Q1-extra2/src/CircularApp.java index 371ed78..6b32240 100644 --- a/T2Q1-extra2/src/CircularApp.java +++ b/T2Q1-extra2/src/CircularApp.java @@ -13,8 +13,8 @@ public class CircularApp do { printMenu(); option = scanner.nextInt(); - if (option == 1) circle = createCircle(scanner); - else if (option == 2) elipse = createElipse(scanner); + if (option == 1) createCircle(scanner); + else if (option == 2) createElipse(scanner); else if (option == 3) printCircleArea(); else if (option == 4) printElipseArea(); else if (option == 5) printCircleCircumference(); @@ -43,10 +43,9 @@ public class CircularApp else circle.printArea(); } - private static Elipse createElipse(Scanner scanner) { + private static void createElipse(Scanner scanner) { double smallRadius = 0.0; double largeRadius = 0.0; - Elipse elipse; System.out.println("Enter the radius 1 to compute the area and circumference"); smallRadius = scanner.nextDouble(); System.out.println("Enter the radius 2 to compute the area and circumference"); @@ -58,17 +57,13 @@ public class CircularApp } elipse = new Elipse(smallRadius, largeRadius); System.out.println("A new elipse is created"); - return elipse; } - private static Circle createCircle(Scanner scanner) { - double radius = 0.0; - Circle circle; + private static void createCircle(Scanner scanner) { System.out.println("Enter the radius to compute the area and circumference"); - radius = scanner.nextDouble(); + double radius = scanner.nextDouble(); circle = new Circle(radius); System.out.println("A new circle is created"); - return circle; } private static void printMenu() { diff --git a/T2Q1-extra2/src/Elipse.java b/T2Q1-extra2/src/Elipse.java index ae88c63..847d919 100644 --- a/T2Q1-extra2/src/Elipse.java +++ b/T2Q1-extra2/src/Elipse.java @@ -1,6 +1,5 @@ public class Elipse { - private double radius; private double smallRadius; private double largeRadius; private static final double PI = 3.14159; diff --git a/T2Q1-extra3/src/Circle.java b/T2Q1-extra3/src/Circle.java index 3e36543..a6a8aca 100644 --- a/T2Q1-extra3/src/Circle.java +++ b/T2Q1-extra3/src/Circle.java @@ -15,11 +15,11 @@ public class Circle implements Circular { return radius; } - public double area() + public double computeArea() { return PI * radius * radius; } - public double circumference() + public double computeCircumference() { return 2 * PI * radius; } @@ -27,12 +27,12 @@ public class Circle implements Circular { System.out.println("Area of circle"); System.out.println("Radius: " + radius); - System.out.println("Area: " + area()); + System.out.println("Area: " + computeArea()); } public void printCircumference() { System.out.println("Circumference of circle"); System.out.println("Radius: " + radius); - System.out.println("Circumference: " + circumference()); + System.out.println("Circumference: " + computeCircumference()); } } \ No newline at end of file diff --git a/T2Q1-extra3/src/Circular.java b/T2Q1-extra3/src/Circular.java index 04ac82b..fc816b2 100644 --- a/T2Q1-extra3/src/Circular.java +++ b/T2Q1-extra3/src/Circular.java @@ -1,7 +1,7 @@ public interface Circular { - public double area(); - public double circumference(); + public double computeArea(); + public double computeCircumference(); public void printArea(); public void printCircumference(); } \ No newline at end of file diff --git a/T2Q1-extra3/src/CircularApp.java b/T2Q1-extra3/src/CircularApp.java index aee7d38..1314245 100644 --- a/T2Q1-extra3/src/CircularApp.java +++ b/T2Q1-extra3/src/CircularApp.java @@ -11,8 +11,8 @@ public class CircularApp do { printMenu(); option = scanner.nextInt(); - if (option == 1) circular = createCircle(scanner); - else if (option == 2) circular = createElipse(scanner); + if (option == 1) createCircle(scanner); + else if (option == 2) createElipse(scanner); else if (option == 3) printCircleArea(); else if (option == 4) printCircleCircumference(); } while (option < 5); @@ -29,10 +29,9 @@ public class CircularApp else circular.printArea(); } - private static Elipse createElipse(Scanner scanner) { + private static void createElipse(Scanner scanner) { double smallRadius = 0.0; double largeRadius = 0.0; - Elipse elipse; System.out.println("Enter the radius 1 to compute the area and circumference"); smallRadius = scanner.nextDouble(); System.out.println("Enter the radius 2 to compute the area and circumference"); @@ -42,25 +41,21 @@ public class CircularApp smallRadius = largeRadius; largeRadius = tempRadius; } - elipse = new Elipse(smallRadius, largeRadius); + circular = new Elipse(smallRadius, largeRadius); System.out.println("A new elipse is created"); - return elipse; } - private static Circle createCircle(Scanner scanner) { - double radius = 0.0; - Circle circle; + private static void createCircle(Scanner scanner) { System.out.println("Enter the radius to compute the area and circumference"); - radius = scanner.nextDouble(); - circle = new Circle(radius); + double radius = scanner.nextDouble(); + circular = new Circle(radius); System.out.println("A new circle is created"); - return circle; } private static void printMenu() { System.out.println("==== Circle Computation ====="); System.out.println("|1. Create a new circle |"); - System.out.println("|2. Create a new elise |"); + System.out.println("|2. Create a new elipse |"); System.out.println("|3. Print Area |"); System.out.println("|4. Print circumference |"); System.out.println("|5. Quit |"); diff --git a/T2Q1-extra3/src/Elipse.java b/T2Q1-extra3/src/Elipse.java index d880cb3..f410ec1 100644 --- a/T2Q1-extra3/src/Elipse.java +++ b/T2Q1-extra3/src/Elipse.java @@ -26,11 +26,11 @@ public class Elipse implements Circular { return largeRadius; } - public double area() + public double computeArea() { return PI * smallRadius * largeRadius; } - public double circumference() + public double computeCircumference() { double a = smallRadius; double b = largeRadius; @@ -45,13 +45,13 @@ public class Elipse implements Circular System.out.println("Area of elipse"); System.out.println("Small Radius: " + smallRadius); System.out.println("Large Radius: " + largeRadius); - System.out.println("Area: " + area()); + System.out.println("Area: " + computeArea()); } public void printCircumference() { System.out.println("Circumference of elipse"); System.out.println("Small Radius: " + smallRadius); System.out.println("Large Radius: " + largeRadius); - System.out.println("Circumference: " + circumference()); + System.out.println("Circumference: " + computeCircumference()); } } \ No newline at end of file diff --git a/T2Q2/src/Dice.java b/T2Q2/src/Dice.java index 1ef68f5..ae3afc1 100644 --- a/T2Q2/src/Dice.java +++ b/T2Q2/src/Dice.java @@ -1,6 +1,6 @@ public class Dice { - private int valueOfDice=1; + private int valueOfDice = 1; public Dice() { diff --git a/T3Q2-1/src/Circle.java b/T3Q2-1/src/Circle.java index 51775ce..bc96152 100644 --- a/T3Q2-1/src/Circle.java +++ b/T3Q2-1/src/Circle.java @@ -10,5 +10,6 @@ public class Circle extends Point { public void setRadius(double radius) { this.radius = radius; } public double area() { return Math.PI * radius * radius; } + public String toString() { return "Circle of radius " + radius + " at point [" + x + "," + y + "]"; } } diff --git a/T3Q2-1/src/Point.java b/T3Q2-1/src/Point.java index 4cf799a..b0d59ae 100644 --- a/T3Q2-1/src/Point.java +++ b/T3Q2-1/src/Point.java @@ -1,4 +1,4 @@ -public class Point { +public class Point extends Object { protected int x, y; public Point() { x = 0; y = 0; } diff --git a/T3Q2-3/src/Circle.java b/T3Q2-3/src/Circle.java index 9b5c6d9..fe57827 100644 --- a/T3Q2-3/src/Circle.java +++ b/T3Q2-3/src/Circle.java @@ -11,4 +11,4 @@ public class Circle extends Point { public double area() { return Math.PI * radius * radius; } public String toString() { return String.format("Circle of radius %.2f at point %s", radius, super.toString()); } -} +} \ No newline at end of file