diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/src/App.java b/src/App.java index c851d85e4a6f8d54f40c36133702fd452bd34a9e..919c748040e30676e800217504bec9fc5dadd720 100644 --- a/src/App.java +++ b/src/App.java @@ -2,7 +2,7 @@ import java.util.List; public class App { public static void main(String[] args) throws Exception { - List<Loot> loots = new InstanceReader().read("src/sac0"); - System.out.println(loots); + Backpack backpack= new InstanceReader().read("src/sac0"); + System.out.println(backpack); } } diff --git a/src/Backpack.java b/src/Backpack.java new file mode 100644 index 0000000000000000000000000000000000000000..121d485ed18cc2096aaf45eb08d3c699ff125a14 --- /dev/null +++ b/src/Backpack.java @@ -0,0 +1,15 @@ +import java.util.List; + +public class Backpack { + int capacity; + List<Loot> loots; + + public Backpack(int capacity, List<Loot> loots) { + this.capacity = capacity; + this.loots = loots; + } + + public String toString(){ + return capacity +"\n"+loots; + } +} diff --git a/src/InstanceReader.java b/src/InstanceReader.java index 213d7f504871051560f01a695a02a4058fd54c00..58e01aeeea4ff1d787bd9d70dba63e67f393f3c4 100644 --- a/src/InstanceReader.java +++ b/src/InstanceReader.java @@ -6,12 +6,13 @@ import java.util.stream.Stream; public class InstanceReader { - List<Loot> read(String filename) throws Exception { + Backpack read(String filename) throws Exception { File file = new File(filename); List<Loot> loots = new ArrayList<>(); BufferedReader buffer = new BufferedReader(new FileReader(file)); - buffer.readLine(); + int capacity = Integer.decode(buffer.readLine()); Stream<String> lines = buffer.lines(); + lines.forEach(s -> { String[] line = s.split(" "); loots.add(new Loot(Integer.decode(line[0]), @@ -19,7 +20,7 @@ public class InstanceReader { ); }); - return loots; + return new Backpack(capacity,loots); }