Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kodutöö #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions Proov2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Proov2{
public static void main(String[] args){
Silinder silinder1=new Silinder(3,2);
System.out.println(silinder1.toString());
}
}
25 changes: 25 additions & 0 deletions Silinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Silinder{
double r, h;
public Silinder(double raadius, double k6rgus){
if(raadius<=0){throw new RuntimeException("Sobimatu pikkus");}
if(k6rgus<=0){throw new RuntimeException("Sobimatu pikkus");}
r=raadius;
h=k6rgus;
}
public double ruumala(){
return Math.PI*h*Math.pow(r, 2);
}

public double pindala(){
return 2*Math.PI*Math.pow(r, 2)+2*Math.PI*r*h;
}

public double kylgpindala(){
return 2*Math.PI*r*h;
}

public String toString(){
return "Silindri ruumala on "+Math.round(ruumala())+" kuupsentimeetrit, pindala on "+Math.round(pindala())+" ruutsentimeetrit ja kylgpindala on "+Math.round(kylgpindala())+" ruutsentimeetrit.";
}

}