I am having a problem getting the sales part of this to display a $ sign and 2 decimal places.
Where would I have to insert the command to have that display as $45000.00? One other question is there a way to get this to display the result all on one line. I have the commission displaying as it should but I can't figure out who to get the sales to display with the decimal places and $ sign.
Thanks for any help!
public class Commission2 {
public static void main(String[] args) {
double sales = 45000.0;
double commission = 0.0;
int rate = 5;
commission = computeCommission(sales, rate);
System.out.println("Commission on sales of "
+sales
+ " with a rate of " + rate + "%"
+ " is ");
System.out.printf("$%.2f\n",commission);
commission = computeCommission (sales);
System.out.println("Commission on sales of "
+sales
+ " with a rate of 7.5%"
+ " is");
System.out.printf("$%.2f\n",commission);
}
public static double computeCommission(double s, double r) {
return (( (double) r / 100.0) * s);
}
public static double computeCommission(double s, int r) {
return (( (double) r / 100.0) * s);
}
public static double computeCommission(double s) {
return (( 7.5 / 100.0) * s);
//Calling a method from another class Commission.display(y);
}
}