Bruhhhhh
Bruhhhhh
Bruhhhhh
Q2. Design a class for student entity and consider relevent abstract data. Accept and display the
data for 5 objects using array ofobjects.
import java.util.Scanner;
class Student
String name;
int age;
int rollno;
String bloodgroup;
name=n;
age=a;
rollno=r;
bloodgroup=bg;
void display()
System.out.println("name:"+name);
System.out.println("age:"+age);
System.out.println("roll no:"+rollno);
System.out.println("blood group:"+bloodgroup);
{
Scanner sc = new Scanner(System.in);
for(int i=0;i<5;i++)
System.out.println("Enter name:");
String name=sc.nextLine();
System.out.println("Enter age:");
int age=sc.nextInt();
sc.nextLine();
String bloodgroup=sc.nextLine();
for(int i=0;i<5;i++)
s[i].display();
}
Q3.Design a class 'Complex 'with data members for real and imaginary part. Provide detault and
Parameterized constructors. Write a program to perform arithmetic operations of two complex
numbers
// Design a class 'Complex 'with data members for real and imaginary part. Provide
import java.util.*;
class Complex40 {
double real;
double imaginary;
Complex40()
real = 0;
imaginary = 0;
this.real = real;
this.imaginary = imaginary;
{
return new Complex40(this.real - other.real, this.imaginary - other.imaginary);
void display()
if (imaginary > 0) {
} else {
sum.display();
difference.display();
Q5. Design and develop inheritance for a given case study, identiff objects and relationships and
implement inheritance wherever applicable.
Employee class with Emp_name, Emp_id, Address, Mail-id, and Mobile-no as members. Inherit the
classes, Programmer ,Assistant Professor, Associate Professor and Professor from employee class
Add Basic Pay (BP) AS the member of all the classes with 97% of BP AS DA, l0 % of Bp as HRA, 12% of
BP as PF,0.1 percent of BP for staff club fund.
Generate pay slips for the employees with their gross and net salary
import java.util.Scanner;
class Employee {
String emp_name;
int emp_id;
String address;
String mail_id;
String mobile_no;
float BP;
void getEmployeeDetails() {
emp_name = sc.nextLine();
address = sc.nextLine();
mail_id = sc.nextLine();
mobile_no = sc.nextLine();
void generatePaymentSlip() {
DA = 0.97f * BP;
PF = 0.12f * BP;
gross_salary = BP + DA + HRA;
System.out.println("\n++++++Employee details++++++");
System.out.println("+++++++Pay Slip++++++++");
}
class Programmer extends Employee {
void basic_pay() {
BP = sc.nextFloat();
void basic_pay() {
BP = sc.nextFloat();
void basic_pay() {
BP = sc.nextFloat();
void basic_pay() {
BP = sc.nextFloat();
}
}
int choice;
do {
System.out.println("1. Programmer");
System.out.println("4. Professor");
System.out.println("5. Exit");
choice = sc.nextInt();
switch (choice) {
case 1:
prg.getEmployeeDetails();
prg.basic_pay();
prg.generatePaymentSlip();
break;
case 2:
A1.getEmployeeDetails();
A1.basic_pay();
A1.generatePaymentSlip();
break;
case 3:
AssociateProfessor B1 = new AssociateProfessor();
B1.getEmployeeDetails();
B1.basic_pay();
B1.generatePaymentSlip();
break;
case 4:
C1.getEmployeeDetails();
C1.basic_pay();
C1.generatePaymentSlip();
break;
case 5:
System.out.println("Successfully Exited!!");
break;
default:
sc.close();
Q6.Design a base class shape with two double type values and member functions to input the data
and compute_areaQ for calculating area irf figure. Derive two classes' triangle and rectangle. Make
compute_areaQ as abstract function and redefine this function in the derived class to suit their
requirements. Write a program that accepts dimensions of trianglelrectangle and display calculated
area. lmplement dynamic binding :for given case study
import java.util.*;
double value1;
double value2;
void input()
value1 = sc.nextInt();
value2 = sc.nextInt();
void compute_area()
double area;
void compute_area()
double area;
}
class Same {
int choice;
System.out.println("\n1.Traingle\n2.Rectangle\n3.exit");
System.out.println("enter choice:");
choice= sc.nextInt();
do {
switch (choice) {
case 1:
t.input();
t.compute_area();
case 2:
r.input();
r.compute_area();
case 3:
default: {
System.out.println("invalid input");
while(choice!=3);
}
Q7. Design and develop a context for given case study and implement an interface for Vehicles
Consider the example of vehicles like bicycle, car, and bike. All Vehicles have common functionalities
such as Gear Change, Speed up and apply breaks 'Make an interface and put all these common
functionalities. Bicycle, Bike, Car classes should be implemented tbr all these functionalities in their
own class in their own way.
import java.util.Scanner;
interface Vehicles {
void gearChange();
void speedUp();
void applyBrakes();
@Override
@Override
System.out.println("Speed up in bicycle");
@Override
}
class Car implements Vehicles {
@Override
@Override
System.out.println("Speed up in car");
@Override
@Override
@Override
System.out.println("Speed up in bike");
@Override
class Main2 {
int choice;
do {
System.out.println("Choose vehicle:");
choice = sc.nextInt();
switch (choice) {
case 1:
by.gearChange();
by.speedUp();
by.applyBrakes();
break;
case 2:
c.gearChange();
c.speedUp();
c.applyBrakes();
break;
case 3:
Bike bi = new Bike();
bi.gearChange();
bi.speedUp();
bi.applyBrakes();
break;
case 4:
System.out.println("Exited successfully");
break;
default:
break;
Q8. Implement a program to handle Arithmetic exception, Array Index Out OfBounds.The user
enters two numbers Numl and Num2. The division of Numl and Num2 is displayed. If Numl and
Num2 were not integers, the program would throw a Number Format Exception. If Num2 were zero,
the program would throw an Arithmetic Exception. Display the exception.
import java.util.*;
import java.io.IOException;
class Ex {
try{
int num2=Integer.parseInt(value2);
int div=num1/num2;
catch (NumberFormatException e)
catch(ArithmeticException e)