Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /** Sphere class
  2. *
  3. * @author Ivan Filipov
  4. * @version 25Jun2019
  5. *
  6. */
  7. public class Sphere {
  8.  
  9. double radius;
  10.  
  11. Sphere(){
  12. radius = 1;
  13. }
  14.  
  15. Sphere(double newRadius){
  16. radius = newRadius;
  17. }
  18.  
  19. double getSurfaceArea() {
  20. return (Math.PI * Math.pow(radius, 2)) * 4;
  21. }
  22.  
  23. boolean checkRadius() {
  24. if(radius > 0) {
  25. return true;
  26. }
  27. return false;
  28. }
  29.  
  30.  
  31. public static void main(String[] args) {
  32.  
  33. Sphere sphere1 = new Sphere(12);
  34.  
  35. if(sphere1.checkRadius()) {
  36. System.out.println("Sphere 1: ");
  37. System.out.println("Radius: " + sphere1.radius);
  38. System.out.println("Surface area: " + sphere1.getSurfaceArea());
  39. System.out.println("checkRadius(): " + sphere1.checkRadius());
  40. }
  41.  
  42. Sphere sphere2 = new Sphere(-15);
  43.  
  44. if(sphere2.checkRadius()) {
  45.  
  46. System.out.println("Sphere 2: ");
  47. System.out.println("Radius: " + sphere2.radius);
  48. System.out.println("Surface area: " + sphere2.getSurfaceArea());
  49. System.out.println("checkRadius(): " + sphere2.checkRadius());
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement