Program:-
/*Q1. create a class Employee with following properties and methods:
salary(property/attribute)(int)
getSalary(method returning int)
name(property/attribute)(int)
getName(method returning String)
setName(Method changing name)
*/
class Employee1{
int salary;
String name;
public int getSalary(){
return salary;
}
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
}
/*Q2. Create a class CellPhone with method to print "Ringing...","vibrating..." etc.*/
class CellPhone{
public void ring(){
System.out.println("Ringing...");
}
public void vibrate(){
System.out.println("Vibrating...\n");
}
}
//Q3.create a class Square with a method to initiate its side , calculate area , perimeter etc
class Square{
int side;
public int Area(){
return side * side;
}
public int Perimeter(){
return 4*side;
}
}
//Q4.Create a class Rectangle and repeat 3.
class Rectangle{
int length;
int width;
public int Area(){
return length*width;
}
public int Perimeter(){
return 4*(length+width);
}
}
//Q5.Create a class TommyVecetti for Rockstar Games capable of hitting(print hitting),running,firing etc.
class TommyVecetti{
public void hit(){
System.out.println("Hitting...");
}
public void run(){
System.out.println("running...");
}
public void fire(){
System.out.println("firing..."+"\n");
}
}
//Q6. repeat 4 for a circle.
class Circle{
float radius;
public float Area(){
return 3.142f*radius*radius;
}
public float Perimeter(){
return 2*3.142f*radius;
}
}
public class PracticeSet8V39 {
public static void main(String[] args) {
//Q1.
System.out.println("Q1.");
Employee1 yash = new Employee1();
yash.salary = 150000;
yash.setName("Yash");
System.out.println("The name of employee : "+yash.getName());
System.out.println("And his salary is : "+yash.getSalary()+"\n");
//Q2.
System.out.println("Q2.");
CellPhone no = new CellPhone();
no.ring();
no.vibrate();
//Q3.
System.out.println("Q3.");
Square square = new Square();
square.side = 3;
System.out.println("The area of square having side of length 3 is : "+square.Area());
System.out.println("and its perimeter is : "+square.Perimeter()+"\n");
//Q4.
System.out.println("Q4.");
Rectangle rec = new Rectangle();
rec.length = 8;
rec.width = 3;
System.out.println("The area of Rectangle having length=8 & width=3 is :"+rec.Area());
System.out.println("and its perimeter is : "+rec.Perimeter()+"\n");
//Q5.
System.out.println("Q5.");
TommyVecetti player1 = new TommyVecetti();
player1.hit();
player1.run();
player1.fire();
//Q6.
System.out.println("Q6.");
Circle cir = new Circle();
cir.radius = 4;
System.out.println("The area of Circle having radius 4 is :"+cir.Area());
System.out.println("and its perimeter is : "+cir.Perimeter());
}
}

