Advertisement
blackpab

Zestaw 2 - java

Mar 6th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package prostokat44;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Prostokat44 {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.    
  18.     //Pola klasy lub składowe
  19.     private double w; //wysokosc
  20.     private double s; //szerokosc
  21.  
  22.     public Prostokat44(double w, double s) {
  23.         this.w = w;
  24.         this.s = s;
  25.     }
  26.  
  27.     private Prostokat44() {
  28.         this.s = 0;
  29.         this.w = 0;
  30.     }
  31.    
  32.     /*  Typ zwracanej wartosci tak sam jak typ pola
  33.         Nazwa zaczyna sie od slowa get
  34.         Metoda zawsze publiczna */
  35.    
  36.     //Metody
  37.     public double getW() {
  38.         return w;
  39.     }
  40.    
  41.     public double getS() {
  42.         return s;
  43.     }
  44.    
  45.     public void setW(double w) {
  46.         this.w = w;
  47.     }
  48.    
  49.     public void setS(double s) {
  50.         this.s = s;
  51.     }
  52.    
  53.     public double getPole() {
  54.         return s*w;
  55.     }
  56.    
  57.     public double getObwod() {
  58.         return 2*(s+w);
  59.     }
  60.    
  61.     public static void main(String[] args) {
  62.         Prostokat44 p = new Prostokat44(); //domysle warosci logiczne: false, liczbowe: 0, referencyjne: null;
  63.         p.setS(4);
  64.         p.setW(8);
  65.        
  66.         System.out.println("p: wysokosc = " + p.getW() + " szerokosc = " + p.getS() + " Pole = " + p.getPole()+ " Obwod = " + p.getObwod());
  67.        
  68.         Prostokat44 p2 = new Prostokat44(2, 1);
  69.         System.out.println("p: wysokosc = " + p2.getW() + " szerokosc = " + p2.getS() + " Pole = " + p2.getPole()+ " Obwod = " + p2.getObwod());
  70.     }    
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement