Advertisement
GSculerlor

Circle

Oct 12th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package OverloadOverride;
  2.  
  3. public class Circle {
  4.     public static final double DEFAULT_RADIUS = 8.8;
  5.     public static final String DEFAULT_COLOR = "red";
  6.    
  7.     private double radius;
  8.     private String color;
  9.    
  10.     public Circle() {
  11.         radius = DEFAULT_RADIUS;
  12.         color = DEFAULT_COLOR;
  13.     }
  14.    
  15.     public Circle(double radius) {
  16.         this.radius = radius;
  17.         color = DEFAULT_COLOR;
  18.     }
  19.    
  20.     public Circle(double radius, String color) {
  21.         this.radius = radius;
  22.         this.color = color;
  23.     }
  24.    
  25.     public double getRadius() {
  26.         return radius;
  27.     }
  28.    
  29.     public void setRadius(double radius) {
  30.         this.radius = radius;
  31.     }
  32.    
  33.     public String getColor() {
  34.         return color;
  35.     }
  36.    
  37.     public void setCOlor(String color) {
  38.         this.color = color;
  39.     }
  40.    
  41.     public String toString() {
  42.         return "Circle with radius = " + radius + " and color of " + color;
  43.     }
  44.    
  45.     public double getArea() {
  46.         return radius*radius*Math.PI;
  47.     }
  48.    
  49.     public static void main(String args[]) {
  50.         Circle b = new Circle();
  51.         double f;
  52.         f = b.getArea();
  53.         System.out.println(f);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement