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)
5 views
Implementation of Java Program To Pass Arguments To A Method and Return Value
Uploaded by
harsita
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save Implementation of Java Program to Pass Arguments t... For Later
Download
Save
Save Implementation of Java Program to Pass Arguments t... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
5 views
Implementation of Java Program To Pass Arguments To A Method and Return Value
Uploaded by
harsita
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save Implementation of Java Program to Pass Arguments t... For Later
Carousel Previous
Carousel Next
Save
Save Implementation of Java Program to Pass Arguments t... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
IMPLEMENTATION OF JAVA PROGRAM TO PASS ARGUMENTS TO A
METHOD AND RETURN VALUE
PROGRAM CODE:
class Salary {
double m_salary;
double other;
Salary(double m, double o) {
this.m_salary = m;
this.other = o;
}
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;
}
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;
}
double savings_earned() {
return tsalary - twages;
}
}
public class Exp {
public static void main(String[] args) {
Salary sal = new Salary(32000, 5000);
Wages wag = new Wages(20000, 3000, 5000);
Savings sav = new Savings(sal.m_salary + sal.other, wag.home_wages +
wag.repair_charges + wag.medicinal_wages);
double ts = sal.totalsalary();
double tw = wag.totalwages();
double se = sav.savings_earned();
System.out.println("TOTAL SALARY: " + ts);
System.out.println("TOTAL WAGES: " + tw);
System.out.println("TOTAL SAVINGS: " + se);
}
}
OUTPUT:
IMPLEMENTATION OF JAVA PROGRAM TO PASS ARGUMENTS TO A
METHOD AND RETURN VALUE
PROGRAM CODE:
class Salary {
double m_salary;
double other;
Salary(double m, double o) {
this.m_salary = m;
this.other = o;
}
double totalsalary() {
return m_salary + other;
}
static double totalSalaryFromArray(Salary[] salaries) {
double total = 0;
for (Salary salary : salaries) {
total += salary.totalsalary();
}
return total;
}
}
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;
}
double totalwages() {
return home_wages + repair_charges + medicinal_wages;
}
static double totalWagesFromArray(Wages[] wagesArray) {
double total = 0;
for (Wages wages : wagesArray) {
total += wages.totalwages();
}
return total;
}
}
class Savings {
double tsalary;
double twages;
Savings(double sala, double wage) {
this.tsalary = sala;
this.twages = wage;
}
double savingsEarned() {
return tsalary - twages;
}
static Savings calculateSavings(Salary[] salaries, Wages[] wagesArray) {
double totalSalary = Salary.totalSalaryFromArray(salaries);
double totalWages = Wages.totalWagesFromArray(wagesArray);
return new Savings(totalSalary, totalWages);
}
}
class ExpenseTracker {
double totalExpenses = 0;
void addExpense(double amount) {
totalExpenses += amount;
}
double getTotalExpenses() {
return totalExpenses;
}
}
public class Exp1 {
public static void main(String[] args) {
Salary[] salaries = {
new Salary(32000, 5000),
new Salary(35000, 7000)
};
Wages[] wagesArray = {
new Wages(20000, 3000, 5000),
new Wages(15000, 2000, 3000)
};
Savings sav = Savings.calculateSavings(salaries, wagesArray);
double ts = Salary.totalSalaryFromArray(salaries);
double tw = Wages.totalWagesFromArray(wagesArray);
double se = sav.savingsEarned();
ExpenseTracker expenseTracker = new ExpenseTracker();
expenseTracker.addExpense(1500);
expenseTracker.addExpense(300);
double totalExpenses = expenseTracker.getTotalExpenses();
System.out.println("TOTAL SALARY: " + ts);
System.out.println("TOTAL WAGES: " + tw);
System.out.println("TOTAL SAVINGS: " + se);
System.out.println("TOTAL EXPENSES: " + totalExpenses);
}
}
OUTPUT:
You might also like
Tax Payer Details Reports
PDF
No ratings yet
Tax Payer Details Reports
1,092 pages
Polymorphism, Relations
PDF
50% (2)
Polymorphism, Relations
46 pages
Service Manual: Blu-Ray Disc/Dvd Player
PDF
No ratings yet
Service Manual: Blu-Ray Disc/Dvd Player
125 pages
Drill and Blast Manual
PDF
50% (2)
Drill and Blast Manual
40 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 Demonstrate Aggregation and Composition
PDF
No ratings yet
Implementation of Java Program To Demonstrate Aggregation and Composition
4 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
Java
PDF
No ratings yet
Java
5 pages
Koustubh Javapraticalassignment1
PDF
No ratings yet
Koustubh Javapraticalassignment1
14 pages
OOP_Answer-Key
PDF
No ratings yet
OOP_Answer-Key
15 pages
Lab Polymorphism
PDF
No ratings yet
Lab Polymorphism
6 pages
Assignment# 2
PDF
No ratings yet
Assignment# 2
5 pages
Oop 3 Fa20-Be-012
PDF
No ratings yet
Oop 3 Fa20-Be-012
19 pages
PGM 3
PDF
No ratings yet
PGM 3
1 page
Prova Av2
PDF
No ratings yet
Prova Av2
11 pages
Assignment - 3
PDF
No ratings yet
Assignment - 3
5 pages
Neelu
PDF
No ratings yet
Neelu
14 pages
EXP (4)-2
PDF
No ratings yet
EXP (4)-2
9 pages
Person
PDF
No ratings yet
Person
3 pages
Lab 4
PDF
0% (1)
Lab 4
13 pages
Programming Notes
PDF
No ratings yet
Programming Notes
4 pages
Anurag Tiwari Mca.10029.24 Assignment 9
PDF
No ratings yet
Anurag Tiwari Mca.10029.24 Assignment 9
7 pages
Apex Codes-Day 1 & 2
PDF
No ratings yet
Apex Codes-Day 1 & 2
11 pages
NLP I LEVEL 2021-1 INITIAL COMPLETED - Jiancarlos Anton Vasquez
PDF
No ratings yet
NLP I LEVEL 2021-1 INITIAL COMPLETED - Jiancarlos Anton Vasquez
14 pages
Employee Oop Example
PDF
No ratings yet
Employee Oop Example
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
Java 3 & 4
PDF
0% (1)
Java 3 & 4
50 pages
Assignment 01
PDF
No ratings yet
Assignment 01
7 pages
Assignments Pooja Gaikwad
PDF
No ratings yet
Assignments Pooja Gaikwad
23 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
Java Output
PDF
No ratings yet
Java Output
8 pages
Java pgm 10-18
PDF
No ratings yet
Java pgm 10-18
24 pages
JAVA ASSIGNMENT-3
PDF
No ratings yet
JAVA ASSIGNMENT-3
13 pages
Exp 07
PDF
No ratings yet
Exp 07
31 pages
CODER
PDF
No ratings yet
CODER
14 pages
Employees: Employee
PDF
No ratings yet
Employees: Employee
6 pages
Lab 7
PDF
No ratings yet
Lab 7
29 pages
Question # 1: Assignment # 1 (OOP C#)
PDF
No ratings yet
Question # 1: Assignment # 1 (OOP C#)
16 pages
Lab 8
PDF
No ratings yet
Lab 8
16 pages
ass3prac2
PDF
No ratings yet
ass3prac2
4 pages
Solution Lab Mini Project Java
PDF
No ratings yet
Solution Lab Mini Project Java
2 pages
Personal Finance Tracker
PDF
No ratings yet
Personal Finance Tracker
5 pages
Computer Project Class 12th
PDF
No ratings yet
Computer Project Class 12th
91 pages
Java Lab Evaluation
PDF
No ratings yet
Java Lab Evaluation
2 pages
23011103044_SandhyaP_Exercise2
PDF
No ratings yet
23011103044_SandhyaP_Exercise2
9 pages
Renzie
PDF
No ratings yet
Renzie
2 pages
PF lab 9
PDF
No ratings yet
PF lab 9
5 pages
assignment34
PDF
No ratings yet
assignment34
7 pages
class Bank אריאל
PDF
No ratings yet
class Bank אריאל
5 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
My_Handwritten_Questions_To_Practtice_Coding
PDF
No ratings yet
My_Handwritten_Questions_To_Practtice_Coding
3 pages
Name1
PDF
No ratings yet
Name1
43 pages
Ass Java
PDF
No ratings yet
Ass Java
6 pages
Chapter-Seven: Object-Oriented Implementation
PDF
No ratings yet
Chapter-Seven: Object-Oriented Implementation
23 pages
Gsis Salary Loan
PDF
No ratings yet
Gsis Salary Loan
2 pages
5. OOP
PDF
No ratings yet
5. OOP
5 pages
Manya ass 3-Copy
PDF
No ratings yet
Manya ass 3-Copy
17 pages
PR 4
PDF
No ratings yet
PR 4
4 pages
Ict 3309
PDF
No ratings yet
Ict 3309
12 pages
Assignment OOP
PDF
No ratings yet
Assignment OOP
11 pages
Software Design Simplified
From Everand
Software Design Simplified
Liviu Catalin Dorobantu
No ratings yet
Amazing Java: Learn Java Quickly
From Everand
Amazing Java: Learn Java Quickly
Andrei Besedin
No ratings yet
Best-Practices For Large Eddy Simulations (LES) in FLUENT
PDF
No ratings yet
Best-Practices For Large Eddy Simulations (LES) in FLUENT
2 pages
Call For Papers: Health Informatics - An International Journal (HIIJ)
PDF
No ratings yet
Call For Papers: Health Informatics - An International Journal (HIIJ)
2 pages
IT Assignment Term1
PDF
No ratings yet
IT Assignment Term1
4 pages
Writing and Structuring Deep Learning Code: 4.1 Best Practices
PDF
No ratings yet
Writing and Structuring Deep Learning Code: 4.1 Best Practices
34 pages
Ext GWT Tutorial PDF
PDF
No ratings yet
Ext GWT Tutorial PDF
2 pages
Lecture 4 NOS and #Models
PDF
No ratings yet
Lecture 4 NOS and #Models
50 pages
Infologix White Paper Extending Sap Ewm Life Sciences
PDF
100% (1)
Infologix White Paper Extending Sap Ewm Life Sciences
12 pages
20+ Best Figma Tutorials For Beginners Design System
PDF
No ratings yet
20+ Best Figma Tutorials For Beginners Design System
13 pages
Js 7
PDF
No ratings yet
Js 7
6 pages
Data Dictionary Meterial
PDF
No ratings yet
Data Dictionary Meterial
12 pages
Brkaci 2102
PDF
No ratings yet
Brkaci 2102
121 pages
Soma Bringer Cheat Code
PDF
50% (2)
Soma Bringer Cheat Code
14 pages
Local Area Network Trainer Equipment
PDF
No ratings yet
Local Area Network Trainer Equipment
1 page
Composition Aggregation UML Class Diagram For Composition and Aggregation
PDF
No ratings yet
Composition Aggregation UML Class Diagram For Composition and Aggregation
25 pages
" Automation in Construction - An Overview ": BY: Ananth Baba - J
PDF
0% (2)
" Automation in Construction - An Overview ": BY: Ananth Baba - J
30 pages
Modulo 6 - Clase 4
PDF
No ratings yet
Modulo 6 - Clase 4
29 pages
Rekordbox Manual - en - 1001c PDF
PDF
No ratings yet
Rekordbox Manual - en - 1001c PDF
225 pages
Lis 312 - 7
PDF
No ratings yet
Lis 312 - 7
20 pages
Practice 1
PDF
No ratings yet
Practice 1
2 pages
CODING PART 2 - 1wKUNkNSo33bqOWCyxNQzpgkECuGIM-i8
PDF
No ratings yet
CODING PART 2 - 1wKUNkNSo33bqOWCyxNQzpgkECuGIM-i8
11 pages
Isc 2025 Prac CMS
PDF
No ratings yet
Isc 2025 Prac CMS
3 pages
UMTS Frequency Bands
PDF
No ratings yet
UMTS Frequency Bands
2 pages
Different File Formats
PDF
No ratings yet
Different File Formats
10 pages
CSi Detailer
PDF
100% (2)
CSi Detailer
85 pages
HUAWEI RRC REstablishment
PDF
No ratings yet
HUAWEI RRC REstablishment
8 pages
Serial Entrepreneurship and Born-Global New Ventures. A Case Study
PDF
No ratings yet
Serial Entrepreneurship and Born-Global New Ventures. A Case Study
33 pages
Neuro Glow[1]
PDF
No ratings yet
Neuro Glow[1]
11 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Tax Payer Details Reports
PDF
Tax Payer Details Reports
Polymorphism, Relations
PDF
Polymorphism, Relations
Service Manual: Blu-Ray Disc/Dvd Player
PDF
Service Manual: Blu-Ray Disc/Dvd Player
Drill and Blast Manual
PDF
Drill and Blast Manual
Implementation of Java Program To Demonstrate Method Overloading and Constructor Overloading
PDF
Implementation of Java Program To Demonstrate Method Overloading and Constructor Overloading
Implementation of Java Program To Demonstrate Aggregation and Composition
PDF
Implementation of Java Program To Demonstrate Aggregation and Composition
Implementation of Java Program To Demonstrate File Handling and Object Serialization
PDF
Implementation of Java Program To Demonstrate File Handling and Object Serialization
Implementation of Java Program To Demonstrate Exception Handling
PDF
Implementation of Java Program To Demonstrate Exception Handling
Java
PDF
Java
Koustubh Javapraticalassignment1
PDF
Koustubh Javapraticalassignment1
OOP_Answer-Key
PDF
OOP_Answer-Key
Lab Polymorphism
PDF
Lab Polymorphism
Assignment# 2
PDF
Assignment# 2
Oop 3 Fa20-Be-012
PDF
Oop 3 Fa20-Be-012
PGM 3
PDF
PGM 3
Prova Av2
PDF
Prova Av2
Assignment - 3
PDF
Assignment - 3
Neelu
PDF
Neelu
EXP (4)-2
PDF
EXP (4)-2
Person
PDF
Person
Lab 4
PDF
Lab 4
Programming Notes
PDF
Programming Notes
Anurag Tiwari Mca.10029.24 Assignment 9
PDF
Anurag Tiwari Mca.10029.24 Assignment 9
Apex Codes-Day 1 & 2
PDF
Apex Codes-Day 1 & 2
NLP I LEVEL 2021-1 INITIAL COMPLETED - Jiancarlos Anton Vasquez
PDF
NLP I LEVEL 2021-1 INITIAL COMPLETED - Jiancarlos Anton Vasquez
Employee Oop Example
PDF
Employee Oop Example
Rules/naming Convention's We Need To Follow While Writing The Program
PDF
Rules/naming Convention's We Need To Follow While Writing The Program
Java 3 & 4
PDF
Java 3 & 4
Assignment 01
PDF
Assignment 01
Assignments Pooja Gaikwad
PDF
Assignments Pooja Gaikwad
Homework #1: Please Refer To The Code in The Appendix (Pages 2 - 6) To Answer The Following Questions
PDF
Homework #1: Please Refer To The Code in The Appendix (Pages 2 - 6) To Answer The Following Questions
Java Output
PDF
Java Output
Java pgm 10-18
PDF
Java pgm 10-18
JAVA ASSIGNMENT-3
PDF
JAVA ASSIGNMENT-3
Exp 07
PDF
Exp 07
CODER
PDF
CODER
Employees: Employee
PDF
Employees: Employee
Lab 7
PDF
Lab 7
Question # 1: Assignment # 1 (OOP C#)
PDF
Question # 1: Assignment # 1 (OOP C#)
Lab 8
PDF
Lab 8
ass3prac2
PDF
ass3prac2
Solution Lab Mini Project Java
PDF
Solution Lab Mini Project Java
Personal Finance Tracker
PDF
Personal Finance Tracker
Computer Project Class 12th
PDF
Computer Project Class 12th
Java Lab Evaluation
PDF
Java Lab Evaluation
23011103044_SandhyaP_Exercise2
PDF
23011103044_SandhyaP_Exercise2
Renzie
PDF
Renzie
PF lab 9
PDF
PF lab 9
assignment34
PDF
assignment34
class Bank אריאל
PDF
class Bank אריאל
Oop Assignment 01: Name: Ghazanfar Qarshi ROLL NO: 2020-BSCS-019 Sec: A
PDF
Oop Assignment 01: Name: Ghazanfar Qarshi ROLL NO: 2020-BSCS-019 Sec: A
My_Handwritten_Questions_To_Practtice_Coding
PDF
My_Handwritten_Questions_To_Practtice_Coding
Name1
PDF
Name1
Ass Java
PDF
Ass Java
Chapter-Seven: Object-Oriented Implementation
PDF
Chapter-Seven: Object-Oriented Implementation
Gsis Salary Loan
PDF
Gsis Salary Loan
5. OOP
PDF
5. OOP
Manya ass 3-Copy
PDF
Manya ass 3-Copy
PR 4
PDF
PR 4
Ict 3309
PDF
Ict 3309
Assignment OOP
PDF
Assignment OOP
Software Design Simplified
From Everand
Software Design Simplified
Amazing Java: Learn Java Quickly
From Everand
Amazing Java: Learn Java Quickly
Best-Practices For Large Eddy Simulations (LES) in FLUENT
PDF
Best-Practices For Large Eddy Simulations (LES) in FLUENT
Call For Papers: Health Informatics - An International Journal (HIIJ)
PDF
Call For Papers: Health Informatics - An International Journal (HIIJ)
IT Assignment Term1
PDF
IT Assignment Term1
Writing and Structuring Deep Learning Code: 4.1 Best Practices
PDF
Writing and Structuring Deep Learning Code: 4.1 Best Practices
Ext GWT Tutorial PDF
PDF
Ext GWT Tutorial PDF
Lecture 4 NOS and #Models
PDF
Lecture 4 NOS and #Models
Infologix White Paper Extending Sap Ewm Life Sciences
PDF
Infologix White Paper Extending Sap Ewm Life Sciences
20+ Best Figma Tutorials For Beginners Design System
PDF
20+ Best Figma Tutorials For Beginners Design System
Js 7
PDF
Js 7
Data Dictionary Meterial
PDF
Data Dictionary Meterial
Brkaci 2102
PDF
Brkaci 2102
Soma Bringer Cheat Code
PDF
Soma Bringer Cheat Code
Local Area Network Trainer Equipment
PDF
Local Area Network Trainer Equipment
Composition Aggregation UML Class Diagram For Composition and Aggregation
PDF
Composition Aggregation UML Class Diagram For Composition and Aggregation
" Automation in Construction - An Overview ": BY: Ananth Baba - J
PDF
" Automation in Construction - An Overview ": BY: Ananth Baba - J
Modulo 6 - Clase 4
PDF
Modulo 6 - Clase 4
Rekordbox Manual - en - 1001c PDF
PDF
Rekordbox Manual - en - 1001c PDF
Lis 312 - 7
PDF
Lis 312 - 7
Practice 1
PDF
Practice 1
CODING PART 2 - 1wKUNkNSo33bqOWCyxNQzpgkECuGIM-i8
PDF
CODING PART 2 - 1wKUNkNSo33bqOWCyxNQzpgkECuGIM-i8
Isc 2025 Prac CMS
PDF
Isc 2025 Prac CMS
UMTS Frequency Bands
PDF
UMTS Frequency Bands
Different File Formats
PDF
Different File Formats
CSi Detailer
PDF
CSi Detailer
HUAWEI RRC REstablishment
PDF
HUAWEI RRC REstablishment
Serial Entrepreneurship and Born-Global New Ventures. A Case Study
PDF
Serial Entrepreneurship and Born-Global New Ventures. A Case Study
Neuro Glow[1]
PDF
Neuro Glow[1]