forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/AY2324S1-CS2103-F13-2/tp …
…into add-leave
- Loading branch information
Showing
15 changed files
with
514 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="bin/main" path="src/main/java"> | ||
<attributes> | ||
<attribute name="gradle_scope" value="main"/> | ||
<attribute name="gradle_used_by_scope" value="main,test"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="bin/main" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="gradle_scope" value="main"/> | ||
<attribute name="gradle_used_by_scope" value="main,test"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="bin/test" path="src/test/java"> | ||
<attributes> | ||
<attribute name="gradle_scope" value="test"/> | ||
<attribute name="gradle_used_by_scope" value="test"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="bin/test" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="gradle_scope" value="test"/> | ||
<attribute name="gradle_used_by_scope" value="test"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/> | ||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> | ||
<classpathentry kind="output" path="bin/default"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>tp</name> | ||
<comment>Project tp created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
<filteredResources> | ||
<filter> | ||
<id>1696599672119</id> | ||
<name></name> | ||
<type>30</type> | ||
<matcher> | ||
<id>org.eclipse.core.resources.regexFilterMatcher</id> | ||
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> | ||
</matcher> | ||
</filter> | ||
</filteredResources> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
arguments= | ||
auto.sync=false | ||
build.scans.enabled=false | ||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) | ||
connection.project.dir= | ||
eclipse.preferences.version=1 | ||
gradle.user.home= | ||
java.home=/usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home | ||
jvm.arguments= | ||
offline.mode=false | ||
override.workspace.settings=true | ||
show.console.view=true | ||
show.executions.view=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 | ||
org.eclipse.jdt.core.compiler.compliance=11 | ||
org.eclipse.jdt.core.compiler.source=11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/seedu/address/logic/commands/ClaimCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Money; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Performs claims for each employee and alters respective claim budgets. | ||
*/ | ||
public class ClaimCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "claim"; | ||
public static final String MESSAGE_EMPTY = "Kindly state the index and amount that the employee hopes to process!"; | ||
public static final String AMOUNT_EMPTY = "Kindly state the amount that the employee hopes to process!"; | ||
public static final String CLAIM_SUCCESS = "Claim has been successfully processed!\n"; | ||
|
||
private final Index index; | ||
private final Boolean isSubtract; | ||
private final long amount; | ||
|
||
/** | ||
* Initialises a ClaimCommand Objects with three variables being index, isSubtract and amount. | ||
* | ||
* @param index Index Object representing the position of individual within the list of employees. | ||
* @param isSubtract Boolean Object where True represents deduction and False represents addition. | ||
* @param amount Long Object representing the claim amount user is submitting. | ||
*/ | ||
public ClaimCommand(Index index, Boolean isSubtract, long amount) { | ||
this.index = index; | ||
this.isSubtract = isSubtract; | ||
this.amount = amount; | ||
} | ||
|
||
/** | ||
* Returns CommandResult Object after successfully updating user's claim budget. | ||
* Updating the Person Object in the list. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return CommandResult which highlights the new claim budget the individual has. | ||
* @throws CommandException Exception thrown if index input from HR is beyond the pre-existing max list index. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
long prevClaimBudget = Integer.parseInt(personToEdit.getClaimBudget().amount); | ||
Money claimBudget = calculateNewClaimBudget(prevClaimBudget); | ||
Person editedPerson = postClaimPerson(personToEdit, claimBudget); | ||
|
||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
|
||
return new CommandResult(String.format("%s Remaining claim %s has: %s", | ||
CLAIM_SUCCESS, editedPerson.getName(), claimBudget)); | ||
} | ||
|
||
/** | ||
* Returns a Money Object which represents the new amount the user has after the claiming process is completed. | ||
* | ||
* @param prevClaimBudget long object on user's claim budget before the claim process. | ||
* @return Money Object that highlights the new claim budget the user has. | ||
* @throws CommandException Exception if the subtracted claim amount is more the user's claim budget. | ||
*/ | ||
public Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException { | ||
if (this.isSubtract && (this.amount > prevClaimBudget)) { | ||
throw new CommandException(Messages.MESSAGE_OVER_CLAIM); | ||
} | ||
long newClaimBudget; | ||
if (this.isSubtract) { | ||
newClaimBudget = prevClaimBudget - this.amount; | ||
} else { | ||
newClaimBudget = prevClaimBudget + this.amount; | ||
} | ||
return new Money(String.valueOf(newClaimBudget)); | ||
} | ||
|
||
/** | ||
* Returns a Person object which contains the new claim budget. | ||
* Other variables of the person remains unchanged. | ||
* | ||
* @param personToEdit Person object (Old). | ||
* @param claimBudget Money object which reflects the new claim budget user has. | ||
* @return Person Object that contains the new claim budget whilst other variables remain unchanged. | ||
*/ | ||
public Person postClaimPerson(Person personToEdit, Money claimBudget) { | ||
return new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), | ||
personToEdit.getAddress(), personToEdit.getSalary(), claimBudget, | ||
personToEdit.getDepartment(), personToEdit.getDob()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; // Both are the same instance | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; // Other is not an instance of ClaimCommand | ||
} | ||
ClaimCommand that = (ClaimCommand) other; | ||
return index.equals(that.index) | ||
&& isSubtract.equals(that.isSubtract) | ||
&& amount == that.amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/address/logic/parser/ClaimCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.ClaimCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Claim; | ||
|
||
|
||
/** | ||
* Parses input arguments and creates a new ClaimCommand object. | ||
*/ | ||
public class ClaimCommandParser implements Parser<ClaimCommand> { | ||
|
||
/** | ||
* Returns ClaimCommand which contains the employee-of-interest's index, | ||
* boolean to represent subtraction/addition as well as the claim amount. | ||
* Parser to parse out the index as well as claim amount | ||
* (containing both symbol [+/-] and amount) based on delimiter of "$/". | ||
* Checks are in place to ensure the index is inputted and claim amount consists of only digits. | ||
* | ||
* @param args String object which represents the user's input. | ||
* @return ClaimCommand which consists of employee's index, subtraction/addition boolean indicator and claim amount. | ||
* @throws ParseException Exception thrown either when index is not inputted or claim amount contains non-digits. | ||
*/ | ||
public ClaimCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CLAIM_AMOUNT); | ||
|
||
Index index; | ||
Claim claim; | ||
|
||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.MESSAGE_EMPTY), pe); | ||
} | ||
|
||
if (argMultimap.getValue(PREFIX_CLAIM_AMOUNT).isPresent()) { | ||
claim = ParserUtil.parseClaim(argMultimap.getValue(PREFIX_CLAIM_AMOUNT).get()); | ||
} else { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.AMOUNT_EMPTY)); | ||
} | ||
|
||
return new ClaimCommand(index, claim.isSubtract, claim.amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package seedu.address.model.person; | ||
|
||
/** | ||
* Represents a Person's Claim in the address book. | ||
* Ensures boolean variable and amount is provided. | ||
*/ | ||
public class Claim { | ||
public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add " | ||
+ "the claim amount! Provide either +/- in front of the amount!"; | ||
public static final String ALPHABETS_ERROR = "Kindly only input integers for the claim amount!"; | ||
|
||
public final boolean isSubtract; | ||
public final int amount; | ||
|
||
/** | ||
* Returns a Claim Object which contains of two variables, isSubtract and amount. | ||
* isSubtract variable represents whether this claim is either addition/subtraction of claim budget. | ||
* amount variable represents whether the claim amount employee is hoping to claim. | ||
* | ||
* @param numStr String Object of user's input. | ||
*/ | ||
public Claim(String numStr) { | ||
char firstChar = numStr.charAt(0); | ||
if (firstChar == '+') { | ||
this.isSubtract = false; | ||
} else { | ||
this.isSubtract = true; | ||
} | ||
this.amount = Integer.parseInt(numStr.substring(1)); | ||
} | ||
|
||
/** | ||
* Returns a boolean object where True if symbol (+/-) is provided before claim amount else False. | ||
* | ||
* @param args String Object that contains parsed out portions from user's CLI input. | ||
* @return Boolean where True represents correct claim input format else False. | ||
*/ | ||
public static boolean comtainsSymbol(String args) { | ||
char firstChar = args.charAt(0); | ||
return firstChar == '+' || firstChar == '-'; | ||
} | ||
|
||
/** | ||
* Returns boolean object where True if claim amount only contains of digits else False. | ||
* This portion represents post symbol portion. For example, if args == "+500", we are obly care about "500". | ||
* | ||
* @param args String object that contains parsed out partions from user's CLI input. | ||
* @return Boolean where True represents claim amount was given in correct format else False. | ||
*/ | ||
public static boolean isCorrectAmountType(String args) { | ||
String amount = args.substring(1); | ||
return amount.matches("\\d+"); | ||
} | ||
} |
Oops, something went wrong.