ASS3
ASS3
ASS3
Assignment 3
1]Employee and Salary Class
import java.util.Scanner;
class Employee {
String employee_id;
String employee_name;
class TestShapes {
public static void main(String[] args) {
Triangle triangle = new Triangle(5, 10);
Rectangle rectangle = new Rectangle(5, 10);
Circle circle = new Circle(5);
4]class Fan {
final int SLOW = 1;
final int MEDIUM = 2;
12202040501019 Dharmik Rabadiya
public Fan() {
speed = SLOW;
f_on = false;
radius = 4;
color = "blue";
}
void display() {
System.out.println("Speed: " + (f_on ? speed : "Fan is off"));
System.out.println("Color: " + color);
System.out.println("Radius: " + radius);
}
System.out.println("Fan 1:");
fan1.display();
System.out.println("\nFan 2:");
fan2.display();
}
}
5]Rectangle Class
class Rectangle {
double x;
double y;
double width;
double height;
public Rectangle() {
this(0, 0, 1, 1);
}
double getArea() {
return width * height;
}
double getPerimeter() {
return 2 * (width + height);
}
6]Vegetable Hierarchy
class Vegetable {
String color;
System.out.println(potato);
System.out.println(brinjal);
System.out.println(tomato);
}
}
7]Employee Hierarchy
import java.util.Date;
public Principal() {
this.Name = "Principal";
this.Address = "Address";
this.mob = 1234567890;
this.Basic = 50000;
this.HRA = (10 * Basic) / 100;
this.DA = (50 * Basic) / 100;
12202040501019 Dharmik Rabadiya
public Lecturer() {
this.Name = "Lecturer";
this.Address = "Address";
this.mob = 1234567890;
this.Basic = 35000;
this.HRA = (10 * Basic) / 100;
this.DA = (50 * Basic) / 100;
this.book_allowance = (10 * Basic) / 100;
}
void getPersonalDetails() {
// No need to implement, default values are set in constructor
}
void calculateGross() {
gross = Basic + HRA + DA + book_allowance;
}
void displayDetails() {
System.out.println("Name: " + Name);
System.out.println("Address: " + Address);
System.out.println("Mobile: " + mob);
System.out.println("Basic: " + Basic);
System.out.println("HRA: " + HRA);
System.out.println("DA: " + DA);
System.out.println("Book Allowance: " + book_allowance);
System.out.println("Gross Salary: " + gross);
}
}
public Peon() {
this.Name = "Peon";
12202040501019 Dharmik Rabadiya
this.Address = "Address";
this.mob = 1234567890;
this.Basic = 10000;
this.HRA = (10 * Basic) / 100;
this.DA = (50 * Basic) / 100;
}
void getPersonalDetails() {
// No need to implement, default values are set in constructor
}
void calculateGross() {
gross = Basic + HRA + DA + medical;
}
@Override
void displayDetails() {
System.out.println("Name: " + Name);
System.out.println("Address: " + Address);
System.out.println("Mobile: " + mob);
System.out.println("Basic: " + Basic);
System.out.println("HRA: " + HRA);
System.out.println("DA: " + DA);
System.out.println("Medical Allowance: " + medical);
System.out.println("Gross Salary: " + gross);
}
}
class EmployeeTest {
public static void main(String[] args) {
Principal principal = new Principal();
principal.calculateGross();
System.out.println("Principal Details:");
principal.displayDetails();
System.out.println();
System.out.println();
import java.util.Scanner;
class Cricket {
12202040501019 Dharmik Rabadiya
String name;
int age;
System.out.println("Match Details:");
for (int i = 0; i < 5; i++) {
System.out.println("\nMatch " + (i + 1) + ":");
matches[i].display();
}
scanner.close();
12202040501019 Dharmik Rabadiya
}
}
8.2Parking System
class Vehicle {
String make;
String model;
int year;
public Car(String make, String model, int year, int doors, String
type) {
super(make, model, year);
this.doors = doors;
12202040501019 Dharmik Rabadiya
this.type = type;
}
@Override
public void display() {
super.display();
System.out.println("Doors: " + doors);
System.out.println("Type: " + type);
}
}
@Override
public void display() {
super.display();
System.out.println("Engine Displacement: " + engineDisplacement);
12202040501019 Dharmik Rabadiya
class ParkingSystem {
public static void main(String[] args) {
Vehicle[] parkingSlots = new Vehicle[5];
parkingSlots[0] = new Car("Toyota", "Camry", 2020, 4, "Sedan");
parkingSlots[1] = new Car("Honda", "Civic", 2018, 4, "Sedan");
parkingSlots[2] = new Motorcycle("Ducati", "Monster", 2019, 1100,
"Sports");
parkingSlots[3] = new Motorcycle("Harley Davidson", "Street",
2021, 750, "Cruiser");
parkingSlots[4] = new Car("Ford", "Fusion", 2017, 4,
"Hatchback");