Skip to content
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

Feedback #1

Open
wants to merge 2 commits into
base: feedback
Choose a base branch
from
Open
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
59 changes: 43 additions & 16 deletions Shapes.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
import java.util.*;
import java.util.Scanner;
import java.lang.Math;

public class Shapes{
class Shapes{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the side length: ");

System.out.print("What is the side length for squares? ");
double side = input.nextDouble();

square(side);
}

/*
* N: square
* P: to calculate the area of any square
* I: a side measure (double)
* R:
*/
public static void square(double s){
//side times side
double a = s * s;
System.out.print("What is the base for triangles? ");
double base = input.nextDouble();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice variable names! They clearly represent what value they're storing and their purpose.

System.out.print("What is the height for triangles? ");
double height = input.nextDouble();

triangles(base, height);

System.out.print("What is side 1 triangles? ");
double side1 = input.nextDouble();
System.out.print("What is side 2 triangles? ");
double side2 = input.nextDouble();
System.out.print("What is side 3 triangles? ");
double side3 = input.nextDouble();

trianglesSides(side1, side2, side3);

//generate some output
System.out.println("A square with side " + s + " has an area of " + a);
}//close square method
System.out.print("What is the radius for the circle? ");
double radius = input.nextDouble();

circle(radius);
}
public static void square(double s){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job using static methods here! Can you think of a way to have a return type that isn't void?

double a = s * s;
System.out.println("A square with a side length of " + s + " has an area of " + a);
}
public static void triangles(double b, double h){
double a1 = (1/2.0) * b * h;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to have (1/2.0)? What's a different way of representing this?

System.out.println("A triangle with a base of " + b + " and a height of " + h + " has an area of " + a1);
}
public static void trianglesSides(double s1, double s2, double s3){
double s = (s1 + s2 + s3) / 2.0;
double a = ((s) * (s - s1) * (s - s2) * (s - s3));;
double area = Math.sqrt(a);
System.out.println("A triangle with sides of " + s1 + "," + s2 + "," + s3 + " has an area of " + area);
}
public static void circle(double r){
double a = Math.PI * r * r;
System.out.println("A circl with the radius of " + r + " has an area of " + a);
}
}