Cannot get if statement to display bonus amount if sales are greater than certain amount - JAVA -


OK, so this is what I got stuck on. Code compiles it inspires the user to enter their sales. If the sale is $ 3000 or the equivalent, then the program should print the $ 100 bonus. I do not know why when I type in 3000 +, then why not print it? Can somebody help me out? Thanks to anyone who can do my code here:

  import java.util.Scanner; Public Class Commission {Fixed scanner keyboard; // in all ways it will see public static zero main (string [] algs) {double bayspe = 500; Double commission = 0.10; Float sales; // Sales volume entered by user = 335; Commission = Sale * 0.10; String input; // To capture the user's input, create a scanner object for the keyboard input = keyboard = new scanner (System.in); System.out.println ("Enter your total sales for this month:"); Input = keyboard.nextLine (); System.out.println ("Your salary for this month:"); System.out.println ("Base pay: $ 500.00"); If (Sales> 3000) System.out.println ("Bonus for more than 3,000 in sales: 100"); System.exit (0); }}  

assigns only sales The program asks for the sale input, reassign the sales variable to that amount, then try that you scanner object:

 < Code> System.out.println ("Enter your total sales for this month:"); Sales = keyboard.nextInt ();  

The way you want to input your input number, you should read it. For more accuracy, you may want to change from sales to float to int , because floating point decimals can get the correct accuracy or you can keyboard.nextInt () to keyboard.nextFloat ()

Another programming suggestion can change: to close any I / O Remember, in this case, you use the scanner . Just call it keyboard.close (); Call after calling .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -