Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Explain the solution too. The following implementation of the discount method of

ID: 3693451 • Letter: E

Question

Explain the solution too.

The following implementation of the discount method of the TicketMachine class studied in lectures and labs contains an error. Supposing you have created a JUnit test object ticket200 = new TicketMachine(200); Which of the following JUnit test cases will fail, so alerting you to the error. ticket200.discount(50); assertEquals(150,ticket200.getPrice ()); ticket200.discount(25); assertEquals(125,ticket200.getPrice ()); ticket200.discount(-10); assertEquals(200,ticket200.getPrice()); ticket200.discount(200); assertEquals(200,ticket200.getPrice ()); ticket200.discount(250); assertEquals(200,ticket200.getPrice ());

Explanation / Answer

Case C Will fail

Because we are sending amount = -10 to the discount function.

and when it goes to the if statment in discount funcion it will first check the statement whether amount > 0 and since -10 is not greater than 0 so it will fail. The if statement contains OR operator so it will go to the next condition.

Now it will check wheather amount > price and since amount(-10) is not > price(200) this condition will also fail.

So flow will go in else part of if statement and error messsage "Discount is too large" will be dispalyed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote