Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Sphere class
- *
- * @author Ivan Filipov
- * @version 25Jun2019
- *
- */
- public class Sphere {
- double radius;
- Sphere(){
- radius = 1;
- }
- Sphere(double newRadius){
- radius = newRadius;
- }
- double getSurfaceArea() {
- return (Math.PI * Math.pow(radius, 2)) * 4;
- }
- boolean checkRadius() {
- if(radius > 0) {
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- Sphere sphere1 = new Sphere(12);
- if(sphere1.checkRadius()) {
- System.out.println("Sphere 1: ");
- System.out.println("Radius: " + sphere1.radius);
- System.out.println("Surface area: " + sphere1.getSurfaceArea());
- System.out.println("checkRadius(): " + sphere1.checkRadius());
- }
- Sphere sphere2 = new Sphere(-15);
- if(sphere2.checkRadius()) {
- System.out.println("Sphere 2: ");
- System.out.println("Radius: " + sphere2.radius);
- System.out.println("Surface area: " + sphere2.getSurfaceArea());
- System.out.println("checkRadius(): " + sphere2.checkRadius());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement