Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ClothesDiscount {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- // Declaring variables
- float payment, paymentAfterDiscount1, paymentAfterDiscount2;
- int numOfItems;
- // Getting data from the user
- System.out.println("Please enter the total cost of the clothes: ");
- payment = s.nextFloat();
- System.out.println("Please enter the number of purchased items: ");
- numOfItems = s.nextInt();
- // Calculating two discounts
- paymentAfterDiscount1 = payment - ((int)payment / 300) * 50;
- paymentAfterDiscount2 = numOfItems >= 3 ? payment * 0.8f : payment;
- // Printing the cheapest price to the console
- System.out.println("The total price after discount is " +
- (paymentAfterDiscount1 < paymentAfterDiscount2 ? paymentAfterDiscount1 + " using discount 1"
- : paymentAfterDiscount2 + " using discount 2"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement