Skip to content

Commit ad68535

Browse files
Chapter 8 Practice Set Solutions
1 parent 37a68be commit ad68535

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Square {
2+
int side;
3+
4+
public int perimeter() {
5+
return (4 * side);
6+
}
7+
8+
public int area() {
9+
return side * side;
10+
}
11+
}
12+
13+
public class cwh_39_ps_pr_03 {
14+
public static void main(String args[]) {
15+
Square sq = new Square();
16+
sq.side = 5;
17+
System.out.println(sq.perimeter());
18+
System.out.println(sq.area());
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Rectangle {
2+
int length;
3+
int breadth;
4+
5+
public int perimeter() {
6+
return (2 * length * breadth);
7+
}
8+
9+
public int area() {
10+
return length * breadth;
11+
}
12+
}
13+
14+
public class cwh_39_ps_pr_04 {
15+
public static void main(String args[]) {
16+
Rectangle rec = new Rectangle();
17+
rec.length = 5;
18+
rec.breadth = 4;
19+
System.out.println(rec.perimeter());
20+
System.out.println(rec.area());
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class TommyVecetti{
2+
public void hit(){
3+
System.out.println("Hitting the enemy");
4+
}
5+
public void run(){
6+
System.out.println("Running from the enemy");
7+
}
8+
public void fire(){
9+
System.out.println("Firing on the enemy");
10+
}
11+
}
12+
13+
public class cwh_39_ps_pr_05 {
14+
public static void main(String args[]) {
15+
TommyVecetti player = new TommyVecetti();
16+
player.hit();
17+
player.run();
18+
player.fire();
19+
}
20+
}

0 commit comments

Comments
 (0)