Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 30aab2f

Browse files
committed
lesson 6
1 parent 8561f46 commit 30aab2f

File tree

8 files changed

+265
-0
lines changed

8 files changed

+265
-0
lines changed

Lesson_06/Lesson_06.zip

-1.55 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
public class runFunction
2+
{
3+
public static void main(String[]args)
4+
{
5+
int run = 4;
6+
// 1 is square
7+
// 2 is rectangle
8+
// 3 is triangle
9+
// 4 is circle
10+
11+
//variables used for Square object parameters
12+
double squareSide = 2;
13+
14+
//variables used for Rectangle object parameters
15+
double rectLength = 4;
16+
double rectWidth = 7;
17+
18+
//variables used for Triangle object parameters
19+
double sideOne = 5;
20+
double sideTwo = 3;
21+
double sideThree = 4;
22+
23+
//variables used for Circle object parameters
24+
double radius = 4;
25+
26+
Square squareObject = new Square(squareSide); //The Square Object
27+
Rectangle rectObject = new Rectangle(rectLength, rectWidth); //The Rectangle Object
28+
Triangle triObject = new Triangle(sideOne, sideTwo, sideThree); //The Triangle Object
29+
Circle circObject = new Circle(radius); //The Circle Object
30+
31+
if(run == 1)
32+
{
33+
System.out.println("The area of the square is " + squareObject.returnArea());
34+
System.out.println("The perimeter of the square is " + squareObject.returnPerimeter());
35+
}
36+
else if(run == 2)
37+
{
38+
System.out.println("The area of the rectangle is " + rectObject.returnArea());
39+
System.out.println("The perimeter of the rectangle is " + rectObject.returnPerimeter());
40+
}
41+
else if(run == 3)
42+
{
43+
System.out.println("The area of the triangle is " + triObject.returnArea());
44+
System.out.println("The perimeter of the triangle is " + triObject.returnPerimeter());
45+
}
46+
else if(run == 4)
47+
{
48+
System.out.println("The area of the circle is " + circObject.returnArea());
49+
System.out.println("The perimeter of the circle is " + circObject.returnPerimeter());
50+
}
51+
else
52+
{
53+
System.out.println("The variable 'run', has an inappropriate value.");
54+
}
55+
56+
}
57+
}
58+
59+
//The Square class
60+
class Square
61+
{
62+
double side;//variable used for calculation purposes
63+
public Square(double s) //This is what we call the constructor, it acts like parameters (used to import variable from other classes)
64+
{
65+
side = s;
66+
}
67+
68+
public double returnArea() // This function returns the value of the Area
69+
{
70+
return side*side;
71+
}
72+
73+
public double returnPerimeter() // This function returns the value of the Perimeter
74+
{
75+
return 4*side;
76+
}
77+
}
78+
79+
class Rectangle
80+
{
81+
double length, width; //variables used for calculation purposes
82+
public Rectangle(double x, double y) //Constructor
83+
{
84+
length = x;
85+
width = y;
86+
}
87+
88+
public double returnArea() // This function returns the value of the Area
89+
{
90+
return length*width;
91+
}
92+
93+
public double returnPerimeter() // This function returns the value of the Perimeter
94+
{
95+
return 2*(length + width);
96+
}
97+
}
98+
99+
class Triangle
100+
{
101+
double sideOne, sideTwo, sideThree; //variables used for calculation purposes
102+
public Triangle(double s1, double s2, double s3) //Constructor
103+
{
104+
sideOne = s1;
105+
sideTwo = s2;
106+
sideThree = s3;
107+
}
108+
109+
public double returnArea() // This function returns the value of the Area
110+
{
111+
double p = returnPerimeter()/2;
112+
return Math.pow((p) * (p - sideOne) * (p - sideTwo) * (p - sideThree), .5);
113+
}
114+
115+
public double returnPerimeter() // This function returns the value of the Perimeter
116+
{
117+
return sideTwo + sideOne + sideThree;
118+
}
119+
}
120+
121+
class Circle
122+
{
123+
double radius; //variable used for calculation purposes
124+
public Circle(double r) //Constructor
125+
{
126+
radius = r;
127+
}
128+
public double returnArea() // This function returns the value of the Area
129+
{
130+
return Math.PI * radius * radius;
131+
}
132+
133+
public double returnPerimeter() // This function returns the value of the Perimeter
134+
{
135+
return Math.PI * radius * 2;
136+
}
137+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Circle
2+
{
3+
double radius; //variable used for calculation purposes
4+
public Circle(double r) //Constructor
5+
{
6+
radius = r;
7+
}
8+
public double returnArea() // This function returns the value of the Area
9+
{
10+
return Math.PI * radius * radius;
11+
}
12+
13+
public double returnPerimeter() // This function returns the value of the Perimeter
14+
{
15+
return Math.PI * radius * 2;
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Rectangle
2+
{
3+
double length, width; //variables used for calculation purposes
4+
public Rectangle(double x, double y) //Constructor
5+
{
6+
length = x;
7+
width = y;
8+
}
9+
10+
public double returnArea() // This function returns the value of the Area
11+
{
12+
return length*width;
13+
}
14+
15+
public double returnPerimeter() // This function returns the value of the Perimeter
16+
{
17+
return 2*(length + width);
18+
}
19+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Square
2+
{
3+
double side;//variable used for calculation purposes
4+
public Square(double s) //This is what we call the constructor, it acts like parameters (used to import variable from other classes)
5+
{
6+
side = s;
7+
}
8+
9+
public double returnArea() // This function returns the value of the Area
10+
{
11+
return side*side;
12+
}
13+
14+
public double returnPerimeter() // This function returns the value of the Perimeter
15+
{
16+
return 4*side;
17+
}
18+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Triangle
2+
{
3+
double sideOne, sideTwo, sideThree; //variables used for calculation purposes
4+
public Triangle(double s1, double s2, double s3) //Constructor
5+
{
6+
sideOne = s1;
7+
sideTwo = s2;
8+
sideThree = s3;
9+
}
10+
11+
public double returnArea() // This function returns the value of the Area
12+
{
13+
double p = returnPerimeter()/2;
14+
return Math.pow((p) * (p - sideOne) * (p - sideTwo) * (p - sideThree), .5);
15+
}
16+
17+
public double returnPerimeter() // This function returns the value of the Perimeter
18+
{
19+
return sideTwo + sideOne + sideThree;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
public class runFunction
2+
{
3+
public static void main(String[]args)
4+
{
5+
int run = 4;
6+
// 1 is square
7+
// 2 is rectangle
8+
// 3 is triangle
9+
// 4 is circle
10+
11+
double squareSide = 2;
12+
13+
double rectLength = 4;
14+
double rectWidth = 7;
15+
16+
double sideOne = 5;
17+
double sideTwo = 3;
18+
double sideThree = 4;
19+
20+
double radius = 4;
21+
22+
Square squareObject = new Square(squareSide);
23+
Rectangle rectObject = new Rectangle(rectLength, rectWidth);
24+
Triangle triObject = new Triangle(sideOne, sideTwo, sideThree);
25+
Circle circObject = new Circle(radius);
26+
27+
if(run == 1)
28+
{
29+
System.out.println("The area of the square is " + squareObject.returnArea());
30+
System.out.println("The perimeter of the square is " + squareObject.returnPerimeter());
31+
}
32+
else if(run == 2)
33+
{
34+
System.out.println("The area of the rectangle is " + rectObject.returnArea());
35+
System.out.println("The perimeter of the rectangle is " + rectObject.returnPerimeter());
36+
}
37+
else if(run == 3)
38+
{
39+
System.out.println("The area of the triangle is " + triObject.returnArea());
40+
System.out.println("The perimeter of the triangle is " + triObject.returnPerimeter());
41+
}
42+
else if(run == 4)
43+
{
44+
System.out.println("The area of the circle is " + circObject.returnArea());
45+
System.out.println("The perimeter of the circle is " + circObject.returnPerimeter());
46+
}
47+
else
48+
{
49+
System.out.println("The variable run, has an inappropriate value.");
50+
}
51+
52+
}
53+
}

Lesson_06/Lessons/Lesson.zip

11.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)