forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of the Budget class is necessary to represent the budget attribute for Buyer objects. Implemented the Budget class to encapsulate the budget information for buyers, allowing for better organization and management of budget-related data. Using a separate class for budget ensures separation of concerns and follows the single responsibility principle, improving code readability and maintainability. This commit also includes necessary adjustments to integrate the Budget class with the Buyer class.
- Loading branch information
1 parent
0658640
commit feaef10
Showing
21 changed files
with
309 additions
and
67 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
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,58 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Buyer's budget in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidBudget(String)} | ||
*/ | ||
public class Budget { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "Budget should be a positive number."; | ||
public static final String VALIDATION_REGEX = "\\d+(\\.\\d+)?"; | ||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code Budget}. | ||
* | ||
* @param budget A valid budget amount. | ||
*/ | ||
public Budget(String budget) { | ||
requireNonNull(budget); | ||
checkArgument(isValidBudget(budget), MESSAGE_CONSTRAINTS); | ||
value = budget; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid budget amount. | ||
*/ | ||
public static boolean isValidBudget(String test) { | ||
return test.matches(VALIDATION_REGEX) && Double.parseDouble(test) >= 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Budget)) { | ||
return false; | ||
} | ||
|
||
Budget otherBudget = (Budget) other; | ||
return value.equals(otherBudget.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
} |
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
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
Oops, something went wrong.