Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract public class Shape {
- public String color;
- public boolean filled;
- public Shape(){
- }
- public Shape(String color, boolean filled){
- this.color=color;
- this.filled=filled;
- }
- public String getColor(){
- return color;
- }
- public void setColor(String color){
- }
- public boolean isFilled(){
- return filled;
- }
- public void setFilled(boolean filled){
- }
- abstract double getArea();
- abstract double getPerimeter();
- public String toString(){
- return ("Shape: color, radius" + this.color + "radius :"+this.filled);
- }
- }
- public class Rectangle extends Shape {
- double width;
- double length;
- public Rectangle(){
- width = 1;
- length = 1;
- }
- public Rectangle(double width, double length){
- this.width = width;
- this.length = length;
- }
- public Rectangle(double length, double width, String color, boolean filled){
- this.width = width;
- this.length = length;
- this.color = color;
- this.filled = filled;
- }
- public double getWidth(){
- return width;
- }
- void setWidth(double width){
- this.width = width;
- }
- public double getLength(){
- return length;
- }
- void setLength(double length){
- this.length = length;
- }
- double getArea(){
- return width*length;
- }
- double getPerimeter(){
- return (width+length)*2;
- }
- @Override
- public String toString(){
- return ("Rectangle: width, length" + this.width + "length:" + this.length);
- }
- }
- class Circle extends Shape {
- protected double radius;
- public Circle(){
- this.filled = false;
- this.color = "red";
- radius = 1;
- }
- public Circle(double radius){
- this.radius = radius;
- }
- public Circle(double radius, String color, boolean filled){
- this.radius = radius;
- this.color = color;
- this.filled=filled;
- }
- public double getRadius(){
- return radius;
- }
- public void setRadius(double radius){
- this.radius = radius;
- }
- double getArea(){
- return (3.14*radius*radius);
- }
- double getPerimeter(){
- return (2*3.14*radius);
- }
- public String toString(){
- return "Shape: color. radius. filled: " + this.filled +"color :"+this.color+"radius: "+this.radius;
- }
- }
- class Square extends Rectangle {
- protected double side;
- public Square(){
- this.color = "red";
- this.filled = false;
- side = 1;
- }
- public Square(double side){
- this.side = side;
- this.color = "red";
- this.filled = false;
- }
- public Square(double side, String color, boolean filled){
- this.side = side;
- this.color = color;
- this.filled = filled;
- }
- public double getSide(){
- return side;
- }
- public void setSide(double side){
- this.side = side;
- }
- void setWidth(double side){
- this.side = side;
- }
- void setLength(double side){
- this.side = side;
- }
- @Override
- public String toString(){
- return "Square: side and side: "+ this.side+"side: " + this.side;
- }
- }
- public class TestClass {
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement