From 89fb0e0a9fc3be65ef4236a0bb2cbafa0c048fb2 Mon Sep 17 00:00:00 2001
From: Boubacar <gounouseroboubacar@gmail.com>
Date: Tue, 21 Jan 2025 23:10:11 +0100
Subject: [PATCH] solutionFractionnelle

---
 .idea/misc.xml                             |   2 +-
 out/production/aroTP2/App.class            | Bin 1265 -> 1265 bytes
 out/production/aroTP2/InstanceReader.class | Bin 2335 -> 2335 bytes
 out/production/aroTP2/Loot.class           | Bin 1160 -> 1160 bytes
 src/Backpack.java                          |  13 ++++++++-----
 src/Loot.java                              |   2 +-
 6 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1b2d693..38eefb8 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>
\ No newline at end of file
diff --git a/out/production/aroTP2/App.class b/out/production/aroTP2/App.class
index 8d3c8e862e7d1d8ac1daac52964bbb7ec3329713..4ae707af27c19bbfc1bf784eb39242b2b1eb1ffe 100644
GIT binary patch
delta 17
Zcmey!`H_?3)W2Q(7#J9wH*&mW0RTt*2POaj

delta 17
Zcmey!`H_?3)W2Q(7#J9wHgddV0RTt$2PFUi

diff --git a/out/production/aroTP2/InstanceReader.class b/out/production/aroTP2/InstanceReader.class
index 9a1d5b11a0914dac9a5b1a1a0bdda4d0958bdced..5e8faaeb63c791acfcbc457ec4e45f20eb8b6eee 100644
GIT binary patch
delta 17
ZcmbO)G+&70)W2Q(7#J9wH*$z`0suWL1;+pY

delta 17
ZcmbO)G+&70)W2Q(7#J9wHgbq_0suWG1;zjX

diff --git a/out/production/aroTP2/Loot.class b/out/production/aroTP2/Loot.class
index 4ffba3f58d9594f16f64fe6527d3748ef90eb0fc..dcc24c07e6b496357fea863d1d9cdfe408d4b69a 100644
GIT binary patch
delta 26
hcmeC+?BL`$^>5cc1_lP_jT{`z%rb4#n}wN683A-52XO!Z

delta 26
hcmeC+?BL`$^>5cc1_lPFjT{`z%+hT#n}wN683A+=2XFuY

diff --git a/src/Backpack.java b/src/Backpack.java
index b8552f0..c1b8321 100644
--- a/src/Backpack.java
+++ b/src/Backpack.java
@@ -27,13 +27,16 @@ public class Backpack {
         this.sortByRatio();
 
         for(Loot loot : loots){
-            if(loot.getWeight() > this.capacity){
-                sfValuee += (loot.getValue() * loot.getWeight()) / (capacity - sfWeight);
-                sfWeight += capacity - sfWeight;
+            if(sfWeight + loot.getWeight() <= this.capacity){
+                // Si l'objet entier peut entrer dans le sac
+                sfValuee += loot.getValue();
+                sfWeight += loot.getWeight();
             }
             else {
-                sfValuee += loot.getWeight();
-                sfWeight += loot.getWeight();
+                // Si l'objet ne peut pas entrer entièrement dans le sac
+                int remainingWeight = this.capacity - sfWeight;
+                sfValuee += (int) (loot.getRatio() * remainingWeight);
+                break;
             }
         }
     }
diff --git a/src/Loot.java b/src/Loot.java
index e2a85e0..d7dc032 100644
--- a/src/Loot.java
+++ b/src/Loot.java
@@ -5,7 +5,7 @@ public class Loot {
     public Loot(int weight, int value) {
         this.weight = weight;
         this.value = value;
-        this.ratio = (float) weight/value;
+        this.ratio = (float) value/weight;
     }
 
     public String toString(){
-- 
GitLab