This program is meant to act as a shop, with a number being inputted for a corresponding item and a quantity. The catch is that if you want three or more items you receive a 10% discount on the purchase and any decimals should be truncated (staying within whole numbers of the int data type). The program will run, however the discount isn't calculated and is always stated as 0 though the program will run. Check it out!
int item, longsword, shortsword, warhammer, ring, potion, itemcost, quantity, discount, totalcost, finalcost;
System.out.print("Item Number: ");
item = keyboard.nextInt();
final int LONGSWORD = 120;
final int SHORTSWORD = 90;
final int WARHAMMER = 80;
final int RING = 150;
final int POTION = 10;
itemcost = 0;
if (item == 1)
{
itemcost = LONGSWORD;
}
if (item == 2)
{
itemcost = SHORTSWORD;
}
if (item == 3)
{
itemcost = WARHAMMER;
}
if (item == 4)
{
itemcost = RING;
}
if (item == 5)
{
itemcost = POTION;
}
System.out.print("Quantity of Item: ");
quantity = keyboard.nextInt();
totalcost = itemcost * quantity;
System.out.println("Total Cost: " + totalcost);
if (quantity >= 3)
{
discount = totalcost * (1/10);
}
else
{
discount = 0;
}
System.out.println("Discount: " + discount);