package introduction; /** * Παρουσιάζει την βασική δομή της κλάσης υπακούοντας στους κανόνες της ενσωμάτωσης * @author Lefteris Moussiades */ public class Trigwno { //instance variables private double basi; private double ipsos; //constructor public Trigwno(double b, double i) { if (b < 0 || i < 0) { throw new RuntimeException(); } basi = b; ipsos = i; } //constructor public Trigwno() { basi = 2; ipsos = 2; } //getter public double getBasi() { return basi; } //setter public void setBasi(double b) { if (b < 0) { throw new RuntimeException(); } basi = b; } //getter public double getIpsos() { return ipsos; } //setter public void setIpsos(double i) { if (i < 0) { throw new RuntimeException(); } ipsos = i; } // instance function public double getEmbadon() { return basi * ipsos / 2; } // instance function public void print(String varName) { System.out.println("ipsos " + varName + " = " + ipsos); System.out.println("basi " + varName + " = " + basi); System.out.println("embadon " + varName + " = " + getEmbadon()); } //static function public static void print(Trigwno t, String varName) { System.out.println("ipsos " + varName + " = " + t.ipsos); System.out.println("basi " + varName + " = " + t.basi); System.out.println("embadon " + varName + " = " + t.getEmbadon()); } // Note that main is also a static function public static void main(String[] args) { Trigwno t1 = new Trigwno(2, 5), t2 = new Trigwno(); t1.print("t1"); System.out.println("-------------------"); t2.print("t2"); System.out.println("-------------------"); print(t1, "t1"); } }