Professional Documents
Culture Documents
Week 6
SUBMITTED BY: Joyjit Banerjee
RA NO: RA2211003012007
1. Write a Java program to create a class called "Person" with a name
and age attribute. Create two instances of the "Person" class, set
their attributes using the constructor, and print theirname and age.
System.out.println("Person 1:");
System.out.println("Name: " + p1.Name());
System.out.println("Age: " + p1.Age());
System.out.println();
System.out.println("Person 2:");
System.out.println("Name: " + p2.Name());
System.out.println("Age: " + p2.Age());
}
}
2. Write a Java program to create class called "TrafficLight" with
attributes for color and duration, and methods to change the color
and check for red or green.
System.out.println("Initial Light:");
System.out.println("Color: " + l1.getColor());
System.out.println("Time: " + l1.getTime() + " seconds");
System.out.println("Updated Light:");
System.out.println("Color: " + l1.getColor());
System.out.println("Time: " + tl1.getTime() + " seconds");
}
}
Write a Java
program to
perform arithmetic
operations using
method
overloading.
3.
@Override
public void performWork() {
System.out.println("Manager is managing.");
}
}
Write a Java program to create a class called Shape with methods
called getPerimeter() and getArea(). Create a subclass called Circle
that overrides the getPerimeter() and getArea() methods to
calculate the area and perimeter of a circle.
class Shape {
}
interface Sorter {
void sort(int[] arr);
}
rect.resizeWidth(35);
System.out.println("Resized Width:");
rect.display();
8.
rect.resizeHeight(50);
System.out.println("Resized
Height:");
rect.display();
}
}
Write a Java program to
create an interface Flyable
with a method called
fly_obj(). Create three
classes Spacecraft, Airplane, and Helicopter that implement the
Flyable interface. Implement the fly_obj() method for each of the
three classes. Hint :- fly_obj definition – prints the particular object
is flying.
interface F {
void fly();
}
F a = new Plane();
a.fly();
java
package com.addition;
java
package com.subtraction;
java
package com.multiplication;
java
package com.division;
```java
package bubblesort;
```java
package selectionsort;