Facebook
From Chartreuse Crow, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 128
  1. public class Kwadrat {
  2.  
  3.         private static int id;
  4.         public int dlugosc;
  5.  
  6.         public Kwadrat(){
  7.             this.dlugosc = 1;
  8.             System.out.println("Stworzono kwadrat o boku 1.");
  9.         }
  10.         public Kwadrat(int b) throws IllegalArgumentException{
  11.             if(b > 0) {
  12.                 this.dlugosc = b;
  13.                 System.out.println("Stworzono kwadrat o boku "+ this.getDlugosc() +".");
  14.             }
  15.             else throw new IllegalArgumentException();
  16.         }
  17.         public Kwadrat(Kwadrat k1)
  18.         {
  19.             this.dlugosc = k1.dlugosc;
  20.             System.out.println("Stworzono kwadrat o boku "+ k1.getDlugosc() +".");
  21.         }
  22.         public int getDlugosc(){
  23.             return this.dlugosc;
  24.         }
  25.         public int getId(){
  26.             return this.id;
  27.         }
  28.         public int pole(){
  29.             return (this.dlugosc*this.dlugosc);
  30.         }
  31.         public static class Prostokat extends Kwadrat
  32.         {
  33.             private int szerokosc;
  34.  
  35.             public Prostokat() {
  36.                 this.dlugosc = 1;
  37.                 this.szerokosc = 2;
  38.                 System.out.println("Stworzono prostokat o bokach "+ this.getDlugosc() +" i " + this.getSzerokosc() +".");
  39.             }
  40.             public Prostokat(int a, int b) throws IllegalArgumentException{
  41.                 if(a > 0 && b > 0) {
  42.                     this.dlugosc = a;
  43.                     this.szerokosc = b;
  44.                     System.out.println("Stworzono prostokat o bokach "+ this.getDlugosc() +" i " + this.getSzerokosc() +".");
  45.                 }
  46.                 else throw new IllegalArgumentException();
  47.             }
  48.             public Prostokat(Prostokat p1) {
  49.                 this.dlugosc = p1.dlugosc;
  50.                 this.szerokosc = p1.szerokosc;
  51.                 System.out.println("Stworzono prostokat o bokach "+ this.getDlugosc() +" i " + this.getSzerokosc() +".");
  52.             }
  53.             public int getSzerokosc() {
  54.                 return this.szerokosc;
  55.             }
  56.             public int pole() {
  57.                 return (getDlugosc() * getSzerokosc());
  58.             }
  59.         }
  60.  
  61. }
  62.