Hi, i have an issue where my programs output is returning false in comparison to the benchmark output for an assignment I'm doing (can be seen in attachment below), I was wondering if anyone knows what I did wrong?, I put a comment with // below on what I think went wrong but I'm still unsure why the method isChestUnlocked returning false, maybe instead of referring to jar1 in class ground, I have to refer to jar1, jar2 and 3 in class Chest instead?, if so how do I do this since the variables have to be private.
Webp.net-resizeimage.pngpublic class Stone { private String name; private int weight; public Stone()[ATTACH=CONFIG]3655[/ATTACH][ATTACH=CONFIG]3655[/ATTACH] { System.out.print("Enter stone name: "); name = Global.keyboard.nextLine(); System.out.print("Enter stone weight: "); weight = Global.keyboard.nextInt(); Global.keyboard.nextLine(); } public int getWeight() { return weight; } } public class Jar { private int position; private Stone stone; public Jar() { position = 0; stone = null; } public Jar(int initPos, Stone stone) { position = initPos; this.stone = stone; } public void move(int distance) { position = position + distance; } public void moveTo(Jar jar) { jar.stone = stone; stone = null; } public int getWeight() { if (stone == null) { return 0; } return stone.getWeight(); } public class Ground { private Jar jar1; private Jar jar2; private Jar jar3; private Player player; private Chest chest; private Stone stone1; private Stone stone2; private Stone stone3; public Ground() { player = new Player(); jar1 = new Jar(1, new Stone()); jar2 = new Jar(2, new Stone()); jar3 = new Jar(3, new Stone()); chest = new Chest(); } public boolean isChestUnlocked(){ if (jar1.getWeight() + jar2.getWeight() + jar3.getWeight() == chest.combination) // I think this is the main problem return true; else return false; } } public class Chest { public int combination; private int position = 4; private Jar jar1; private Jar jar2; private Jar jar3; public Chest() { System.out.print("Enter chest combination (5-10): "); combination = Global.keyboard.nextInt(); Global.keyboard.nextLine(); jar1 = new Jar(4, null); jar2 = new Jar(4, null); jar3 = new Jar(4, null); } }