Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
19 views
Implementation of Java Program To Demonstrate Aggregation and Composition
Uploaded by
harsita
AI-enhanced title
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
Download now
Download
Save Implementation of Java Program to Demonstrate Aggr... For Later
Download
Save
Save Implementation of Java Program to Demonstrate Aggr... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
19 views
Implementation of Java Program To Demonstrate Aggregation and Composition
Uploaded by
harsita
AI-enhanced title
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
Download now
Download
Save Implementation of Java Program to Demonstrate Aggr... For Later
Carousel Previous
Carousel Next
Save
Save Implementation of Java Program to Demonstrate Aggr... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
IMPLEMENTATION OF JAVA PROGRAM TO DEMONSTRATE
AGGREGATION AND COMPOSITION
PROGRAM CODE:
class Salary {
double m_salary;
double other;
Salary(double m, double o) {
this.m_salary = m;
this.other = o;
}
Salary(double m) {
this(m, 0);
}
double totalSalary() {
return m_salary + other;
}
}
class Wages {
double home_wages;
double repair_charges;
double medicinal_wages;
Wages(double wages, double charges, double medicine) {
this.home_wages = wages;
this.repair_charges = charges;
this.medicinal_wages = medicine;
}
Wages(double wages) {
this(wages, 0, 0);
}
double totalWages() {
return home_wages + repair_charges + medicinal_wages;
}
}
class Savings {
double tsalary;
double twages;
Savings(double sala, double wage) {
this.tsalary = sala;
this.twages = wage;
}
Savings(double sala) {
this(sala, 0);
}
double savingsEarned() {
return tsalary - twages;
}
}
class Worker {
private Salary salary;
private Wages wages;
Worker(Salary salary, Wages wages) {
this.salary = salary;
this.wages = wages;
}
double totalIncome() {
return salary.totalSalary() + wages.totalWages();
}
}
class Finance {
private Worker worker;
private Savings savings;
Finance(Worker worker, double expenses) {
this.worker = worker;
this.savings =new Savings(worker.totalIncome(), expenses);
}
void displayFinancialSummary() {
double totalIncome = worker.totalIncome();
double totalSavings = savings.savingsEarned();
System.out.println("Total Income: " + totalIncome);
System.out.println("Total Savings: " + totalSavings);
}
}
public class Exp4 {
public static void main(String[] args) {
Salary sal = new Salary(32000, 5000);
Wages wag = new Wages(20000, 3000, 5000);
Salary sal2 = new Salary(35000);
Wages wag2 = new Wages(15000);
Worker worker1 = new Worker(sal, wag);
Worker worker2 = new Worker(sal2, wag2);
Finance finance1 = new Finance(worker1, 33000);
Finance finance2 = new Finance(worker2, 11370);
System.out.println("Financial Summary for Worker 1:");
finance1.displayFinancialSummary();
System.out.println("Financial Summary for Worker 2:");
finance2.displayFinancialSummary();
}}
OUTPUT:
You might also like
Bus Tracker Business Plan
PDF
100% (4)
Bus Tracker Business Plan
9 pages
Step For Running RP in SAP
PDF
No ratings yet
Step For Running RP in SAP
4 pages
Implementation of Java Program To Demonstrate Method Overloading and Constructor Overloading
PDF
No ratings yet
Implementation of Java Program To Demonstrate Method Overloading and Constructor Overloading
8 pages
Implementation of Java Program To Pass Arguments To A Method and Return Value
PDF
No ratings yet
Implementation of Java Program To Pass Arguments To A Method and Return Value
8 pages
Implementation of Java Program To Demonstrate File Handling and Object Serialization
PDF
No ratings yet
Implementation of Java Program To Demonstrate File Handling and Object Serialization
8 pages
Implementation of Java Program To Demonstrate Exception Handling
PDF
No ratings yet
Implementation of Java Program To Demonstrate Exception Handling
6 pages
assignment1
PDF
No ratings yet
assignment1
7 pages
Koustubh Javapraticalassignment1
PDF
No ratings yet
Koustubh Javapraticalassignment1
14 pages
Salary c# Program
PDF
No ratings yet
Salary c# Program
3 pages
Prova Av2
PDF
No ratings yet
Prova Av2
11 pages
PGM 3
PDF
No ratings yet
PGM 3
1 page
Assignment# 2
PDF
No ratings yet
Assignment# 2
5 pages
Rules/naming Convention's We Need To Follow While Writing The Program
PDF
No ratings yet
Rules/naming Convention's We Need To Follow While Writing The Program
4 pages
Person
PDF
No ratings yet
Person
3 pages
EXP (4)-2
PDF
No ratings yet
EXP (4)-2
9 pages
Personal Finance Tracker
PDF
No ratings yet
Personal Finance Tracker
5 pages
Assignment - 3
PDF
No ratings yet
Assignment - 3
5 pages
OOP_Answer-Key
PDF
No ratings yet
OOP_Answer-Key
15 pages
Java
PDF
No ratings yet
Java
5 pages
Lab Polymorphism
PDF
No ratings yet
Lab Polymorphism
6 pages
Oop 3 Fa20-Be-012
PDF
No ratings yet
Oop 3 Fa20-Be-012
19 pages
Employee Oop Example
PDF
No ratings yet
Employee Oop Example
5 pages
Java 3 & 4
PDF
0% (1)
Java 3 & 4
50 pages
Homework #1: Please Refer To The Code in The Appendix (Pages 2 - 6) To Answer The Following Questions
PDF
No ratings yet
Homework #1: Please Refer To The Code in The Appendix (Pages 2 - 6) To Answer The Following Questions
5 pages
programmed assessment
PDF
No ratings yet
programmed assessment
6 pages
Java_Tasks_Report (1)
PDF
No ratings yet
Java_Tasks_Report (1)
4 pages
program on this keyword
PDF
No ratings yet
program on this keyword
2 pages
PP 2 Brian Sankey
PDF
No ratings yet
PP 2 Brian Sankey
4 pages
Java Project Report On Employee Management System
PDF
100% (1)
Java Project Report On Employee Management System
16 pages
Solution Lab Mini Project Java
PDF
No ratings yet
Solution Lab Mini Project Java
2 pages
Java Output
PDF
No ratings yet
Java Output
8 pages
OOP Assignment 02
PDF
No ratings yet
OOP Assignment 02
17 pages
public class Exercise14
PDF
No ratings yet
public class Exercise14
5 pages
Renzie
PDF
No ratings yet
Renzie
2 pages
Neelu
PDF
No ratings yet
Neelu
14 pages
Class Employee
PDF
No ratings yet
Class Employee
2 pages
Payroll System Final
PDF
No ratings yet
Payroll System Final
7 pages
Midterm Exam Set Two II
PDF
No ratings yet
Midterm Exam Set Two II
2 pages
APT1030_assignment2
PDF
No ratings yet
APT1030_assignment2
3 pages
ASS3
PDF
No ratings yet
ASS3
11 pages
CODER
PDF
No ratings yet
CODER
14 pages
Computer Project Class 12th
PDF
No ratings yet
Computer Project Class 12th
91 pages
C#Lab5 7
PDF
No ratings yet
C#Lab5 7
8 pages
SalaryComponent
PDF
No ratings yet
SalaryComponent
2 pages
Java pgm 10-18
PDF
No ratings yet
Java pgm 10-18
24 pages
Assignment 01
PDF
No ratings yet
Assignment 01
7 pages
Chapter-Seven: Object-Oriented Implementation
PDF
No ratings yet
Chapter-Seven: Object-Oriented Implementation
23 pages
Question # 1: Assignment # 1 (OOP C#)
PDF
No ratings yet
Question # 1: Assignment # 1 (OOP C#)
16 pages
Lab 7
PDF
No ratings yet
Lab 7
29 pages
Assignments Pooja Gaikwad
PDF
No ratings yet
Assignments Pooja Gaikwad
23 pages
PF lab 9
PDF
No ratings yet
PF lab 9
5 pages
Lucrarea de Laborator Nr. 3: Raport La
PDF
No ratings yet
Lucrarea de Laborator Nr. 3: Raport La
12 pages
2.2 Employee
PDF
No ratings yet
2.2 Employee
1 page
المستند
PDF
No ratings yet
المستند
3 pages
Esaimen Ooop
PDF
No ratings yet
Esaimen Ooop
9 pages
Oop Assignment 01: Name: Ghazanfar Qarshi ROLL NO: 2020-BSCS-019 Sec: A
PDF
No ratings yet
Oop Assignment 01: Name: Ghazanfar Qarshi ROLL NO: 2020-BSCS-019 Sec: A
9 pages
Java Program Employee - Management Program
PDF
No ratings yet
Java Program Employee - Management Program
2 pages
Untitled document-1
PDF
No ratings yet
Untitled document-1
4 pages
Employees: Employee
PDF
No ratings yet
Employees: Employee
6 pages
Import Class Public Static Void New Double Int While: "Enter Salary: "
PDF
No ratings yet
Import Class Public Static Void New Double Int While: "Enter Salary: "
2 pages
Code For Employee Class in Java
PDF
No ratings yet
Code For Employee Class in Java
2 pages
Software Design Simplified
From Everand
Software Design Simplified
Liviu Catalin Dorobantu
No ratings yet
Web Summer 2023
PDF
No ratings yet
Web Summer 2023
2 pages
WinTAK_Data_Sync_SUM
PDF
No ratings yet
WinTAK_Data_Sync_SUM
12 pages
Sun Explorer 6.1 User Guide
PDF
No ratings yet
Sun Explorer 6.1 User Guide
100 pages
Wall
PDF
No ratings yet
Wall
4 pages
Robust Control Part1
PDF
No ratings yet
Robust Control Part1
12 pages
Template Laporan Praktikum
PDF
No ratings yet
Template Laporan Praktikum
5 pages
Display Rpgle
PDF
No ratings yet
Display Rpgle
917 pages
Unlock Zip File Method
PDF
No ratings yet
Unlock Zip File Method
26 pages
PSP Brochure
PDF
No ratings yet
PSP Brochure
4 pages
Dberry Exclusively For Europe: Case Postale 296 Tel: + 41 22 548 13 89 CH-1095 Lutry Email: Switzerland Web
PDF
No ratings yet
Dberry Exclusively For Europe: Case Postale 296 Tel: + 41 22 548 13 89 CH-1095 Lutry Email: Switzerland Web
10 pages
MAD 4
PDF
No ratings yet
MAD 4
3 pages
Vesda Vlc-400: Product Guide
PDF
No ratings yet
Vesda Vlc-400: Product Guide
46 pages
User Manual RedpackAPI English 1.0
PDF
No ratings yet
User Manual RedpackAPI English 1.0
23 pages
Perancangan Dan Pengembangan Aplikasi Jam Pengingat Waktu Sholat Arah Kiblat Dan Rekomendasi Masjid Terdekat
PDF
No ratings yet
Perancangan Dan Pengembangan Aplikasi Jam Pengingat Waktu Sholat Arah Kiblat Dan Rekomendasi Masjid Terdekat
10 pages
Write A Program That Implements An Algorithm Using An IDE
PDF
No ratings yet
Write A Program That Implements An Algorithm Using An IDE
10 pages
Introduction To Evolutionary Computation: Assist. Prof. Dr. Mohammed Najm Abdullah
PDF
No ratings yet
Introduction To Evolutionary Computation: Assist. Prof. Dr. Mohammed Najm Abdullah
11 pages
Lecture5 1
PDF
No ratings yet
Lecture5 1
52 pages
Class 5 Pa 2
PDF
No ratings yet
Class 5 Pa 2
2 pages
Washer Drive Belt 1411 Jma
PDF
No ratings yet
Washer Drive Belt 1411 Jma
4 pages
The Torrent Guide For Everyone - 24 Pages PDF
PDF
No ratings yet
The Torrent Guide For Everyone - 24 Pages PDF
24 pages
Deep Learning For Credit Risk 1713932406
PDF
No ratings yet
Deep Learning For Credit Risk 1713932406
13 pages
NetBeans IDE Java Quick Start Tutorial
PDF
No ratings yet
NetBeans IDE Java Quick Start Tutorial
5 pages
Configuration Deployment Sample For Sterling Commerce
PDF
No ratings yet
Configuration Deployment Sample For Sterling Commerce
4 pages
Introduction On Data Warehouse With OLTP and OLAP: Arpit Parekh
PDF
No ratings yet
Introduction On Data Warehouse With OLTP and OLAP: Arpit Parekh
5 pages
Ibm Presentation
PDF
No ratings yet
Ibm Presentation
27 pages
07 - Recursion PDF
PDF
No ratings yet
07 - Recursion PDF
28 pages
Design-ACVM SC DCChap01Lesson 10emsys
PDF
No ratings yet
Design-ACVM SC DCChap01Lesson 10emsys
30 pages
Hadoop World: Enabling Ad-Hoc Analytics at Web Scale
PDF
No ratings yet
Hadoop World: Enabling Ad-Hoc Analytics at Web Scale
17 pages