Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Rakendus.class
Binary file not shown.
15 changes: 15 additions & 0 deletions Rakendus.java
Original file line number Diff line number Diff line change
@@ -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);

}

}
Binary file added Silinder.class
Binary file not shown.
18 changes: 18 additions & 0 deletions Silinder.java
Original file line number Diff line number Diff line change
@@ -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";
}
}