RGAlex

O1. Black Flag / O6. Mid Exam Retake

Feb 26th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package MidExam.O6;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O1BlackFlag {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int days = scanner.nextInt();
  9.         int dailyPlunder = scanner.nextInt();
  10.         double target = scanner.nextDouble();
  11.         double sum = 0;
  12.  
  13.         for (int i = 1; i <= days; i++) {
  14.             sum += dailyPlunder;
  15.             if (i % 3 == 0) {
  16.                 sum += dailyPlunder * 0.5;
  17.             }
  18.             if (i % 5 == 0) {
  19.                 sum = sum * 0.7;
  20.             }
  21.         }
  22.         if (sum >= target) {
  23.             System.out.printf("Ahoy! %.2f plunder gained.", sum);
  24.         } else {
  25.             double percent = (sum / target) * 100;
  26.             System.out.printf("Collected only %.2f%% of the plunder.", percent);
  27.         }
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment