0% found this document useful (0 votes)
7 views

Java Lab 5-6

Uploaded by

EnRyuu Castadel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java Lab 5-6

Uploaded by

EnRyuu Castadel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

NETAJI SUBHASH ENGINEERING COLLEGE

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE


LEARNING

Course Name: Object Oriented Programming Student Name:


Course Code: PCC CS 593 University Roll No.:

Sl. Exp. Problem Statement D.O.E. D.O.S. Marks Signature Remarks


No. No. 5 15 20
1 5 Create a class named complex 21.08.24 11.09.24
with data members as real and
imaginary. Overload three
constructors to initialize the data
members (i.e. default, normal/
parameterized and through
object initialization). Provide
methods which return objects of
the complex class as the result
for addition, subtraction and
multiplication of two complex
numbers.
Average Marks
Problem Statement: Create a class named complex with data members as real
and imaginary. Overload three constructors to initialize the data members (i.e.
default, normal/ parameterized and through object initialization). Provide
methods which return objects of the complex class as the result for addition,
subtraction and multiplication of two complex numbers.

Program:
import java.io.*;

class Complex{

double real = 0;

double im = 0;

Complex(){

//real = 5;

//im = 3;

Complex(double r, double i){

real = r;

im = i;

Complex(Complex obj){

real = obj.real;

im = obj.im;

Complex addition(Complex num){

double r = real + num.real;

double i = im + num.im;

return (new Complex(r, i));

Complex substraction(Complex num){

double r = real - num.real;

double i = im - num.im;

return (new Complex(r, i));

Complex multiply(Complex num){

double r = (real * num.real) - (im * num.im);


double i = (im * num.real) + (real * num.im);

return (new Complex(r, i));

class day5 {

public static void main(String args[])

throws IOException{

BufferedReader reader = new BufferedReader(new


InputStreamReader(System.in));

while (true){

System.out.print("\nEnter
choice:\nDefault\nParameterized\nCopy\nExit\n->");

String ch1 = reader.readLine();

if (ch1.equals("default")){

Complex num1 = new Complex();

Complex num2 = new Complex();

Complex add = num1.addition(num2);

Complex sub = num1.substraction(num2);

Complex mul = num1.multiply(num2);

System.out.println("Addition: " + add.real + " + (" + add.im +


")i");

System.out.println("Substraction: " + sub.real + " + (" + sub.im +


")i");

System.out.println("Multiplication: " + mul.real + " + (" + mul.im


+ ")i");

else if (ch1.equals("parameterized")){

System.out.print("First number:-\nReal: ");

Double n1 = Double.parseDouble(reader.readLine());

System.out.print("Imagninary: ");

Double n2 = Double.parseDouble(reader.readLine());

System.out.print("Second number:-\nReal: ");

Double n3 = Double.parseDouble(reader.readLine());

System.out.print("Imagninary: ");

Double n4 = Double.parseDouble(reader.readLine());

Complex num1 = new Complex(n1, n2);

Complex num2 = new Complex(n3, n4);

Complex add = num1.addition(num2);


Complex sub = num1.substraction(num2);

Complex mul = num1.multiply(num2);

System.out.println("Addition: " + add.real + " + (" + add.im +


")i");

System.out.println("Substraction: " + sub.real + " + (" + sub.im +


")i");

System.out.println("Multiplication: " + mul.real + " + (" + mul.im


+ ")i");

else if (ch1.equals("copy")){

System.out.print("First number:-\nReal: ");

Double n1 = Double.parseDouble(reader.readLine());

System.out.print("Imagninary: ");

Double n2 = Double.parseDouble(reader.readLine());

Complex num1 = new Complex(n1, n2);

Complex num2 = new Complex(num1);

Complex add = num1.addition(num2);

Complex sub = num1.substraction(num2);

Complex mul = num1.multiply(num2);

System.out.println("Addition: " + add.real + " + (" + add.im +


")i");

System.out.println("Substraction: " + sub.real + " + (" + sub.im +


")i");

System.out.println("Multiplication: " + mul.real + " + (" + mul.im


+ ")i");

else if (ch1.equals("exit")){

System.out.println("GoodBye... Never See You Again!!!");

break;

else

System.out.println("Enter proper choice");

}
Output:
NETAJI SUBHASH ENGINEERING COLLEGE
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE
LEARNING

Course Name: Object Oriented Programming Student Name:


Course Code: PCC CS 593 University Roll No.:

Sl. Exp. Problem Statement D.O.E. D.O.S. Marks Signature Remarks


No. No. 5 15 20
1 6 Write a program to maintain the 11.09.24 18.09.24
office database using
inheritance.

Average Marks
Problem Statement: Write a program to maintain the office database using
inheritance. Superclass is Employee that contains the information as follows:
Emp_code, Emp_name, Address, Ph_no, Da=10%, Hra=20%. The inheritance
properties held by the problem is as follows:

Teaching class contains its own attributes Subject Specialization, Designation


and Office class contains own attribute Position.
Faculty class has another attribute called Research Area and Technical class has
another attribute called Tech Expert Area. Create all the lowest level classes with
each class having their own Basic Pay. Implement the inheritance concept of
above figure and calculate the salary statement for each employee.

Program:
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

class Employee{

int emp_code;

String emp_name;

String address;

String phone_no;

Double da=0.1;

Double hra=0.2;

int basic_pay;

Employee(int code, String name, String ad, String phone){

emp_code = code;

emp_name = name;
address = ad;

phone_no = phone;

void increase_da(int increase){

da += increase;

void increase_hra(int increase){

hra += increase;

void show_da_hra(){

System.out.println("DA: " + da);

System.out.println("HRA: " + hra);

void set_basic_pay(int pay){

basic_pay = pay;

void show_salary(){

Double salary = basic_pay + basic_pay*da + basic_pay*hra;

System.out.println("Salary: " + salary);

void show_details(){

System.out.println("\nEmployee Details:-");

System.out.println("----------------");

System.out.println("Employee Code: " + emp_code);

System.out.println("Employee Name: " + emp_name);

System.out.println("Employee Address: " + address);

System.out.println("Employee Phone Number: " + phone_no);

System.out.println("Basic Pay: " + basic_pay);

class Teaching extends Employee{

String subject_specialization;

String designation;

Teaching(int code, String name, String ad, String phone, String subject, String
desig){

super(code, name, ad, phone);

subject_specialization = subject;
designation = desig;

void change_designation(String desig){

designation = desig;

class Office extends Employee{

String position;

Office(int code, String name, String ad, String phone, String pos){

super(code, name, ad, phone);

position = pos;

void change_position(String pos){

position = pos;

class Faculty extends Teaching{

String research_area;

Faculty(int code, String name, String ad, String phone, String subject, String
desig, String research){

super(code, name, ad, phone, subject, desig);

research_area = research;

void show_more_details(){

System.out.println("Subject Specialization: " + subject_specialization);

System.out.println("Designation: " + designation);

System.out.println("Research Area: " + research_area);

class Technical extends Teaching{

String tech_expert_area;

Technical(int code, String name, String ad, String phone, String subject, String
desig, String tech){

super(code, name, ad, phone, subject, desig);

tech_expert_area = tech;

void show_more_details(){

System.out.println("Subject Specialization: " + subject_specialization);


System.out.println("Designation: " + designation);

System.out.println("Tech Expert Area: " + tech_expert_area);

class Administrative extends Office{

Administrative(int code, String name, String ad, String phone, String pos){

super(code, name, ad, phone, pos);

void show_more_details(){

System.out.println("Position: " + position);

class Accounts extends Office{

Accounts(int code, String name, String ad, String phone, String pos){

super(code, name, ad, phone, pos);

void show_more_details(){

System.out.println("Position: " + position);

class day6 {

public static void main(String[] args)

throws IOException{

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

while (true){

System.out.println("\nEnter Employee Details:-");

System.out.print("Employee Code: ");

int code = Integer.parseInt(reader.readLine());

System.out.print("Employee Name: ");

String name = reader.readLine()

System.out.print("Employee Address: ");

String address = reader.readLine();

System.out.print("Employee Phone Number: ");

String phone = reader.readLine();

System.out.print("Enter
department:\nfaculty\ntechnical\nadministrative\naccounts\n->");

String ch = reader.readLine();
if (ch.equals("faculty")){

System.out.print("Enter your subject specialization: ");

String subject = reader.readLine();

System.out.print("Enter designation: ");

String desig = reader.readLine();

System.out.print("Enter Research area: ");

String research = reader.readLine();

Faculty emp = new Faculty(code, name, address, phone, subject, desig,


research);

System.out.print("Enter basic pay: ");

int pay = Integer.parseInt(reader.readLine());

emp.set_basic_pay(pay);

emp.show_details();

emp.show_more_details();

System.out.println("\nThe salary of the given employee is:-");

emp.show_salary();

else if (ch.equals("technical")){

System.out.print("Enter your subject specialization: ");

String subject = reader.readLine();

System.out.print("Enter designation: ");

String desig = reader.readLine();

System.out.print("Enter Tech Expert Area: ");

String tech = reader.readLine();

Technical emp = new Technical(code, name, address, phone, subject,


desig, tech);

System.out.print("Enter basic pay: ");

int pay = Integer.parseInt(reader.readLine());

emp.set_basic_pay(pay);

emp.show_details();

emp.show_more_details();

System.out.println("\nThe salary of the given employee is:-");

emp.show_salary();

else if (ch.equals("administrative")){

System.out.print("Enter position: ");

String pos = reader.readLine();


Administrative emp = new Administrative(code, name, address, phone,
pos);

System.out.print("Enter basic pay: ");

int pay = Integer.parseInt(reader.readLine());

emp.set_basic_pay(pay);

emp.show_details();

emp.show_more_details();

System.out.println("\nThe salary of the given employee is:-");

emp.show_salary();

else if (ch.equals("accounts")){

System.out.print("Enter position: ");

String pos = reader.readLine();

Administrative emp = new Administrative(code, name, address, phone,


pos);

System.out.print("Enter basic pay: ");

int pay = Integer.parseInt(reader.readLine());

emp.set_basic_pay(pay);

emp.show_details();

emp.show_more_details();

System.out.println("\nThe salary of the given employee is:-");

emp.show_salary();

else{

System.out.println("Enter properly next time, if you ever get a next


time");

System.out.println("\n");

continue;

System.out.print("\nDo you wish to exit?(y/n): ");

String exit = reader.readLine();

if (exit.equals("y")){

System.out.println("Thank you for using the program");

break;

}
Output:

You might also like