Advertisement
abd9344

Exception in Thread "main"

Sep 20th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import java.util.Scanner;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class SalesCommission
  5. {
  6. public static void main( String [] args )
  7. {
  8. double commissionRate;
  9. double item1Commission;
  10. double item2Commission;
  11. double item3Commission;
  12. double item4Commission;
  13. double totalCommission;
  14. int item1Quantity;
  15. int item2Quantity;
  16. int item3Quantity;
  17. int item4Quantity;
  18. int itemSelected;
  19.  
  20. commissionRate = 0.09;
  21. item1Commission = 239.99 * commissionRate;
  22. item2Commission = 129.75 * commissionRate;
  23. item3Commission = 99.95 * commissionRate;
  24. item4Commission = 350.89 * commissionRate;
  25. item1Quantity = 0;
  26. item2Quantity = 0;
  27. item3Quantity = 0;
  28. item4Quantity = 0;
  29. itemSelected = 0;
  30. totalCommission = 200 + (item1Quantity * item1Commission) + (item2Quantity * item2Commission) + (item3Quantity * item3Commission) + (item4Quantity * item4Commission);
  31.  
  32. Scanner input = new Scanner( System.in );
  33. System.out.println( "Enter item number. Enter -1 to quit." );
  34. itemSelected = input.nextInt();
  35.  
  36. while( itemSelected != -1 )
  37. {
  38. if( itemSelected == 1 )
  39. {
  40. System.out.printf( "How many of item 1 did you sell?\n" );
  41. item1Quantity = item1Quantity + input.nextInt();
  42. }
  43. else if( itemSelected == 2 )
  44. {
  45. System.out.printf( "How many of item 2 did you sell?\n" );
  46. item2Quantity = item2Quantity + input.nextInt();
  47. }
  48. else if( itemSelected == 3 )
  49. {
  50. System.out.printf( "How many of item 3 did you sell?\n" );
  51. item3Quantity = item3Quantity + input.nextInt();
  52. }
  53. else if( itemSelected == 4 )
  54. {
  55. System.out.printf( "How many of item 4 did you sell?\n" );
  56. item4Quantity = item4Quantity + input.nextInt();
  57. }
  58. else
  59. {
  60. System.out.println( "Item number does not exist." );
  61. }
  62. System.out.println( "Enter item number. Enter -1 to quit." );
  63. itemSelected = input.nextInt();
  64. }
  65.  
  66. String message = String.format( "Your commission is $%.2d", totalCommission );
  67. JOptionPane.showMessageDialog( null, message );
  68.  
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement