Created
September 10, 2015 23:29
-
-
Save ad-m/0ef46b7a4ba974dc18d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Circle extends Figure { | |
| private double radius; | |
| public Circle(double radius) { | |
| super(); | |
| this.radius = radius; | |
| } | |
| double area() { | |
| return 3.14*radius*radius; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Circle [radius=" + radius + "]"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Scanner; | |
| public class CLI { | |
| static Scanner sc = new Scanner(System.in); | |
| public static void main(String[] args) { | |
| int choose; | |
| do{ | |
| System.out.print("Select option:"); | |
| choose = sc.nextInt(); | |
| Circle[] tab1 = new Circle[0]; | |
| Rectangle[] tab2 = new Rectangle[0]; | |
| Integer[] tab3; | |
| if(choose == 1){ | |
| Circle c = new Circle(sc.nextDouble()); | |
| System.out.print("Area: "+c.area()); | |
| }else if(choose == 2){ | |
| Rectangle r = new Rectangle(sc.nextInt(), sc.nextInt()); | |
| System.out.print("Area: "+r.area()); | |
| }else if(choose == 3){ | |
| System.out.print("Circle count:"); | |
| int c = sc.nextInt(); | |
| tab1 = new Circle[c]; | |
| for(int i=0; i<c; i++){ | |
| tab1[i] = new Circle(sc.nextDouble()); | |
| } | |
| System.out.print("Rectangle count:"); | |
| c = sc.nextInt(); | |
| tab2 = new Rectangle[c]; | |
| for(int i=0; i<c; i++){ | |
| tab2[i] = new Rectangle(sc.nextInt(), sc.nextInt()); | |
| } | |
| }else if(choose == 4){ | |
| double epsilon = sc.nextDouble(); | |
| int smaller; | |
| if(tab1.length > tab2.length){ | |
| smaller = tab1.length; | |
| }else{ | |
| smaller = tab2.length; | |
| } | |
| ArrayList<Integer> list = new ArrayList<Integer>(); | |
| for(int i=0; i<smaller; i++){ | |
| if(Math.sqrt(Math.pow(tab1[i].area()-tab2[i].area(), 2)) < epsilon){ | |
| list.add(i); | |
| } | |
| } | |
| tab3 = list.toArray(new Integer[list.size()]); | |
| }else{ | |
| System.out.print("Unknown option!"); | |
| } | |
| }while(true); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class Figure { | |
| abstract double area(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Rectangle extends Figure { | |
| private int width; | |
| private int height; | |
| public Rectangle(int width, int height) { | |
| super(); | |
| this.width = width; | |
| this.height = height; | |
| } | |
| double area() { | |
| return this.width*this.height; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Rectangle [width=" + width + ", height=" + height + "]"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment