Java code help?

Discussion in 'School Work Help' started by Jokerjr, Feb 20, 2012.

  1. Jokerjr

    Jokerjr Member

    19
    26
    0
    Hi, I'm having some trouble with a java code i'm supposed to write... Long story short I have no idea how to grab 5 out of 15. Since this is just beginner level java, I'm kinda lost.. since I need to use the 15 as a double.. but the only way to pull it is to set it as an char or string... any pointers?

    Well.. it's supposed to be like the user enters a number lets say 16.. Then 10 of those items are priced at full price but 6 are priced at discount.. so any item 10 or lower are priced at full price while every additional item after 10 is priced at a discounted price...

    anyway...
     
  2. not going to give you syntax but the theory/thinking process.... write a separate class function for discount and full price... in the main class get the user input and do a simple if - else if - else with the math calling on the right function within the if/else if statements and you should get what you are looking to accomplish
     
  3. mizuKAZE

    mizuKAZE Well-Known Member

    52
    31
    0
    http://www.javaranch.com/drive/modulo.html
    You can use modulo to get the 6 of the 16
    int discount_price = 16 % 10 ; //16 - 10 = 6 remains
    so //discount_price = 6

    to get the 10 of the 16
    int full_price = 16 / 10; 16/10=1.6, but since full_price is a integer and not a double, it will remove the .6 => So 1.6 = 1
    int full_price = full_price * 10 // 1* 10 = 10