Skip to content

Instantly share code, notes, and snippets.

@tipochka
Last active September 21, 2016 09:35
Show Gist options
  • Save tipochka/6cb3741a161f413ece6ee813f3bc3abd to your computer and use it in GitHub Desktop.
Save tipochka/6cb3741a161f413ece6ee813f3bc3abd to your computer and use it in GitHub Desktop.
Rectangle (*). Написать класс Rectangle (Прямоугольник), содержащий размеры (высоту и ширину), и умеющий подсчитывать свои периметр и площадь. Написать клиентский класс RectangleRunner, создающий список прямоугольников и подсчитывающий их суммарную площадь.
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;
}
}
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