-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: feedback
Are you sure you want to change the base?
Feedback #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job using |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to have |
||
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); | ||
} | ||
} |
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.
Nice variable names! They clearly represent what value they're storing and their purpose.