Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLASE MAIN
- package main;
- import objetos.Rectangulo;
- public class Main {
- public static void main(String[] args) {
- Rectangulo forma = new
- Rectangulo(10,7);
- forma.imprimirFigura();
- }
- }
- //OBJETO RECTANGULO
- package objetos;
- import java.util.Iterator;
- public class Rectangulo {
- private Double largo;
- private Double ancho;
- public Rectangulo(double largo, double ancho) {
- this.largo = largo;
- this.ancho = ancho;
- }
- public Double getLargo() {
- return largo;
- }
- public Double getAncho() {
- return ancho;
- }
- public Double calcularArea() {
- return largo * ancho;
- }
- public void imprimirFigura() {
- for (int i = 0; i < ancho; i++) {
- for (int j = 0; j < largo; j++) {
- if (i == 0 || i == ancho-1) {
- System.out.print("*");
- }
- else if (j == 0 || j == largo-1) {
- System.out.print("*");
- } else {
- System.out.print(" ");
- }
- }
- System.out.print("\n");
- }
- }
- }
- //COLLECION RECTANGULO
- package main;
- import java.util.Iterator;
- import objetos.Rectangulo;
- public class ColeccionRectangulo {
- private Rectangulo[] arreglo;
- public ColeccionRectangulo(int tamanio) {
- arreglo = new Rectangulo[tamanio];
- for (int i = 0; i < tamanio; i++) {
- int largo = (int) (Math.random()*10);
- int ancho = (int) (Math.random()*8);
- Rectangulo rectangulito = new Rectangulo(largo, ancho);
- arreglo[i] = rectangulito;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement