0% found this document useful (0 votes)
2 views4 pages

Java Classes for Job, Shapes, and Marks

The document contains Java classes demonstrating various object-oriented programming concepts, including inheritance, abstraction, and method overriding. Key classes include Job and SoftwareDeveloper for job-related functionalities, Triangle and Circle for geometric calculations, and several abstract classes for defining common behaviors in banking and marking systems. Additionally, it showcases the use of constructors in abstract classes and the implementation of area calculations for different shapes.

Uploaded by

cosmic.sus.73
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)
2 views4 pages

Java Classes for Job, Shapes, and Marks

The document contains Java classes demonstrating various object-oriented programming concepts, including inheritance, abstraction, and method overriding. Key classes include Job and SoftwareDeveloper for job-related functionalities, Triangle and Circle for geometric calculations, and several abstract classes for defining common behaviors in banking and marking systems. Additionally, it showcases the use of constructors in abstract classes and the implementation of area calculations for different shapes.

Uploaded by

cosmic.sus.73
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

// 1.

Job and SoftwareDeveloper Classes

import [Link];

class Job {
protected double salary;
protected int yearsOfExperience;
protected String jobPosition;
protected String companyName;

public Job(double salary, int yearsOfExperience, String jobPosition, String companyName) {


[Link] = salary;
[Link] = yearsOfExperience;
[Link] = jobPosition;
[Link] = companyName;
}

public void getSalary() {


[Link](null, "Salary: $" + salary);
}

public void displaySummaryDetails() {


[Link](null, "Job Position: " + jobPosition + "\nCompany: " + co
}
}

class SoftwareDeveloper extends Job {


public SoftwareDeveloper(double salary, int yearsOfExperience, String jobPosition, String c
super(salary, yearsOfExperience, jobPosition, companyName);
}

@Override
public void getSalary() {
if (yearsOfExperience > 3) {
salary *= 1.3;
} else {
salary *= 1.05;
}
[Link](null, "Updated Salary: $" + salary);
}
}

// 2. Triangle Class
import [Link];

class Triangle {
int a, b, c;

public Triangle() {
a = 3;
b = 4;
c = 5;
}
public void calculate() {
int perimeter = a + b + c;
double s = perimeter / 2.0;
double area = [Link](s * (s - a) * (s - b) * (s - c));

[Link]("Perimeter: " + perimeter);


[Link]("Area: " + area);
}
}

// 3. Circle Class

class Circle {
private double radius, pi;

public Circle() {
[Link] = 5;
[Link] = [Link];
}

public void setRadius(double radius) {


[Link] = radius;
}

public double getCircumference() {


return 2 * pi * radius;
}
}

// 4. Abstract Parent Class

abstract class Parent {


abstract void message();
}

class SubClass1 extends Parent {


void message() {
[Link]("This is the first subclass");
}
}

class SubClass2 extends Parent {


void message() {
[Link]("This is the second subclass");
}
}

// 5. Bank Abstract Class

abstract class Bank {


abstract void getBalance();
}
class BankA extends Bank {
void getBalance() {
[Link]("Bank A: $100");
}
}

class BankB extends Bank {


void getBalance() {
[Link]("Bank B: $150");
}
}

class BankC extends Bank {


void getBalance() {
[Link]("Bank C: $200");
}
}

// 6. Marks Abstract Class

abstract class Marks {


abstract double getPercentage();
}

class A extends Marks {


private int sub1, sub2, sub3;

public A(int sub1, int sub2, int sub3) {


this.sub1 = sub1;
this.sub2 = sub2;
this.sub3 = sub3;
}

double getPercentage() {
return (sub1 + sub2 + sub3) / 3.0;
}
}

class B extends Marks {


private int sub1, sub2, sub3, sub4;

public B(int sub1, int sub2, int sub3, int sub4) {


this.sub1 = sub1;
this.sub2 = sub2;
this.sub3 = sub3;
this.sub4 = sub4;
}

double getPercentage() {
return (sub1 + sub2 + sub3 + sub4) / 4.0;
}
}

// 7. Abstract Class with Constructor


abstract class AbstractDemo {
public AbstractDemo() {
[Link]("This is the constructor of the abstract class");
}

abstract void a_method();

void normalMethod() {
[Link]("This is the normal method of the abstract class");
}
}

class SubClass extends AbstractDemo {


void a_method() {
[Link]("This is an abstract method");
}
}

// 8. Shape Abstract Class

abstract class Shape {


abstract void RectangleArea(double length, double breadth);

abstract void SquareArea(double side);

abstract void CircleArea(double radius);


}

class Area extends Shape {


void RectangleArea(double length, double breadth) {
[Link]("Rectangle Area: " + (length * breadth));
}

void SquareArea(double side) {


[Link]("Square Area: " + (side * side));
}

void CircleArea(double radius) {


[Link]("Circle Area: " + ([Link] * radius * radius));
}
}

You might also like