Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Rent {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int months = Integer.parseInt(sc.nextLine());
  7. int percent = Integer.parseInt(sc.nextLine());
  8. double priceRentMonth = Double.parseDouble(sc.nextLine());
  9.  
  10. double totalPrice = 0;
  11.  
  12.  
  13. double priceSecondHalf = 0;
  14. double priceFirstHalf = 0;
  15.  
  16. if (months % 2 == 0) {
  17. priceFirstHalf = priceRentMonth * (months * 1.0 / 2);
  18. priceSecondHalf = (priceRentMonth - priceRentMonth * 0.2) * (months * 1.0 / 2);
  19. } else {
  20. priceFirstHalf = priceRentMonth * months / 2;
  21. priceSecondHalf = (priceRentMonth - priceRentMonth * 0.2) * Math.round(months * 1.0 / 2);
  22. }
  23.  
  24. totalPrice = priceFirstHalf + priceSecondHalf;
  25. totalPrice += totalPrice * (percent * 1.0 / 100);
  26. System.out.printf("Total: %.2f", totalPrice);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement