Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You only assign a value to <code>markup</code> within <code>if</code> statements. The compiler doesn't keep track of what's feasible, and whether you've covered all cases... so the variable still isn't definitely assigned as far as the compiler is concerned.</p> <p>The simplest fix is to use <code>else</code> instead:</p> <pre><code>if (booksOrdered &lt; 20) { markup = .40; } else if (booksOrdered &lt; 50) { markup = .35; } else if (booksOrdered &lt; 100) { markup = .30; } else { markup = .25; } </code></pre> <p>Because the final <code>else</code> is unconditional, the compiler will spot that every path through this code assigns a value to <code>markup</code>.</p> <p>That's enough for <code>markup</code> - but you haven't specified anything that will assign a value to <code>publisherPrice</code>. Was that meant to be set via more user input? Note that it would be easier to spot all of this if you assign values to your variables at the point of declaration, rather than declaring everything at the start of the method and then assigning values.</p> <p>For example, instead of this:</p> <pre><code>String bookName; System.out.println("Enter the Book Title: "); bookName = keyboard.next(); </code></pre> <p>... you can have:</p> <pre><code>System.out.println("Enter the Book Title: "); String bookName = keyboard.next(); </code></pre> <p>As another side note, you shouldn't generally use <code>double</code> for financial amounts - consider using <code>BigDecimal</code> instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload