The program runs perfectly, however I am having an issue adding a discounted price. Another thing I noticed when I run the program is that the switch statement doesn't calculate the discounts at all.
// DiscountPrices.java - This program calculates total cost for discounted items.
// Input: Interactive.
// Output: Original price, discount, discounted price, and total price for all items.
import javax.swing.*;
public class DiscountPrices
{
public static void main(String args[])
{
final double DISCOUNT_ONE = .05;
final double DISCOUNT_TWO = .10;
final double DISCOUNT_THREE = .15;
double price;
String priceString;
int quantity;
String quantityString;
priceString = JOptionPane.showInputDialog("Enter price of item: ");
price = Double.parseDouble(priceString);
quantityString = JOptionPane.showInputDialog("Enter quantity ordered: ");
quantity = Integer.parseInt(quantityString);
// Test price here and call calculatePrice method.
calculatePrice(price, quantity);
int discountValue = 3;
switch(discountValue)
{
case 1: if(price < 5.00);
price = price * DISCOUNT_ONE;
break;
case 2: if(price < 10.00);
price = price * DISCOUNT_TWO;
break;
case 3: if(price > 10.00);
price = price * DISCOUNT_THREE;
break;
}
System.exit(0);
} // End of main() method.
// Write calculatePrice method here.
public static void calculatePrice(double amount, int quantity)
{
double total;
double discountPercent;
double discountPrice;
discountPercent = (amount / 100);
total = (amount * quantity);
System.out.println("Original Price: " + amount + " Discount Percent: " + discountPercent + " Quantity: " + quantity + " Total Price: " + total);
}
} // End of DiscountPrices class.