From 1b25369a5a737c8965e630760823225b321b6f09 Mon Sep 17 00:00:00 2001 From: Tanisha Chavan <151942801+Tanisha0708@users.noreply.github.com> Date: Tue, 5 Nov 2024 18:56:40 +0530 Subject: [PATCH] improvements doneClass Naming: Changed the class name to Fine for clarity. Precision and Scale: Correctly defined precision = 10 and scale = 2 in the @Column annotation for amount to match your documentation. Javadoc Comments: Added detailed Javadoc comments for fields and methods, explaining the purpose and parameters. toString() Method: Added a toString() method for convenient debugging and logging. fineId Column Definition: Set updatable = false for fineId as it should be immutable once generated. --- .../java/com/libraryman_api/fine/Fines.java | 77 +++++++++++++++---- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/libraryman_api/fine/Fines.java b/src/main/java/com/libraryman_api/fine/Fines.java index ca0a674..a791286 100644 --- a/src/main/java/com/libraryman_api/fine/Fines.java +++ b/src/main/java/com/libraryman_api/fine/Fines.java @@ -4,54 +4,99 @@ import java.math.BigDecimal; +/** + * Represents a fine in the Library Management System. + * Each fine has an amount, a payment status, and a unique identifier. + */ @Entity -public class Fines { +public class Fine { + @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, - generator = "fine_id_generator") - @SequenceGenerator(name = "fine_id_generator", - sequenceName = "fine_id_sequence", - allocationSize = 1) - @Column(name = "fine_id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fine_id_generator") + @SequenceGenerator(name = "fine_id_generator", sequenceName = "fine_id_sequence", allocationSize = 1) + @Column(name = "fine_id", updatable = false, nullable = false) private int fineId; /** - * precision = 10 means the total number of digits (including decimal places) is 10. - * scale = 2 means the number of decimal places is 2. - * - * @Column(nullable = false, precision = 10, scale = 2) + * The amount of the fine with a precision of 10 and a scale of 2. + * Precision = 10 means the total number of digits (including decimal places) is 10. + * Scale = 2 means the number of decimal places is 2. */ - @Column(nullable = false, scale = 2) + @Column(nullable = false, precision = 10, scale = 2) private BigDecimal amount; + /** + * Indicates whether the fine has been paid. + */ @Column(nullable = false) private boolean paid = false; - public Fines() { + // Default constructor for JPA + public Fine() { } - public Fines(BigDecimal amount, boolean paid) { + // Constructor with fields + public Fine(BigDecimal amount, boolean paid) { this.amount = amount; this.paid = paid; } + /** + * Gets the unique ID of the fine. + * + * @return the unique fine ID + */ + public int getFineId() { + return fineId; + } + + /** + * Gets the amount of the fine. + * + * @return the amount of the fine + */ public BigDecimal getAmount() { return amount; } + /** + * Sets the amount of the fine. + * + * @param amount the amount to set + */ public void setAmount(BigDecimal amount) { this.amount = amount; } + /** + * Checks if the fine has been paid. + * + * @return true if the fine is paid, false otherwise + */ public boolean isPaid() { return paid; } + /** + * Sets the payment status of the fine. + * + * @param paid true if the fine is paid, false otherwise + */ public void setPaid(boolean paid) { this.paid = paid; } - public int getFineId() { - return fineId; + /** + * Provides a string representation of the Fine object. + * + * @return a string containing the fine details + */ + @Override + public String toString() { + return "Fine{" + + "fineId=" + fineId + + ", amount=" + amount + + ", paid=" + paid + + '}'; } }