• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Reddit Intermediate Challenge #118

a guest Apr 9th, 2013 26 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package reddit;
2.
3. import java.math.BigDecimal;
4. import java.util.Scanner;
5.
6. public class RedditChallengeIntermediate118 {
7.
8.
9.     public static void main(String[] args) {
10.         RedditChallengeIntermediate118 rc118 = new RedditChallengeIntermediate118();
11.         Scanner scan = new Scanner(System.in);
12.         String input = scan.nextLine();
13.         //String input = "5.00 2.00 2.00 1.00";
14.         //rc118.calculate(input.split(" "));
15.         //input = "99.99 1.23 3.21 5.01";
16.         rc118.calculate(input.split(" "));
17.     }
18.
19.
20.     public void calculate(String[] inputs) {
21.         int simLength = new BigDecimal(inputs[0]).multiply(new BigDecimal(100)).setScale(0).intValueExact();
22.         int shellRetrieval = new BigDecimal(inputs[1]).multiply(new BigDecimal(100)).setScale(0).intValueExact();
23.         int propellantRetrieval = new BigDecimal(inputs[2]).multiply(new BigDecimal(100)).setScale(0).intValueExact();
24.         int firingTime = new BigDecimal(inputs[3]).multiply(new BigDecimal(100)).setScale(0).intValueExact();
25.
26.         int shotsFired = 0;
27.
29.         boolean cannonFired = false;
31.         int cannonTimer = 0;
32.
34.         int shellTimer = 0;
35.
37.         int propellantTimer = 0;
38.
39.         //System.out.println("Length of simulation: " + simLength);
40.         //System.out.println("Length of shell retrieval: " + shellRetrieval);
41.         //System.out.println("Length of propellant retrieval: " + propellantRetrieval);
42.         //System.out.println("Length of firingTime: " + firingTime);
43.
44.         for (int timer = 1; timer <= simLength; timer++) {
45.             if (cannonFired) cannonTimer++;
48.
49.             if (shellTimer == shellRetrieval) shellLoaded = true;
50.             if (propellantTimer == propellantRetrieval) propellantLoaded = true;
51.
53.                 if (cannonTimer == firingTime) {
55.                     cannonTimer = 0;
56.                     cannonFired = false;
57.                 }
58.             }
59.
62.
64.                     shotsFired++;
65.                     cannonFired = true;