yanivtamari

targil square square

Jun 12th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public class square {
  2.     private int length, width;
  3.  
  4.     public square(int length, int width) {
  5.         this.length = length;
  6.         this.width = width;
  7.     }
  8.  
  9.     public square() {
  10.         length = 10;
  11.         width = 10;
  12.     }
  13.  
  14.     public int getLength() {
  15.         return length;
  16.     }
  17.  
  18.     public void setLength(int length) {
  19.         this.length = length;
  20.     }
  21.  
  22.     public int getWidth() {
  23.         return width;
  24.     }
  25.  
  26.     public void setWidth(int width) {
  27.         this.width = width;
  28.     }
  29.  
  30.     public String scope() {
  31.         String calc = width > 0 && length > 0 ? "the scope of the Square is: " + ((width * 2) + (length * 2)) : "the number is under 0";
  32.         return calc;
  33.     }
  34.  
  35.     public String area() {
  36.         String calc = width > 0 && length > 0 ? "the area of the Square is: " + (width * length) : "the number is under 0";
  37.         return calc;
  38.     }
  39.  
  40.     public void printstars() {
  41.         for (int i = 0; i < length; i++) {
  42.             for (int j = 0; j < width; j++) {
  43.                 System.out.print("*");
  44.             }
  45.             System.out.println();
  46.         }
  47.     }
  48.     public void printuserch(char ch) {
  49.         for (int i = 0; i < length; i++) {
  50.             for (int j = 0; j < width; j++) {
  51.                 System.out.print(ch);
  52.             }
  53.             System.out.println();
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment