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)
7 views
8 pages
Implementation of Java Program To Pass Arguments To A Method and Return Value
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 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)
7 views
8 pages
Implementation of Java Program To Pass Arguments To A Method and Return Value
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 Pass Arguments t... For Later
Carousel Previous
Carousel Next
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
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
Polymorphism, Relations
PDF
50% (2)
Polymorphism, Relations
46 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
DCIT 201 Assignment
PDF
No ratings yet
DCIT 201 Assignment
18 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
assignment1
PDF
No ratings yet
assignment1
7 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
OOP Assignment 02
PDF
No ratings yet
OOP Assignment 02
17 pages
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
50% (2)
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
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
MiU Technical interview prep
PDF
No ratings yet
MiU Technical interview prep
35 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
Java_Tasks_Report (1)
PDF
No ratings yet
Java_Tasks_Report (1)
4 pages
Assignments Pooja Gaikwad
PDF
No ratings yet
Assignments Pooja Gaikwad
23 pages
karthi
PDF
No ratings yet
karthi
5 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
Salary c# Program
PDF
No ratings yet
Salary c# Program
3 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
java ass 6
PDF
No ratings yet
java ass 6
8 pages
ass3prac2
PDF
No ratings yet
ass3prac2
4 pages
EXPT 7B.docx (4)
PDF
No ratings yet
EXPT 7B.docx (4)
11 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
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 lab1
PDF
No ratings yet
java lab1
10 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
Software Design Simplified
From Everand
Software Design Simplified
Liviu Catalin Dorobantu
No ratings yet
Lesson 1 2
PDF
No ratings yet
Lesson 1 2
7 pages
As7001 00 As7002 00
PDF
No ratings yet
As7001 00 As7002 00
1 page
Jinal: Types of Papad Available With Lajawab Papad
PDF
No ratings yet
Jinal: Types of Papad Available With Lajawab Papad
6 pages
Basic Google Hacking
PDF
100% (1)
Basic Google Hacking
31 pages
Temporary Marking Inverted Spray Paint: Technical Data Sheet
PDF
No ratings yet
Temporary Marking Inverted Spray Paint: Technical Data Sheet
1 page
HEDIONE®-964898 MSDS
PDF
No ratings yet
HEDIONE®-964898 MSDS
9 pages
CH4 Control System
PDF
No ratings yet
CH4 Control System
10 pages
Computer Assignment
PDF
No ratings yet
Computer Assignment
19 pages
TTD Seva Receipt - SEENU KALYANAM-1
PDF
No ratings yet
TTD Seva Receipt - SEENU KALYANAM-1
1 page
Genasi_Ignara_Flameborn_Full_Character_Sheet
PDF
No ratings yet
Genasi_Ignara_Flameborn_Full_Character_Sheet
3 pages
145-Revision of Standard Service Charges of the Bank w.e.f. 01-11-2024
PDF
No ratings yet
145-Revision of Standard Service Charges of the Bank w.e.f. 01-11-2024
12 pages
Construction Equipment Managementfor Engineers Estimatorsand Construction Managers
PDF
No ratings yet
Construction Equipment Managementfor Engineers Estimatorsand Construction Managers
13 pages
Scania Indusstrial DC09, DC13, DC16 Engines Fault Codes
PDF
No ratings yet
Scania Indusstrial DC09, DC13, DC16 Engines Fault Codes
11 pages
Cp4152-Database Practices Lab
PDF
No ratings yet
Cp4152-Database Practices Lab
55 pages
Links
PDF
No ratings yet
Links
5 pages
Minimum Static Strength Requirements
PDF
No ratings yet
Minimum Static Strength Requirements
2 pages
An Overview of Indian Foundry Industry
PDF
100% (1)
An Overview of Indian Foundry Industry
2 pages
Kpsa Chairman Report November 2022
PDF
No ratings yet
Kpsa Chairman Report November 2022
20 pages
Mid Sem Evaluation
PDF
No ratings yet
Mid Sem Evaluation
31 pages
Employment
PDF
No ratings yet
Employment
9 pages
CISSP Training Guide - Robert Bragg
PDF
No ratings yet
CISSP Training Guide - Robert Bragg
75 pages
Department of Education: Republic of The Philippines
PDF
No ratings yet
Department of Education: Republic of The Philippines
2 pages
Formal Letter Format To University
PDF
100% (1)
Formal Letter Format To University
7 pages
NISM VA - Short Notes - Bullet Points
PDF
No ratings yet
NISM VA - Short Notes - Bullet Points
14 pages
The Chemistry of The Colorful Fire
PDF
No ratings yet
The Chemistry of The Colorful Fire
9 pages
Polymer Testing: Beata Kaczmarek, Alina Sionkowska, Anna Maria Osyczka
PDF
No ratings yet
Polymer Testing: Beata Kaczmarek, Alina Sionkowska, Anna Maria Osyczka
6 pages
Philippine Indigenous Music
PDF
No ratings yet
Philippine Indigenous Music
68 pages
Unit 14 Automated Assembly Systems
PDF
No ratings yet
Unit 14 Automated Assembly Systems
23 pages
Excel For Beginners
PDF
No ratings yet
Excel For Beginners
6 pages