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)
9 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
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)
9 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
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
E3D Admin - PML - Net - CourseContent
PDF
No ratings yet
E3D Admin - PML - Net - CourseContent
5 pages
400+ Javascript Interview Questions
PDF
100% (1)
400+ Javascript Interview Questions
176 pages
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
Assignment 1
PDF
No ratings yet
Assignment 1
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
Java 2
PDF
No ratings yet
Java 2
4 pages
Lab 4
PDF
67% (3)
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
MiU Technical Interview Prep
PDF
No ratings yet
MiU Technical Interview Prep
35 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
Java Tasks Report
PDF
No ratings yet
Java Tasks Report
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 Assignment-3
PDF
No ratings yet
Java Assignment-3
13 pages
Java PGM 10-18
PDF
No ratings yet
Java PGM 10-18
24 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
Ass 3 Prac 2
PDF
No ratings yet
Ass 3 Prac 2
4 pages
Expt 7B
PDF
No ratings yet
Expt 7B
11 pages
Personal Finance Tracker
PDF
No ratings yet
Personal Finance Tracker
5 pages
Solution Lab Mini Project Java
PDF
No ratings yet
Solution Lab Mini Project Java
2 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
SandhyaP Exercise2
PDF
No ratings yet
SandhyaP Exercise2
9 pages
Renzie
PDF
No ratings yet
Renzie
2 pages
PF Lab 9
PDF
No ratings yet
PF Lab 9
5 pages
Assignment 34
PDF
No ratings yet
Assignment 34
7 pages
Oop Reference Manual - Final
PDF
No ratings yet
Oop Reference Manual - Final
75 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
Software Design Simplified
From Everand
Software Design Simplified
Liviu Catalin Dorobantu
No ratings yet
Constructor in Java
PDF
No ratings yet
Constructor in Java
6 pages
Unit 5 PLSQL
PDF
No ratings yet
Unit 5 PLSQL
41 pages
Practice Set 1 With Ans
PDF
No ratings yet
Practice Set 1 With Ans
16 pages
Kitty's Calculations On A Tree
PDF
No ratings yet
Kitty's Calculations On A Tree
38 pages
Using Python Libraries-1
PDF
No ratings yet
Using Python Libraries-1
61 pages
WEEK - 10 - MCQ - Attempt Review Hareesh
PDF
No ratings yet
WEEK - 10 - MCQ - Attempt Review Hareesh
24 pages
Q1 What Are Input and Output Stream
PDF
No ratings yet
Q1 What Are Input and Output Stream
5 pages
JDBC
PDF
No ratings yet
JDBC
9 pages
Coding Assignment - Fruit Stand
PDF
No ratings yet
Coding Assignment - Fruit Stand
3 pages
MarkSheet & Calculator Program PDF
PDF
No ratings yet
MarkSheet & Calculator Program PDF
8 pages
CSL203 Java Lab Cycle Programs
PDF
No ratings yet
CSL203 Java Lab Cycle Programs
4 pages
Chương 5 - Entity Framework
PDF
No ratings yet
Chương 5 - Entity Framework
35 pages
Unit 1 - Structured Paradigm
PDF
No ratings yet
Unit 1 - Structured Paradigm
67 pages
All Software 2020 HND
PDF
No ratings yet
All Software 2020 HND
74 pages
Uvm Test Termination
PDF
100% (1)
Uvm Test Termination
24 pages
Linux-4 9 77-4 9 77-Cher1 Diff
PDF
No ratings yet
Linux-4 9 77-4 9 77-Cher1 Diff
70 pages
Name: Shubhangi Mapare Roll No: 17112 Div: TE A Subject: SPOS Lab
PDF
No ratings yet
Name: Shubhangi Mapare Roll No: 17112 Div: TE A Subject: SPOS Lab
7 pages
Fundamentals of ABAP Objects: IBM Global Business Services
PDF
No ratings yet
Fundamentals of ABAP Objects: IBM Global Business Services
46 pages
Design Patterns Notes - Complete
PDF
100% (1)
Design Patterns Notes - Complete
211 pages
CPP Notes
PDF
No ratings yet
CPP Notes
276 pages
Java Course
PDF
No ratings yet
Java Course
3 pages
Functionalprogramminginphp Sample
PDF
100% (3)
Functionalprogramminginphp Sample
29 pages
Grade 10 Bluj Theory Notes
PDF
No ratings yet
Grade 10 Bluj Theory Notes
19 pages
C++ Mutable Keyword: The Mutable Storage Class Speci Er in C++ (Or Use of Mutable Keyword in C++)
PDF
No ratings yet
C++ Mutable Keyword: The Mutable Storage Class Speci Er in C++ (Or Use of Mutable Keyword in C++)
2 pages
Zain 11
PDF
No ratings yet
Zain 11
6 pages
OOP Through Java: Unit - Iii
PDF
No ratings yet
OOP Through Java: Unit - Iii
70 pages
Scala Tutorial: Install, Currying, Inheritance, Pattern Matching, Examples
PDF
No ratings yet
Scala Tutorial: Install, Currying, Inheritance, Pattern Matching, Examples
31 pages
Ict 103 Midterm Exam Test 1:: of Instructions That Tells The Computer What To Execute
PDF
No ratings yet
Ict 103 Midterm Exam Test 1:: of Instructions That Tells The Computer What To Execute
3 pages