Help with adjusting a program. NEw to java!!!!!
=((
Hey everyone below is the code i have and i need help with altering it. First thing is to change the do-while loop to a for loop and let the user enter COMMISSION_SOUGHT instead of fixing it as a constant.
Code :
import java.util.*;
public class SalesAmount {
public static void main(String [] args) {
final double COMMISSION_SOUGHT = 25000;
final double INITIAL_SALES_AMOUNT = 0.01;
double commission = 0;
double salesAmount = INITIAL_SALES_AMOUNT;
do {
salesAmount += 0.01;
if (salesAmount >= 10000.01)
commission =
5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;
else if (salesAmount >= 5000.01)
commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;
else
commission = salesAmount * 0.08;
} while (commission < COMMISSION_SOUGHT);
System.out.println(
"The sales amount $" + (int) (salesAmount * 100) / 100.0 +
"\nis needed to make a comission of $" + COMMISSION_SOUGHT);
}
}
Re: Help with adjusting a program. NEw to java!!!!!
To get value from user, use the following code
Quote:
final double COMMISSION_SOUGHT=Double.parseDouble(args[0]);
actually the "Double.parseDouble()" is used to convert input String type into Double. BUt i dont know how for this syntax works. If it does not work, use the following syntax:
Quote:
final int COMMISSION_SOUGHT=Integer.parseInt(args[0]);
And to convert do while into for loop, try this:
Quote:
int i=0;
for(i=0;commission < COMMISSION_SOUGHT;i++){
salesAmount += 0.01;
if (salesAmount >= 10000.01)
commission =
5000 * 0.08 + 5000 * 0.1 + (salesAmount - 10000) * 0.12;
else if (salesAmount >= 5000.01)
commission = 5000 * 0.08 + (salesAmount - 5000) * 0.10;
else
commission = salesAmount * 0.08;
}
But i am sure that this code wont do the exact work of ur original code. Coz, as u know,do while loop will be executed atleast once.