Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I know its the formula for the midpoint elasticity thats messed up. So its proba

ID: 3628253 • Letter: I

Question

I know its the formula for the midpoint elasticity thats messed up. So its probably and easy fix.



import java.util.Scanner;

/**
* Calculates the midpoint elasticity.
*
* @author Joseph Parrish
* @version 8-29-2010
*/

public class EcomonicsFormula {
/**
* This declares the variables used for the program.
*@param args User-defined command line arguments (not used).
*/

public static void main(String[] args)
{
int aPfinal1 = 0;
int aPinitial1 = 0;
int aPfinal2 = 0;
int aPinitial2 = 0;



Scanner aNumberInput = new Scanner(System.in);

System.out.println("-------------------------------------------");
System.out.println("This program calculates midpoint elasticity.");
System.out.println("-------------------------------------------");
System.out.println("");


System.out.print("Please enter your first item(s) final price:");
aPfinal1 = aNumberInput.nextInt();

System.out.print("Please enter your first item(s) initial price:");
aPinitial1 = aNumberInput.nextInt();

System.out.println("");


System.out.print("Please enter your second item(s) final price:");
aPfinal2 = aNumberInput.nextInt();

System.out.print("Please enter your second item(s) initial price:");
aPinitial2 = aNumberInput.nextInt();

System.out.println("");

double aMidpointElasticity = ((aPfinal1 - aPinitial1) %
+((aPfinal1 + aPinitial1) % (2)) %
+(aPfinal2 - aPinitial2) % (aPfinal2 + aPinitial2) % (2));

System.out.print("The midpoint elasticity is "
+ aMidpointElasticity + " %");

}
}

Explanation / Answer

Your problem is that using foo/2 is integer division. If you multiply by .5 it promotes the divisor to a double. You are now using float point division, instead of integer division double aMidpointElasticity = ((aPfinal2-aPinitial2)/(.5*(aPfinal2-aPinitial2)) / ((aPfinal1-aPinitial1)/(.5*(aPfinal1-aPinitial1));