Commit de701a65 authored by luke.bullas's avatar luke.bullas

Completed Tasks

parent 89aec285
No preview for this file type
......@@ -41,7 +41,7 @@ The `Square` class should store the information and methods related to a square
The `Rectangle` class should store the information and methods related to a Rectangle shape.
1. Instead of using `size` you should use `width` and `hieght` to represent the width and height of the rectangle.
1. Instead of using `size` you should use `width` and `height` to represent the width and height of the rectangle.
2. `Rectangle` should have two constructors. The first should have no parameters and set the `width` equal to 3 and the `height` equal to 4. The second should take a two integer parameter and uses them to set the `width` and `height` (in that order).
3. You should be able to use the `getWidth()` and `setWidth()` methods properly for the `Rectangle`.
4. You should be able to use the `getHeight()` and `setHeight()` methods properly for the `Rectangle`.
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -2,5 +2,11 @@ public class App {
public static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3);
shape1.draw();
Shape shape2 = new Square(3);
shape2.draw();
Shape shape3 = new Rectangle(3);
shape3.draw();
}
}
......@@ -41,7 +41,7 @@ The `Square` class should store the information and methods related to a square
The `Rectangle` class should store the information and methods related to a Rectangle shape.
1. Instead of using `size` you should use `width` and `hieght` to represent the width and height of the rectangle.
1. Instead of using `size` you should use `width` and `height` to represent the width and height of the rectangle.
2. `Rectangle` should have two constructors. The first should have no parameters and set the `width` equal to 3 and the `height` equal to 4. The second should take a two integer parameter and uses them to set the `width` and `height` (in that order).
3. You should be able to use the `getWidth()` and `setWidth()` methods properly for the `Rectangle`.
4. You should be able to use the `getHeight()` and `setHeight()` methods properly for the `Rectangle`.
......
public class Rectangle extends Shape {
public Rectangle() {
super();
}
public Rectangle(int i) {
super(i);
}
@Override
public void draw() {
for (int loop1=0; loop1<size; loop1++){
for (int loop2=loop1; loop2<(size-1); loop2++) {
System.out.print(" ");
}
System.out.print("/");
for (int loop2=0; loop2<loop1; loop2++){
System.out.print(" ");
}
System.out.println("\\");
}
for (int loop1=0; loop1<size; loop1++){
System.out.print("--");
}
System.out.println("");
}
@Override
public float area() {
float area = width * height;
return area;
}
@Override
public float circumference() {
float circ = (width*2) + (height*2);
return circ;
}
}
No preview for this file type
abstract public class Shape {
protected int size;
protected float height;
protected float width;
abstract public void draw();
abstract public float area();
abstract public float circumference();
public int getSize() { return size; }
public void setSize(int size) { this.size = size; }
public float getHeight() { return height; }
public void setHeight(float height) { this.height = height; }
public float getWidth() { return width; }
public void setWidth(float width) { this.width = width; }
public Shape(){
this.size = 3;
this.height = 4;
this.width = 3;
}
public Shape(int size){
this.size = size;
}
public Shape(float width){
this.width = width;
}
}
public class Square extends Shape{
public Square() {
super();
}
public Square(int i) {
super(i);
}
@Override
public void draw() {
for (int loop1=0; loop1<size; loop1++){
for (int loop2=loop1; loop2<(size-1); loop2++) {
System.out.print(" ");
}
System.out.print("/");
for (int loop2=0; loop2<loop1; loop2++){
System.out.print(" ");
}
System.out.println("\\");
}
for (int loop1=0; loop1<size; loop1++){
System.out.print("--");
}
System.out.println("");
}
@Override
public float area() {
float fSize = size;
float area = 1f * fSize * fSize;
return area;
}
@Override
public float circumference() {
float fSize = size;
float circ = fSize + fSize +fSize +fSize;
return circ;
}
}
\ No newline at end of file
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment