OK, here's the description of the program I've got to do:
A large company pats its salespeople on a commission basis. The salespeople recieve $200 per week, plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of merchandise in a week recieves $200 plus 9% of $5000, or a total of $650. You have been supplied with a list of items sold by salespeople. The values of these items are as follows:
1) 239.99
2) 129.75
3) 99.95
4) 350.89
Develop a Java application that inputs one salesperson's items sold for last week and calculates and displays that salesperson's earnings. There is no limit to the number of items that can be sold by a salesperson.
---
OK, the program itself isn't hard. I figure I've got the code just about perfect, but I'm getting an error that looks more like a warning, but won't let the program run:
The error I'm getting occurs with each time i do an equation. It is as follows:
A large company pats its salespeople on a commission basis. The salespeople recieve $200 per week, plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of merchandise in a week recieves $200 plus 9% of $5000, or a total of $650. You have been supplied with a list of items sold by salespeople. The values of these items are as follows:
1) 239.99
2) 129.75
3) 99.95
4) 350.89
Develop a Java application that inputs one salesperson's items sold for last week and calculates and displays that salesperson's earnings. There is no limit to the number of items that can be sold by a salesperson.
---
OK, the program itself isn't hard. I figure I've got the code just about perfect, but I'm getting an error that looks more like a warning, but won't let the program run:
Java:
import javax.swing.JOptionPane;
public class ProductSums {
public static void main(String[] args) {
float sumSoFar=0,total=0;
String numSold;
int productNum=1;
int sold=0;
while (productNum<=4){
numSold= JOptionPane.showInputDialog("Enter the quantity of product " + productNum
+ " sold:");
sold=Integer.parseInt(numSold);
if (productNum==1){
sumSoFar=sumSoFar + (sold*239.99);
}else if (productNum==2){
sumSoFar=sumSoFar + (sold*129.75);
}else if (productNum==2){
sumSoFar=sumSoFar + (sold*99.95);
}else{
sumSoFar=sumSoFar + (sold*350.89);
}
productNum+=1;
}
total=200+ (.09*sumSoFar);
JOptionPane.showMessageDialog(null,"" + total);
System.exit(0);
}
}
The error I'm getting occurs with each time i do an equation. It is as follows:
Code:
ProductSums.java [33:1] possible loss of precision
found : double
required: float
total=200 + (.09*sumSoFar);
^