how to use overload method in java?

January 22, 2011 at 22:40:18
Specs: Windows 7
Given the following header of two overloaded methods that calculates and return the value of the profit as follows :
1. public static float profit ( float sale ,float expense)
2. public static double profit ( double[] sale , double[] expense)

the first method will calculate the profit for a day, while the second method will calculate the profit of a week. all data are passed as input parameters. the profit is calculated by the following formula :
totalProfit = totalSale - totalExpenses

write a complete Java programs that will display the profit for a day and the profit of a week. your program should use the overloaded methods to calculate the profit.


See More: how to use overload method in java?

Report •

#1
January 23, 2011 at 01:32:30
That's a good homework question. You will learn a lot by doing it. You'll learn nothing by asking someone else to do it for you.

Report •

#2
January 23, 2011 at 05:26:31
import javax.swing.* ;
public class Profit
{
public static void main(String [ ] args)
{
float a , b ;
double [ ] x = new double [7];
double [ ] y = new double [7];
profit ( a,b );
profit ( x,y );

public static float profit( float sale, float expenses)
{
double totalProfit;
totalProfit = sale-expenses;
return totalProfit;
}

public static double profit( double [ ] sale, double [ ] expenses)
{
for( int x=0; x<7 ; x++)
{
double sum=0;
double totalProfit=new double[7];
totalProfit[x]= sale[x] - expenses[x];
sum= sum + totalProfit[x];
return sum;
}

}


Report •

#3
January 23, 2011 at 05:28:55
import javax.swing.* ;
public class Profit
{
public static void main(String [ ] args)
{
float a , b ;
double [ ] x = new double [7];
double [ ] y = new double [7];
profit ( a,b );
profit ( x,y );

public static float profit( float sale, float expenses)
{
double totalProfit;
totalProfit = sale-expenses;
return totalProfit;
}

public static double profit( double [ ] sale, double [ ] expenses)
{
for( int x=0; x<7 ; x++)
{
double sum=0;
double totalProfit=new double[7];
totalProfit[x]= sale[x] - expenses[x];
sum= sum + totalProfit[x];
return sum;
}

}


Report •

Related Solutions

#4
January 24, 2011 at 02:55:28
please check my answer there....
i still trying to do the coding,,,not just asking,,,,
if anything wrong,,just reply here,,tq

Report •

#5
January 25, 2011 at 02:51:02
public static double profit( double [ ] sale, double [ ] expenses) {
double sum=0;
for( int x=0; x<7 ; x++) {
sum += sale[x] - expenses[x];
}
return sum;
}

Report •

Ask Question