ch08 practice set oops

 package com.company;

// Tommy Game class
class Tommy{
public void hit(){
System.out.println("Hitting the enemy");
}
public void fire(){
System.out.println("Firing on enemy");
}
public void run(){
System.out.println("Running from the enemy");
}
}
// Rectangle class
class rectangle{
float l;
float b;
public void side(){
System.out.println("The length is "+l);
System.out.println("The breadth is "+b);
}
public float area(){
return l*b;
}
public float perimeter(){
return 2*(l+b);
}
}
//Square class
class square{
int n;
public float side(){
return n;
}
public float area(){
return n*n;
}
public float parameter() {
return 4 * n;
}
}


//cellphone class
class cellphone{
public void ring(){
System.out.println("Ringing");
}
public void vib(){
System.out.println("Vibrating");
}
// employee1 class
}
class employee1{
// Properties
int salary;
String name;

// Methods
public int getSalary(){
return salary;
}
public String getName(){
return name;
}
public void setName(String n){
name=n;
}
}
public class CWH_39_PS_oops {
public static void main(String[] args) {
// Problem 1
// employee1 rohan = new employee1();
//// rohan.setName("Rohan");
// rohan.name="prantika";
// rohan.setName("Rohan");
// rohan.salary=4567;
//// System.out.println(rohan.getName());
// System.out.println(rohan.getName());
// System.out.println(rohan.getSalary());

// Problem 2
// cellphone samsung=new cellphone();
// samsung.ring();
// samsung.vib();

// Problem 3
//square first =new square();
//first.n=3;
// System.out.println("The side is "+ first.side());
// System.out.println("The area is "+ first.area());
// System.out.println("The perimeter is "+ first.parameter());

// Problem 4
// rectangle cal =new rectangle();
// cal.l=7;
// cal.b=9;
// cal.side();
// System.out.println(cal.area());
// System.out.println(cal.perimeter());

// Problem 5
Tommy game= new Tommy();
game.hit();
game.fire();
game.run();



}
}

Comments