-
Notifications
You must be signed in to change notification settings - Fork 78
[AREV-310] (ignore) Incremental test1 #1866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| public class ChickenOrder { | ||||||
|
|
||||||
| // 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); | ||||||
|
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Code BugsThe discount is applied in the wrong direction — Details📖 Explanation: The discount is being added instead of subtracted, resulting in members paying 10% more rather than less.
Suggested change
|
||||||
|
|
||||||
| return total | ||||||
|
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Code Bugs
Details📖 Explanation: Missing semicolon causes a compilation error.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| // 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++) { | ||||||
|
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
mchun2288 marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Code BugsThe loop condition Details📖 Explanation: Using <= instead of < causes an ArrayIndexOutOfBoundsException on the last iteration.
Suggested change
|
||||||
| 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)); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.