Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 23 Chapter7/Shape5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

public class Shape5 {

public static void main(String[] args) {

Triangle5 t1 = new Triangle5("filled", 4.0, 4.0);
Triangle5 t2 = new Triangle5("Outlined", 8.0, 12.0);

System.out.println("Info for t1: ");
t1.showStyle();
t1.showDim();
System.out.println("Area is " + t1.area());

System.out.println();

System.out.println("Info for t2: ");
t2.showStyle();
t2.showDim();
System.out.println("Area is " + t2.area());

}

}
16 changes: 16 additions & 0 deletions 16 Chapter7/Shape6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

public class Shape6 {

public static void main(String[] args) {
// TODO Auto-generated method stub

Triangle6 t1 = new Triangle6();

System.out.println("Info for t1: ");
t1.showStyle();
t1.showDim();
System.out.println("Area is " + t1.area());

}

}
21 changes: 21 additions & 0 deletions 21 Chapter7/Triangle6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

public class Triangle6 extends TwoDShape6 {

private String styleString;

// A default constructor.
public Triangle6() {
// super();

styleString = "none";
}

double area() {
return getWidth() * getHeight() / 2;
}

void showStyle() {
System.out.println("Triangle is " + styleString);
}

}
45 changes: 45 additions & 0 deletions 45 Chapter7/TwoDShape6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Add more constructors to TwoDShape
public class TwoDShape6 {

private double width;
private double height;

// A default constructor
public TwoDShape6() {

width = height = 0.0;
}

// Parameterized constructor.
TwoDShape6(double w, double h){
width = w;
height = h;
}

// Construct object with equal width and height.
TwoDShape6(double x){
width = height = x;
}

// Accessor methods for width and height.
double getWidth() {
return width;
}

double getHeight() {
return height;
}

void setWidth(double w) {
width = w;
}

void setHeight(double h) {
height = h;
}

void showDim() {
System.out.println("Width and height are " + width + " and " + height);
}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.