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 - totalExpenseswrite 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.

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.

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;

}}

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;

}}

please check my answer there....

i still trying to do the coding,,,not just asking,,,,

if anything wrong,,just reply here,,tq

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;

}

Ask Your Question

Weekly Poll

Would you ride in a self-driving car from Tesla?

Discuss in The Lounge

Poll History