Advertisement
malixds_

prac3

Sep 14th, 2022
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. abstract public class Shape {
  2.     public String color;
  3.  
  4.  
  5.     public boolean filled;
  6.     public Shape(){
  7.  
  8.     }
  9.     public Shape(String color, boolean filled){
  10.         this.color=color;
  11.         this.filled=filled;
  12.     }
  13.     public String getColor(){
  14.         return color;
  15.     }
  16.     public void setColor(String color){
  17.  
  18.     }
  19.     public boolean isFilled(){
  20.         return filled;
  21.     }
  22.     public void setFilled(boolean filled){
  23.  
  24.     }
  25.     abstract double getArea();
  26.     abstract double getPerimeter();
  27.     public String toString(){
  28.         return ("Shape: color, radius" + this.color + "radius :"+this.filled);
  29.     }
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. public class Rectangle extends Shape {
  38.     double width;
  39.     double length;
  40.     public Rectangle(){
  41.         width = 1;
  42.         length = 1;
  43.     }
  44.     public Rectangle(double width, double length){
  45.         this.width = width;
  46.         this.length = length;
  47.     }
  48.     public Rectangle(double length, double width, String color, boolean filled){
  49.         this.width = width;
  50.         this.length = length;
  51.         this.color = color;
  52.         this.filled = filled;
  53.     }
  54.     public double getWidth(){
  55.         return width;
  56.     }
  57.     void setWidth(double width){
  58.         this.width = width;
  59.     }
  60.     public double getLength(){
  61.         return length;
  62.     }
  63.     void setLength(double length){
  64.         this.length = length;
  65.     }
  66.     double getArea(){
  67.         return width*length;
  68.     }
  69.     double getPerimeter(){
  70.         return (width+length)*2;
  71.     }
  72.     @Override
  73.     public String toString(){
  74.         return ("Rectangle: width, length" + this.width + "length:" + this.length);
  75.     }
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82. class Circle extends Shape {
  83.     protected double radius;
  84.  
  85.  
  86.     public Circle(){
  87.         this.filled = false;
  88.         this.color = "red";
  89.         radius = 1;
  90.     }
  91.     public Circle(double radius){
  92.         this.radius = radius;
  93.     }
  94.     public Circle(double radius, String color, boolean filled){
  95.         this.radius = radius;
  96.         this.color = color;
  97.         this.filled=filled;
  98.     }
  99.     public double getRadius(){
  100.         return radius;
  101.     }
  102.     public void setRadius(double radius){
  103.         this.radius = radius;
  104.     }
  105.  
  106.     double getArea(){
  107.         return (3.14*radius*radius);
  108.     }
  109.     double getPerimeter(){
  110.         return (2*3.14*radius);
  111.     }
  112.     public String toString(){
  113.         return "Shape: color. radius. filled: " + this.filled +"color :"+this.color+"radius: "+this.radius;
  114.     }
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. class Square extends Rectangle {
  124.     protected double side;
  125.     public Square(){
  126.         this.color = "red";
  127.         this.filled = false;
  128.         side = 1;
  129.     }
  130.     public Square(double side){
  131.         this.side = side;
  132.         this.color = "red";
  133.         this.filled = false;
  134.     }
  135.     public Square(double side, String color, boolean filled){
  136.         this.side = side;
  137.         this.color = color;
  138.         this.filled = filled;
  139.     }
  140.     public double getSide(){
  141.         return side;
  142.     }
  143.     public void setSide(double side){
  144.         this.side = side;
  145.     }
  146.     void setWidth(double side){
  147.         this.side = side;
  148.     }
  149.     void setLength(double side){
  150.         this.side = side;
  151.     }
  152.     @Override
  153.     public String toString(){
  154.         return "Square: side and side: "+ this.side+"side: " + this.side;
  155.     }
  156. }
  157.  
  158.  
  159.  
  160.  
  161.  
  162. public class TestClass {
  163.     public static void main(String[] args) {
  164.  
  165.     }
  166. }
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement