Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

Java_Tasks_Report (1)

The document contains Java code for two tasks: Employee Inheritance and a Polymorphic Banking Application. It defines classes for full-time and part-time employees, including methods for inputting and displaying employee details, as well as calculating salary increments. Additionally, it includes a banking system with account management features like crediting and debiting, along with interest calculation for savings accounts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Java_Tasks_Report (1)

The document contains Java code for two tasks: Employee Inheritance and a Polymorphic Banking Application. It defines classes for full-time and part-time employees, including methods for inputting and displaying employee details, as well as calculating salary increments. Additionally, it includes a banking system with account management features like crediting and debiting, along with interest calculation for savings accounts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Programs for TASK 1 and TASK 2

Author: [Your Name]

Student ID: [Your Student ID]

Java Code

// TASK 1: Employee Inheritance


class Employee {
String name, position;
int years;
double salary;

Employee() {
System.out.println("I am an employee");
salary = 30000;
}

void inputDetails(String name, String position, int years) {


this.name = name;
this.position = position;
this.years = years;
}

void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Position: " + position);
System.out.println("Years: " + years);
System.out.println("Salary: " + salary);
}
}

class FulltimeEmployee extends Employee {


double increment = 0.20;

FulltimeEmployee() {
System.out.println("I am a full-time employee in the company");
}

void displayIncrementedSalary() {
System.out.println("Incremented Salary: " + (salary + (salary * increment)));
}
}

class PartTimeEmployee extends Employee {


double increment = 0.05;

PartTimeEmployee() {
System.out.println("I am a part-time employee in the company");
}

void displayIncrementedSalary() {
System.out.println("Incremented Salary: " + (salary + (salary * increment)));
}
}

// TASK 2: Polymorphic Banking Application


class Accounts {
double balance;

Accounts() {
balance = 0;
}

void debit(double amount) {


if (amount <= balance) {
balance -= amount;
} else {
System.out.println("Insufficient Balance");
}
}

void credit(double amount) {


balance += amount;
}

void getBalance() {
System.out.println("Current Balance: " + balance);
}
}

class SavingAccount extends Accounts {


int timeSpan;
double interestRate = 0.06;
SavingAccount(int timeSpan) {
this.timeSpan = timeSpan;
}

double calculateInterest() {
return balance * interestRate * timeSpan;
}

@Override
void credit(double amount) {
super.credit(amount);
double interest = calculateInterest();
balance += interest;
}
}

public class Main {


public static void main(String[] args) {
// Testing Employee Classes
FulltimeEmployee ft = new FulltimeEmployee();
ft.inputDetails("John Doe", "Manager", 5);
ft.displayDetails();
ft.displayIncrementedSalary();

PartTimeEmployee pt = new PartTimeEmployee();


pt.inputDetails("Jane Doe", "Assistant", 2);
pt.displayDetails();
pt.displayIncrementedSalary();

// Testing Banking Application


SavingAccount sa = new SavingAccount(2);
sa.credit(1000);
sa.getBalance();
sa.debit(200);
sa.getBalance();
}
}

Expected Output

I am an employee
I am a full-time employee in the company
Name: John Doe
Position: Manager
Years: 5
Salary: 30000.0
Incremented Salary: 36000.0

I am an employee
I am a part-time employee in the company
Name: Jane Doe
Position: Assistant
Years: 2
Salary: 30000.0
Incremented Salary: 31500.0

Current Balance: 1120.0


Current Balance: 920.0

You might also like