Advertisement
Guest User

Rent

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