APP Assignment
APP Assignment
Abhisesha Kumaara
REG NO -RA2211026010487
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 their name and age.
age;
name;
}
age;
• Create two instances of the Person class and set their attributes
Person person1 = new Person("Alice", 30);
OUTPUT :
2 . Write a Java program to create a class called "TrafficLight" with attributes for colour
and duration, and methods to change the colour and check for red or green.
int duration;
color.equalsIgnoreCase("red");
color.equalsIgnoreCase("green");
}
public static void main(String[] args) {
trafficLight.changeColor("green");
OUTPUT :
num1 + num2;
if (num2 != 0) {
} else {
}
}
} else {
}
}
OUTPUT :
4 . Write a Java program to create a class called Employee with methods called
work() and getSalary(). Create a subclass called HRManager that overrides the
work() method and adds a new method called addEmployee().
double salary;
= salary;
salary;
}
@Override public
void work() {
System.out.println(getName() + " is managing HR tasks.");
employeeName);
emp1.work();
manager.work();
manager.addEmployee("Bob");
OUTPUT :
5 . 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.
double radius;
radius;
@Override
2 * Math.PI * radius;
OUTPUT :
6 . Write a Java program to create an interface Sortable with a method sort() that
sorts an array of integers in ascending order. Create two classes BubbleSort and
SelectionSort that implement the Sortable interface and provide their own
implementations of the sort() method.
sort(int[] arr);
@Override
boolean swapped;
do {
swapped = false;
n--;
} while (swapped);
minIndex = j;
System.out.println();
OUTPUT :
resizeHeight(int height);
}
height;
width;
height;
width;
height;
System.out.println("\nResized Rectangle:");
System.out.println("Width: " + rectangle.getWidth());
System.out.println("Height: " + rectangle.getHeight());
OUTPUT :
• Flyable interface
interface Flyable { void
fly_obj();
@Override
@Override
public void fly_obj() {
@Override
what's flying:");
spacecraft.fly_obj(); airplane.fly_obj();
helicopter.fly_obj(); }
OUTPUT :
9 . Write a Java program to have the arithmetic functions defined in different user-
defined packages and incorporate all the packages and perform the function in a
single class.
package addition;
package subtraction;
package multiplication;
addition.Addition; import
subtraction.Subtraction; import
multiplication.Multiplication;
OUTPUT :
1. . Create two different packages to compute bubble sort and selection sort.
Write a Java program to implement sorting functions in a single class.
package bubblesort;
arr.length;
boolean swapped;
do {
swapped = false;
n--;
} while (swapped);
package selectionsort;
arr[minIndex]; arr[minIndex] =
temp;
java.util.Arrays; import
bubblesort.BubbleSort; import
selectionsort.SelectionSort;
System.out.println("Original Arrays:");
System.out.println("Array 1: " + Arrays.toString(arr1));
System.out.println("Array 2: " + Arrays.toString(arr2));
BubbleSort.sort(arr1);
SelectionSort.sort(arr2);
System.out.println("\nSorted Arrays:");
OUTPUT :