-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracy marlatt branch #2
Open
TracyMarlatt
wants to merge
11
commits into
siostechcorp:master
Choose a base branch
from
TracyMarlatt:TracyMarlatt-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
32d927e
Create PerimeterCalculator.java
TracyMarlatt 397d318
Create Triangle.java
TracyMarlatt 82f7b2d
Create Shape.java
TracyMarlatt f4bb7f6
Update to Circle.java
TracyMarlatt c100ffa
Update Main.java
TracyMarlatt 76938c1
Update AreaCalculator.java
TracyMarlatt 823b090
Update Rectangle.java
TracyMarlatt 766e4a9
Update Triangle.java
TracyMarlatt 094e5d4
Update Circle.java
TracyMarlatt 0d6524e
Update Rectangle.java
TracyMarlatt 350784c
Update Shape.java
TracyMarlatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 20 additions & 23 deletions
43
plan-for-extension-exercise/src/planForExtensionExercise/AreaCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
package planForExtensionExercise; | ||
|
||
public class AreaCalculator { | ||
public static double calculateArea(Object[] shapes) { | ||
double area = 0.0; | ||
|
||
if (shapes == null) { | ||
return area; | ||
} | ||
|
||
for (Object shape : shapes) { | ||
if (shape == null) { | ||
continue; | ||
} | ||
else if (shape instanceof Circle) { | ||
Circle circle = (Circle)shape; | ||
area += Math.PI * circle.getRadius() * circle.getRadius(); | ||
} | ||
else if (shape instanceof Rectangle) { | ||
Rectangle rectangle = (Rectangle)shape; | ||
area += rectangle.getHeight() * rectangle.getWidth(); | ||
} | ||
} | ||
|
||
return area; | ||
} | ||
|
||
// Calculates the aggregate area for an array of Shapes | ||
public static double calculateArea(Shape[] shapes) { | ||
|
||
double area = 0.0; | ||
|
||
if (shapes == null) { | ||
return area; | ||
} | ||
|
||
for (Shape shape : shapes) { | ||
if (shape == null) { | ||
continue; | ||
} | ||
else { | ||
area += shape.getArea(); | ||
} | ||
} | ||
return area; | ||
} | ||
} |
27 changes: 17 additions & 10 deletions
27
plan-for-extension-exercise/src/planForExtensionExercise/Circle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package planForExtensionExercise; | ||
|
||
public class Circle { | ||
private double radius; | ||
|
||
public Circle(double radius) { | ||
this.radius = radius; | ||
} | ||
|
||
public double getRadius() { | ||
return this.radius; | ||
} | ||
public class Circle extends Shape { | ||
|
||
private double radius; | ||
|
||
public Circle(double radius) { | ||
this.radius = radius; | ||
} | ||
|
||
// Computes its own area | ||
public double getArea() { | ||
return (Math.PI * this.radius * this.radius); | ||
} | ||
|
||
//Computes its own circumference | ||
public double getPerimeter() { | ||
return (2 * Math.PI * this.radius); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
plan-for-extension-exercise/src/planForExtensionExercise/PerimeterCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package planForExtensionExercise; | ||
|
||
public class PerimeterCalculator { | ||
|
||
// Calculates the aggregate perimeter for an array of shapes | ||
public static double calculatePerimeter(Shape[] shapes) { | ||
|
||
double perimeter = 0.0; | ||
|
||
if (shapes == null) { | ||
return perimeter; | ||
} | ||
|
||
for (Shape shape : shapes) { | ||
if (shape == null) { | ||
continue; | ||
} | ||
else { | ||
perimeter += shape.getPerimeter(); | ||
} | ||
} | ||
return perimeter; | ||
} | ||
} |
35 changes: 19 additions & 16 deletions
35
plan-for-extension-exercise/src/planForExtensionExercise/Rectangle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
package planForExtensionExercise; | ||
|
||
public class Rectangle { | ||
private double height; | ||
private double width; | ||
|
||
public Rectangle(double height, double width) { | ||
this.height = height; | ||
this.width = width; | ||
} | ||
|
||
public double getHeight() { | ||
return this.height; | ||
} | ||
|
||
public double getWidth() { | ||
return this.width; | ||
} | ||
public class Rectangle extends Shape { | ||
|
||
private double height; | ||
private double width; | ||
|
||
public Rectangle(double height, double width) { | ||
this.height = height; | ||
this.width = width; | ||
} | ||
|
||
// Computes its own area | ||
public double getArea() { | ||
return (this.height * this.width); | ||
} | ||
|
||
// Computes its own perimeter | ||
public double getPerimeter() { | ||
return (2*this.height + 2*this.width); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
plan-for-extension-exercise/src/planForExtensionExercise/Shape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package planForExtensionExercise; | ||
|
||
public abstract class Shape { | ||
|
||
// Subclasses implement the following methods | ||
abstract double getArea(); | ||
abstract double getPerimeter(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
plan-for-extension-exercise/src/planForExtensionExercise/Triangle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package planForExtensionExercise; | ||
|
||
public class Triangle extends Shape { | ||
|
||
//Triangle may be scalene | ||
private double side1, side2, side3; | ||
|
||
public Triangle(double side1, double side2, double side3) { | ||
this.side1 = side1; | ||
this.side2 = side2; | ||
this.side3 = side3; | ||
} | ||
|
||
// Computes its own area - using Heron's Formula | ||
public double getArea() { | ||
double s = 0.5 * getPerimeter(); | ||
return (Math.sqrt(s * (s-this.side1) * (s-this.side2) * (s-this.side3))); | ||
} | ||
|
||
//Computes its own perimeter | ||
public double getPerimeter() { | ||
return (this.side1 + this.side2 + this.side3); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this abstract class only has methods, it could be an interface instead of an abstract class. Tracy, can you comment on why you made it an abstract class instead of an interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used an abstract class largely because the relationship between Shape and
its subclasses is a very strong, hierarchical one so it seemed to make
sense from an interpretability standpoint. Also it is my understanding that
abstract classes are faster than interfaces and may be preferable in cases
where there is no obvious advantage to using an interface.
On Thu, Feb 5, 2015 at 11:11 AM, Spencer Robinson [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purely for the fun of it, will you please humor me by changing Shape to an interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
On Thu, Feb 5, 2015 at 11:33 AM, Spencer Robinson [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just created a pull request
On Thu, Feb 5, 2015 at 11:34 AM, Tracy Marlatt [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I wasn't very clear. Please update this pull request to include the change, and close the other pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Spencer,
I updated my code in that branch and closed the newest pull request, but
how do I "update" my first pull request?
Thanks, Tracy
On Thu, Feb 5, 2015 at 11:48 AM, Spencer Robinson [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make a commit in the branch and the pull request will automatically be
updated.
On Feb 5, 2015 12:07 PM, "TracyMarlatt" [email protected] wrote: