Last active
September 21, 2016 09:35
-
-
Save tipochka/6cb3741a161f413ece6ee813f3bc3abd to your computer and use it in GitHub Desktop.
Rectangle (*). Написать класс Rectangle (Прямоугольник), содержащий размеры (высоту и ширину), и умеющий подсчитывать свои периметр и площадь. Написать клиентский класс RectangleRunner, создающий список прямоугольников и подсчитывающий их суммарную площадь.
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
package oop.lesson1.homework.rectange; | |
public class RectangleRunner { | |
public static void main(String[] args) { | |
Rectangle[] listRectangles = {new Rectangle(8, 4), new Rectangle(5, 6), new Rectangle(7, 6)}; | |
System.out.println(sumArea(listRectangles)); | |
} | |
public static int sumArea(Rectangle[] listRectungles) { | |
int sumArea = 0; | |
for (Rectangle rectungle: listRectungles) { | |
sumArea += rectungle.area(); | |
} | |
return sumArea; | |
} | |
} |
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
package oop.lesson1.homework.rectange; | |
public class Rectangle | |
{ | |
private int height; | |
private int width; | |
public Rectangle(int height, int width) { | |
this.height = height; | |
this.width = width; | |
} | |
public int perimeter() { | |
return height*2 + width*2; | |
} | |
public int area() { | |
return height*width; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment