Örnek 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
package tr.edu.iku.oop.lab7reyhan; public class VehiclesReyhan { public static void main(String[] args) { // TODO Auto-generated method stub Bus myFirstBus = new Bus("Whoop Whoop ", "RED"); System.out.println(" " + myFirstBus.getColor() + " bus " + myFirstBus.horn() + "with " + myFirstBus.getSeatCount() + " seats. "); Car myFirstCar = new Car("Honk Honk ", "BLUE"); System.out.println(" " + myFirstCar.getColor() + " car " + myFirstCar.horn() + "with " + myFirstCar.getSeatCount() + " seats. "); Motorcycle myFirstMotorcycle = new Motorcycle("Bip Bip ", "WHITE"); System.out.println(" " + myFirstMotorcycle.getColor() + " motorcycle " + myFirstMotorcycle.horn() + "with " + myFirstMotorcycle.getSeatCount() + " seats. "); } } package tr.edu.iku.oop.lab7reyhan; public class Motorcycle { private final int SEAT_COUNT=2; private String sound; private String color; public Motorcycle(String sound, String color ) { this.sound=sound; this.color=color; } public String getColor() { return color; } public int getSeatCount() { return SEAT_COUNT; } public String horn() { return sound; } } package tr.edu.iku.oop.lab7reyhan; public class Car { private final int SEAT_COUNT=6; private String sound ; private String color ; public Car(String sound, String color) { this.sound=sound; this.color=color; } public String getColor() { return color; } public int getSeatCount() { return SEAT_COUNT; } public String horn() { return sound; } } package tr.edu.iku.oop.lab7reyhan; public class Bus { private final int SEAT_COUNT=20; private String sound ; private String color; public Bus(String sound, String color) { this.sound=sound; this.color=color; } public String getColor() { return color; } public int getSeatCount() { return SEAT_COUNT; } public String horn() { return sound; } } |
Örnek 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
package tr.edu.iku.oop.lab7reyhan; public class ShapesReyhan { public static void main(String[] args) { // TODO Auto-generated method stub Circle myFirstCircle = new Circle(3.0, "RED"); System.out.println("Color of the first circle: " + myFirstCircle.getColor()); System.out.println("Area of the first circle: " + myFirstCircle.getArea()); Rectangle myRectangle = new Rectangle(4 , 10 ,"YELLOW"); System.out.println("Color of the first rectangle " + myRectangle.getColor()); System.out.println("Area of the first rectangle: " + myRectangle.getArea()); } } --- package tr.edu.iku.oop.lab7reyhan; public class Circle { private final double PI= 3.14; private double radius; private String color; public Circle(double radius, String color) { this.radius = radius; this.color= color; } public double getArea() { return radius*radius*PI; } public String getColor() { return color; } } --- package tr.edu.iku.oop.lab7reyhan; public class Rectangle { private int length; private int width; private String color; public Rectangle(int length , int width, String color) { this.length=length; this.width=width; this.color=color; } public int getArea() { return length*width; } public String getColor() { return color; } } |
Örnek 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
package tr.edu.iku.oop.lab9; public class Circle { private final double PI = 3.14; private double radius; public Circle( ) { radius = 1; } public Circle (double radius){ this.radius = radius; } public double getArea() { return radius*radius*PI; } public double getArea(String unitType) { if (unitType.equals("metric")) return radius*radius*PI; else if (unitType.equals("imperial")) return radius/2.54 * radius/2.54 * PI ; //convert cm to inch else { System.out.println("unknown unit type choose metric or imperial."); return 0.0; } } public double getCircumference() { return 2*radius*PI; } public double getCircumference(String unitType) { if (unitType.equals("metric")) return 2*radius*PI; else if (unitType.equals("imperial")) return 2 * radius/2.54 * PI ; //convert cm to inch else { System.out.println("unknown unit type choose metric or imperial."); return 0.0; } } } ------------------------------- package tr.edu.iku.oop.lab9; public class Rectangle { private int length; private int width; public Rectangle () { length = 1; width = 1; } public Rectangle(int length , int width) { this.length=length; this.width=width; } public double getArea() { return length*width; } public double getArea(String unitType) { if (unitType.equals("metric")) return length*width; else if (unitType.equals("imperial")) return (length/2.54)*(width/2.54); else { System.out.println("unknown unit type choose metric or imperial."); return 0.0; } } public double getCircumference() { return 2*(length+width); } public double getCircumference(String unitType) { if (unitType.equals("metric")) return 2*(length+width); else if (unitType.equals("imperial")) return 2*((length/2.54)+(width/2.54)); else { System.out.println("unknown unit type choose metric or imperial."); return 0.0; } } } ------------------------------------ package tr.edu.iku.oop.lab9; public class Shapes { public static void main(String[] args) { // TODO Auto-generated method stub Circle myFirstCircle = new Circle(3.0); System.out.println("Area of the circle : "+ myFirstCircle.getArea()); System.out.println("Area of the circle in inch : "+ myFirstCircle.getArea("imperial")); System.out.println("Circumference of the circle : "+ myFirstCircle.getCircumference()); System.out.println("Circumference of the circle in inch : "+ myFirstCircle.getCircumference("imperial")); Circle mySecondCircle = new Circle(); System.out.println("Area of the circle : "+ mySecondCircle.getArea()); System.out.println("Area of the circle in inch : "+ mySecondCircle.getArea("imperial")); System.out.println("Circumference of the circle : "+ mySecondCircle.getCircumference()); System.out.println("Circumference of the circle in inch : "+ mySecondCircle.getCircumference("imperial")); Rectangle myFirstRectangle = new Rectangle(4,10); System.out.println("Area of the rectangle : "+ myFirstRectangle.getArea()); System.out.println("Area of the rectangle in inch : "+ myFirstRectangle.getArea("imperial")); System.out.println("Circumference of the rectangle : "+ myFirstRectangle.getCircumference()); System.out.println("Circumference of the rectangle in inch : "+ myFirstRectangle.getCircumference("imperial")); } } |