Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/incrementaltest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
public class ChickenOrder {
Comment thread
teg-atlassian marked this conversation as resolved.

// Calculates the total price of a rotisserie chicken order
public double calculateTotal(int quantity, double pricePerChicken, boolean isMember) {
double discount = 0.0;

if (isMember) {
discount = 0.10; // 10% member discount
}
double total = quantity * pricePerChicken * (1 + discount);
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Code Bugs

The discount is applied in the wrong direction — (1 + discount) increases the price by 10% instead of reducing it; it should be (1 - discount).

Details

📖 Explanation: The discount is being added instead of subtracted, resulting in members paying 10% more rather than less.

Suggested change
double total = quantity * pricePerChicken * (1 + discount);
double total = quantity * pricePerChicken * (1 - discount);

Uses AI. Verify results. Give Feedback


return total
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Code Bugs

return total is missing a semicolon, which will cause a compilation error.

Details

📖 Explanation: Missing semicolon causes a compilation error.

Suggested change
return total
return total;

Uses AI. Verify results. Give Feedback

}

// Returns the estimated wait time in minutes based on current queue size
public int estimateWaitTime(int queueSize, int avgServiceTimeSeconds) {
int waitMinutes = (queueSize * avgServiceTimeSeconds) / 60;
return waitMinutes;
}

// Returns the name of the most popular item given a list of order counts
public String getMostPopular(String[] items, int[] counts) {
int maxIndex = 0;

for (int i = 0; i <= counts.length; i++) {
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.
Comment thread
mchun2288 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Code Bugs

The loop condition i <= counts.length will throw an ArrayIndexOutOfBoundsException on the last iteration; it should be i < counts.length.

Details

📖 Explanation: Using <= instead of < causes an ArrayIndexOutOfBoundsException on the last iteration.

Suggested change
for (int i = 0; i <= counts.length; i++) {
for (int i = 0; i < counts.length; i++) {

Uses AI. Verify results. Give Feedback

if (counts[i] > counts[maxIndex]) {
maxIndex = i;
}
}

return items[maxIndex];
}

// Returns a formatted receipt line for a single item
public String formatReceiptLine(String item, double price) {
return String.format("%-20s $%.2f", item, price);
}

// Returns true if the order qualifies for free delivery (total over $25)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Maintainability - Documentation

The comment says "total over $25" but the implementation uses >=, meaning an order of exactly $25.00 also qualifies — consider updating the comment to "total of $25 or more" to accurately reflect the condition.

Details

📖 Explanation: There is a mismatch between the inline comment and the actual comparison operator used in the implementation.

Uses AI. Verify results. Give Feedback

public boolean qualifiesForFreeDelivery(double orderTotal) {
return orderTotal >= 25.0;
}

public static void main(String[] args) {
ChickenOrder order = new ChickenOrder();

System.out.println("Total: $" + order.calculateTotal(2, 4.99, true));

String[] items = {"Rotisserie Chicken", "Hot Dog", "Pizza"};
int[] counts = {150, 200, 80};
System.out.println("Most popular: " + order.getMostPopular(items, counts));
}
}
Loading