From 3c343d002af6aaec4f929d98bfbf9a977bb31561 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Tue, 2 May 2023 14:39:08 +1000 Subject: [PATCH] resource: cleaned code --- src/comp1110/ass2/Resource.java | 38 +++++++++++---------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/comp1110/ass2/Resource.java b/src/comp1110/ass2/Resource.java index 84d2b43..ff23306 100644 --- a/src/comp1110/ass2/Resource.java +++ b/src/comp1110/ass2/Resource.java @@ -7,7 +7,7 @@ package comp1110.ass2; */ public class Resource { private char type; - private Coord coord; + private final Coord coord; private boolean claimed; /** @@ -35,20 +35,14 @@ public class Resource { * @return String type of the resource */ public String getTypeString() { - switch (type){ - case 'C': - return "Coconut"; - case 'B': - return "Bamboo"; - case 'W': - return "Water"; - case 'P': - return "Precious Stone"; - case 'S': - return "Statuette"; - default: - return "Invalid"; - } + return switch (type) { + case 'C' -> "Coconut"; + case 'B' -> "Bamboo"; + case 'W' -> "Water"; + case 'P' -> "Precious Stone"; + case 'S' -> "Statuette"; + default -> "Invalid"; + }; } /** @@ -67,17 +61,9 @@ public class Resource { this.type = type; } - /** - * Set the coordinate of the resource - * @param coord Coord coordinate of the resource - */ - public void setCoord(Coord coord) { - this.coord = coord; - } - /** * Check if the resource is equal to another resource - * @param resource Resource resource to be compared + * @param resource resource to be compared * @return boolean true if the resources are equal */ public boolean equals(Resource resource) { @@ -96,8 +82,8 @@ public class Resource { * Check if the resource has been claimed * @return boolean true if the resource has been claimed */ - public boolean isClaimed() { - return this.claimed; + public boolean isAvailable() { + return !this.claimed; } @Override