Skip to content
Snippets Groups Projects
Commit 442bba34 authored by couetoux.b's avatar couetoux.b
Browse files

ajout capacité

parent d5036747
Branches
No related tags found
No related merge requests found
<?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
......@@ -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);
}
}
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;
}
}
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment