Skip to content
Open
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions src/incrementaltest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 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];
}

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