diff --git a/Rakendus.class b/Rakendus.class new file mode 100644 index 0000000..5a21e14 Binary files /dev/null and b/Rakendus.class differ diff --git a/Rakendus.java b/Rakendus.java new file mode 100644 index 0000000..47dffe3 --- /dev/null +++ b/Rakendus.java @@ -0,0 +1,15 @@ +public class Rakendus{ + + public static void main(String[] args){ + + Silinder s1 = new Silinder(2, 3); + Silinder s2 = new Silinder(4.5, 1); + Silinder s3 = new Silinder(5, 2); + + System.out.println(s1); + System.out.println(s2); + System.out.println(s3); + + } + +} \ No newline at end of file diff --git a/Silinder.class b/Silinder.class new file mode 100644 index 0000000..ce368ff Binary files /dev/null and b/Silinder.class differ diff --git a/Silinder.java b/Silinder.java new file mode 100644 index 0000000..45dd531 --- /dev/null +++ b/Silinder.java @@ -0,0 +1,18 @@ +public class Silinder{ + double h, r; + public Silinder(double korgus, double laius){ + if(korgus<=0){throw new RuntimeException("Sobimatu pikkus");} + if(laius <=0){throw new RuntimeException("Sobimatu laius");} + h = korgus; + r = laius; + } + public double pindala(){ + return (2*Math.PI*Math.pow(r,2)) + (2*Math.PI*h); + } + public double ruumala(){ + return Math.PI*Math.pow(r,2)*h; + } + public String toString(){ + return "Silinder korgusega "+h+" ja laiusega "+r+" andmed:\nPindala: "+pindala()+"\nRuumala: "+ruumala()+"\n"; + } +} \ No newline at end of file