jeudi 15 septembre 2016

Trying to negate an operation in java or separate units

I am trying to negate an operation in java for a store sales total. So this is the idea:

If number >= 10 && of base 10

Then give me discounted price on 10 units

if number <= 0 && not base 10

Then add the discount for the number which has 10 units in it and the remainder without the discount (let's say 100% for simplicity sake of the numbers)

So to make a practical example If I order 25 units of x (at $1 each) and 15 units (at $1 each) of y the price will be:

x 20 units = $0 x 5 units = $5 total

y 10 units = $0 y 5 units = $5 total

This is a bit tricky and this is what I got so far:

double discountedmNI = (mNI - ((mNI/100)*10)) * mNIC;
double discountedmNIP = mNI - ((mNI/100)*10);

if(mNIC >= 10 && mNIC % 10 == 0){

    System.out.println("mNI " + discountedmNIP + " " + mNIC);
    System.out.println(discountedmNI);

}

else if (!mNIC % 10 == 0){

    System.out.println("mNI " + mNI + mNIC);
    System.out.println(mNI * mNIC);

}

I don't think I am defining separate the 10 units right

Thank you all!

Aucun commentaire:

Enregistrer un commentaire