0% found this document useful (0 votes)
13 views10 pages

Java Program for Complex Numbers & Salary

The document contains multiple Java assignments demonstrating object-oriented programming concepts. It includes implementations for complex number operations, employee salary calculations, area calculations for shapes, and vehicle interfaces with classes for Bicycle, Car, and Bike. Each assignment features user input and basic error handling.

Uploaded by

yashpuri6861
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Java Program for Complex Numbers & Salary

The document contains multiple Java assignments demonstrating object-oriented programming concepts. It includes implementations for complex number operations, employee salary calculations, area calculations for shapes, and vehicle interfaces with classes for Bicycle, Car, and Bike. Each assignment features user input and basic error handling.

Uploaded by

yashpuri6861
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Assignment1

Package Assignments;
import [Link].*;

public class complex {


//DEFINING VARIABLE
public double real;
public double img;
//default constructor
public complex() {
[Link]=0;
[Link]=0;
}
//Parameterized Constructor
public complex(double r, double i) {
[Link]=r;
[Link]=i;
}

public static void main(String[] args) {


// TODO Auto-generated method stub

Scanner sc=new Scanner([Link]);


[Link]("Enter complex number1 real part:");
double real1 = [Link]();
[Link]("Enter Complex number1 img part: ");
double img1 = [Link]();
[Link]("Enter complex number2 real part:");
double real2=[Link]();
[Link]("Enter Complex number2 img part: ");
double img2=[Link]();
complex c1=new complex(real1,img1 );
complex c2=new complex(real2,img2 );
[Link]("Select one : 1. addition 2.
substraction 3. multiplication [Link] [Link] ");
int choice = [Link]();
switch(choice) {
//Addition of complex numbers
case 1 :
double addreal=[Link]+ [Link];
double addimg=[Link]+ [Link];
[Link]("Additon : "+addreal +" + "+ addimg);
// Subtraction
case 2 :
double subreal=[Link]- [Link];
double subimg=[Link]- [Link];
[Link]("Subtraction :"+subreal +" +"+ subimg);

//(a+bi) * (c+di) = (ac -bd)+(ad+bc)i


//multiplication
case 3:
double mulreal=[Link]*[Link] -[Link]*[Link] ;
double mulimg=[Link]*[Link] + [Link]*[Link];
[Link]("Multiplication :"+mulreal+"+"+mulimg);

//division

case 4:
double denominator = ([Link] * [Link] + [Link] * [Link]);
if (denominator == 0) {
[Link]("Error: Division by zero complex number
is not possible.");
break;
}else {
double numReal = ([Link] * [Link] + [Link] *[Link]);
double numImg = ([Link] * [Link] - [Link] * [Link]);
[Link]("division :" +(numReal/denominator)
+ " + " + (numImg/denominator) +"i");
break;
}
}

}
}

// output
Enter complex number1 real part:
2
Enter Complex number1 img part:
3
Enter complex number2 real part:
1
Enter Complex number2 img part:
2
Select one : 1. addition 2. substraction 3. multiplication [Link] [Link]
4
division :1.6 + -0.2i
// Assignment 3
package Assignments;
import [Link].*;
public class Employee {
int emp_id;
String emp_name;
String address;
String Mail_id;
int mob_no;
float Basic_pay;
String ROLL="";
public Employee(int id , String name,String addr,String Mail,int mob,float
b_pay,String designation) {
emp_id=id;
emp_name=name;
address=addr;
Mail_id=Mail;
mob_no=mob;
Basic_pay=b_pay;
ROLL=designation;
}
///Function used for displaying information
void display() {
double DA=Basic_pay*0.97;
double HRA=Basic_pay* 0.10;
double PF= Basic_pay *0.12;
double SC_fund=Basic_pay*0.001;
double gross=Basic_pay+DA+HRA;
double totalDeduction=PF+SC_fund;
double net=gross-totalDeduction;

[Link]("================================================= ");
[Link](“ COMPANY NAME ");
[Link](" SALARY SLIP - SEPT-2025 ");
[Link]("================================================== ");

[Link]("Employee Details : ");


[Link]("Employee ID : "+emp_id);
[Link]("Employee Name: "+emp_name);
[Link]("Employee Address : "+address);
[Link]("Employee Mail ID : "+Mail_id);
[Link]("Employee Mobile Number : "+mob_no);
[Link]("Employee ROLL : "+ROLL);

[Link]("=================================================");
[Link]("Earnings: ");
[Link]("Employee Basic Pay: "+Basic_pay);
[Link]("DEARENESS ALLOWENESS ="+DA);
[Link]("House Rent Allowance = "+HRA);

[Link]("=================================================");
[Link]("Deductions : ");
[Link]("PF = "+PF);
[Link]("Staff club fund = "+SC_fund);

[Link]("=============================================== ");
[Link]("Gross Salary:"+gross);
[Link]("Total Deduction="+totalDeduction);
[Link]("NET salary : "+net);
[Link]("================================================ ");

public static void main(String [] args) {


///Adding Data of employees
Scanner sc=new Scanner([Link]);
[Link](" Enter Employee Details ");
[Link]("Enter Employee ID : ");
int id=[Link]();
//validation for id
if(id <=0) {
[Link]("Please Enter valid id : ");
}
[Link]("Enter Employee Name :");
String name=[Link]();
[Link]("Enter Employee Address :");
String addr=[Link]();
[Link]("Enter Employee Mail-Id :");
String Mail=[Link]();
[Link]("Enter Mobile number :");
int mob=[Link]();
[Link]("Enter Employee Basic Pay: ");
float b_pay=[Link]();
//validation for basicpay
if(id <=0) {
[Link]("Please Enter valid basic_pay : ");
}
[Link]("Choose designation [Link] [Link] Lead
[Link] Project Manager 4. Project Manager");
int c=[Link]();
String designation= switch(c) {
case 1->"Programmer";
case 2 ->"Team Lead";
case 3 ->"Assistant Project Manager";
case 4 ->"Project Manager";
default->"Employee";
};
Employee emp=new Employee(id,name,addr,Mail,mob,b_pay,designation);
[Link]();
}
}
Enter Employee Details
Enter Employee ID :
101
Enter Employee Name :
abc
Enter Employee Address :
Pune
Enter Employee Mail-Id :
abc12@[Link]
Enter Mobile number :
34783487
Enter Employee Basic Pay:
30000
Choose designation [Link] [Link] Lead [Link] Project Manager 4.
Project Manager
2
==============================================================
COMPANY NAME
SALARY SLIP - SEPT-2025
==============================================================
Employee Details :
Employee ID : 101
Employee Name: abc
Employee Address : Pune
Employee Mail ID : abc12@[Link]
Employee Mobile Number : 34783487
Employee ROLL : Team Lead
==============================================================
Earnings:
Employee Basic Pay: 30000.0
DEARENESS ALLOWENESS =29100.0
House Rent Allowance = 3000.0
==============================================================
Deductions :
PF = 3600.0
Staff club fund = 30.0
==============================================================
Gross Salary:62100.0
Total Deduction=3630.0
NET salary : 58470.0
==============================================================
//Assignment 4

package Assignments;
import [Link];
import [Link];

abstract class shape {


abstract void computeArea(double l,double b);
}

class rectangle extends shape{

void computeArea(double l,double b) {


if (b < 0 || l < 0) {
[Link]("Error: Length and breadth cannot be negative for
a Rectangle.");
return; // Exit the method if validation fails
}else {
double area=l*b;
[Link]("Area of Rectangle = "+area);
}
}
}
class triangle extends shape{

void computeArea(double b, double h) {


if (b <= 0 || h <= 0) {
[Link]("Error: Base and height must be positive for a
triangle.");
return;
} else {
double area = 0.5 * (h * b);
[Link]("Area of Triangle = " + area);
}
}
}
public class CalculateArea {
public static void main(String[] args) {
rectangle r= new rectangle();
[Link](10, 10);
triangle t=new triangle();
[Link](2,0);
}
}
//output
Area of Rectangle = 100.0
Error: Base and height must be positive for a triangle.
//Assignment 5
package Assignments;
import [Link];

interface vehicle {
abstract void gearChange(int gear);
abstract void speedUp(double increment);
abstract void applyBrakes(double decrement);
}
//Bicycle class
class Bicycle implements vehicle {
double speed;
int gear;

public Bicycle() {
[Link] = 0.0;
[Link] = 1;
}

public void gearChange(int gear) {


if (gear >= 1 && gear <= 7) {
[Link] = gear;
[Link]("Bicycle gear changed to: " + gear);
} else {
[Link]("Invalid gear for [Link] be between 1 and 7.");
}
}

public void speedUp(double increment) {


if (increment > 0) {
speed += increment;
if (speed > 30) { // Maximum speed limit
[Link]("Bicycle is out of speed limit. Please apply
brakes!");
} else {
[Link]("Bicycle speed increased to: " + speed + "
km/h");
}
} else {
[Link]("Speed increment must be positive.");
}
}

public void applyBrakes(double decrement) {


if (decrement > 0) {
speed -= decrement;
if (speed <= 0) {
speed = 0;
[Link]("Bicycle stopped.");
} else {
[Link]("Bicycle speed reduced to: " + speed + " km/h");
}
} else {
[Link]("Brake decrement must be positive.");
}
}

//Car class
class Car implements vehicle {
double speed;
int gear;

public Car() {
[Link] = 0.0;
[Link] = 1;
}

public void gearChange(int gear) {


if (gear >= 1 && gear <= 6) {
[Link] = gear;
[Link]("Car gear changed to: " + gear);
} else {
[Link]("Invalid gear for Car. Must be between 1 and 6.");
}
}

public void speedUp(double increment) {


if (increment > 0) {
speed += increment;
if (speed > 200) { // Max speed limit
[Link]("Car is out of speed limit!Please apply brakes.");
} else {
[Link]("Car speed increased to: " + speed + " km/h");
}
} else {
[Link]("Speed increment must be positive.");
}
}

public void applyBrakes(double decrement) {


if (decrement > 0) {
speed -= decrement;
if (speed <= 0) {
speed = 0;
[Link]("Car stopped.");
} else {
[Link]("Car speed reduced to: " + speed + " km/h");
}
} else {
[Link]("Brake decrement must be positive.");
}
}
}

//Bike class
class Bike implements vehicle {
double speed;
int gear;

public Bike() {
[Link] = 0.0;
[Link] = 1;
}

public void gearChange(int gear) {


if (gear >= 1 && gear <= 5) {
[Link] = gear;
[Link]("Bike gear changed to: " + gear);
} else {
[Link]("Invalid gear for Bike. Must be between 1 and 5.");
}
}

public void speedUp(double increment) {


if (increment > 0) {
speed += increment;
if (speed > 150) { // Maximum speed limit for bike
[Link]("Bike is out of speed limit. Please apply
brakes!");
} else {
[Link]("Bike speed increased to: " + speed + " km/h");
}
} else {
[Link]("Speed increment must be positive.");
}
}

public void applyBrakes(double decrement) {


if (decrement > 0) {
speed -= decrement;
if (speed <= 0) {
speed = 0;
[Link]("Bike stopped.");
} else {
[Link]("Bike speed reduced to: " + speed + " km/h");
}
} else {
[Link]("Brake decrement must be positive.");
}
}
}

//Main class
public class interface_Ex {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
vehicle bicycle = new Bicycle();
vehicle car = new Car();
vehicle bike = new Bike();
int choice;
[Link]("Please Enter your choice for bicycle , bike and car :");

choice=[Link]();
switch(choice) {
case 1:
[Link]("Testing Bicycle:");
[Link](8);
[Link](50);
[Link](500);
break;

case 2:
[Link]("\nTesting Car:");
[Link](4);
[Link](1000);
[Link](50002);
break;

case 3:
[Link]("\nTesting Bike:");
[Link](20);
[Link](40);
[Link](6000);
break;

}
}

//output
Please Enter your choice for bicycle , bike and car :1
Testing Bicycle:
Invalid gear for Bicycle. Must be between 1 and 7.
Bicycle is out of speed limit. Please apply brakes!
Bicycle stopped.

Please Enter your choice for bicycle , bike and car :2


Testing Car:
Car gear changed to: 4
Car is out of speed limit! Please apply brakes.
Car stopped.

Please Enter your choice for bicycle , bike and car :3


Testing Bike:
Invalid gear for Bike. Must be between 1 and 5.
Bike speed increased to: 40.0 km/h
Bike stopped.

You might also like