assignment2
assignment2
Write a Java program to find the areas of square (side given, x*x) ,rectangle(length and
breadth given , l*b) and triangle (three sides a,b,c given) by ge ng length and breadth of the
rectangle and three sides of the triangle through keyboard using method overloading
concept. (formula for finding area of triangle = squareroot of (s*(s-a) * (s-b) *(s-c) ) where s=
(a+b+c)/2 )
//program
package bhavana;
double s = (a + b + c) / 2.0;
double a = scanner.nextDouble();
double b = scanner.nextDouble();
double c = scanner.nextDouble();
scanner.close();
//output
Enter the side of the square: 2
Enter the length of the rectangle: 5
Enter the breadth of the rectangle: 6
Enter the first side of the triangle: 2
Enter the second side of the triangle: 5
Enter the third side of the triangle: 5
Area of Square: 4.0
Area of Rectangle: 30.0
Area of Triangle: 4.898979485566356
2. Write a Java program for finding volumes of cube(x*x*x), cuboid (l*b*h) and cylinder( pi
//program
scanner.close();
//output
3. 4. Write a heirarchical inheritance program with method overriding using super() in java for
class Student {
int rollno;
String sname;
this.rollno = rollno;
this.sname = sname;
int hours;
super(rollno, sname);
this.hours = hours;
int totalHour() {
int hours;
Par me(int rollno, String sname, int hours, int dura on) {
super(rollno, sname);
this.hours = hours;
int totalHour() {
}
}
//output
Rollno: 100
Dura on in days: 30
Rollno: 101
Dura on in days: 70
4. Write a mul level inheritance program with method overriding using super() in java for
- >TechAssist(empno,ename,wages, salary) -
>SkilledAsst(empno,ename,wages, salary,bonus)
Create LabourTest class to incorporate all the aforemen oned classes and create objects for
all the classes and display the informa on of the respec ve classes
//program
class Labourer {
int empno;
String ename;
this.empno = empno;
this.ename = ename;
}
void display() {
System.out.println("~~~~~Labour's details~~~~~");
int wages;
super(empno, ename);
this.wages = wages;
void display() {
super.display();
System.out.println("~~~~~Assistant's details~~~~~");
int salary;
this.salary = salary;
}
void display() {
super.display();
System.out.println("~~~~~TechAsst's details~~~~~");
int bonus;
SkilledAsst(int empno, String ename, int wages, int salary, int bonus) {
this.bonus = bonus;
void display() {
super.display();
System.out.println("~~~~~SkilledAsst's details~~~~~");
assistant.display();
techAssist.display();
skilledAsst.display();
//output
Labour's details
Assistant's details
Wages: 500
TechAsst's details
Wages: 10000
Salary: 15000
SkilledAsst's details
Wages: 15000
Salary: 20000
Bonus: 10000