Added java solution to day 0
authorNeil Smith <neil.git@njae.me.uk>
Tue, 13 Jun 2017 15:36:46 +0000 (16:36 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 13 Jun 2017 15:36:46 +0000 (16:36 +0100)
00-holiday-specs/Day0.java [new file with mode: 0644]

diff --git a/00-holiday-specs/Day0.java b/00-holiday-specs/Day0.java
new file mode 100644 (file)
index 0000000..e4062d0
--- /dev/null
@@ -0,0 +1,47 @@
+import java.util.Scanner;
+import java.util.Scanner.*;
+import java.io.FileReader;
+import java.io.FileReader.*;
+
+public class Day0
+{
+   public static void main(String[] args) throws Exception
+   {
+      FileReader f = new FileReader("00-prices.txt");     
+      Scanner sc = new Scanner(f);  
+      
+      String id, bestId = "";
+      int nullarbor = 0;
+      int price, extras, nextCost;      
+      int bestCost = Integer.MAX_VALUE;
+      
+      while(sc.hasNext())
+      {
+         id = sc.next();
+         
+         price = sc.nextInt();
+         
+         String lo = sc.next();
+         
+         if(lo.contains("Nullarbor"))
+            nullarbor++;
+         
+         extras = sc.nextInt();
+         
+         nextCost = price + extras;
+         
+         int savings = Math.min(extras, 500);
+         
+         nextCost -= savings;
+         
+         if(nextCost < bestCost)
+         {
+            bestCost = nextCost;         
+            bestId = id;
+         }
+      }      
+      
+      System.out.println("Nullarbor holidays " + nullarbor);
+      System.out.println("Best price holiday " + bestCost + " id " + bestId );
+   }
+}