From 442bba346d6eeeab1df45e59b5fb621dd6a78b82 Mon Sep 17 00:00:00 2001 From: "couetoux.b" <bidule> Date: Tue, 20 Sep 2022 17:29:56 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20capacit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/vcs.xml | 6 ++++++ src/App.java | 4 ++-- src/Backpack.java | 15 +++++++++++++++ src/InstanceReader.java | 7 ++++--- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/Backpack.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /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 c851d85..919c748 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 0000000..121d485 --- /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 213d7f5..58e01ae 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); } -- GitLab