Advertisement
eranseg

Clothes Discount

Jul 24th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ClothesDiscount {
  4.     public static void main(String[] args) {
  5.         Scanner s = new Scanner(System.in);
  6.         // Declaring variables
  7.         float payment, paymentAfterDiscount1, paymentAfterDiscount2;
  8.         int numOfItems;
  9.         // Getting data from the user
  10.         System.out.println("Please enter the total cost of the clothes: ");
  11.         payment = s.nextFloat();
  12.         System.out.println("Please enter the number of purchased items: ");
  13.         numOfItems = s.nextInt();
  14.         // Calculating two discounts
  15.         paymentAfterDiscount1 = payment - ((int)payment / 300) * 50;
  16.         paymentAfterDiscount2 = numOfItems >= 3 ? payment * 0.8f : payment;
  17.         // Printing the cheapest price to the console
  18.         System.out.println("The total price after discount is " +
  19.                           (paymentAfterDiscount1 < paymentAfterDiscount2 ? paymentAfterDiscount1 + " using discount 1"
  20.                                                                          : paymentAfterDiscount2 + " using discount 2"));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement