Program plan:
The variables used in the program are given below:
- item: SalesItem - an instance of the SalesItem class, which represents a sales item being sold on a website or in a store.
- comment1: Comment - an instance of the Comment class, which represents a comment left by a user about the sales item.
- comment2: Comment - another instance of the Comment class, representing a second comment about the sales item.
- comment3: Comment - a third instance of the Comment class, representing a third comment about the sales item.
The methods used in the program are as follows:
- addComment(comment: Comment): void - a method of the SalesItem class that adds a new Comment object to the item's list of comments.
- getComments(): List
- a method of the SalesItem class that returns a list of all Comment objects that have been added to the item. - assertEquals(expected: int, actual: int): void - a method of the org.junit.Assert class that checks if two integer values are equal, and throws an assertion error if they are not.
- assertTrue(condition: boolean): void - a method of the org.junit.Assert class that checks if a given boolean condition is true, and throws an assertion error if it is not.
- testAddNullComment(): a unit test method that tests the behavior of the SalesItem class when attempting to add a null comment to an item. Expects an IllegalArgumentException to be thrown.
Program Description:
The given code is a unit test written in JUnit framework for the addComment() method of the SalesItem class. It creates a new SalesItem object with a name and description and then adds three comments to it using addComment() method. The test then checks that the comments were added successfully by verifying that the size of the SalesItem's comments list is 3 and that each of the three comments is contained in the list. This is an important test to ensure that comments can be successfully added to a SalesItem object, which is a critical feature of the class for user interaction and feedback.
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- Thank you much. The code doesn't return the right answers for the test cases. Is there a way to fix?arrow_forwardPLEASE ENSURE TO USE THE FRAMEWORK PROVIDED IN THE IMAGES, AND THAT IT WORKS WITH THE TESTER CLASS. PLEASE EDIT BOTH THE TEST CLASS, DO NOT EDIT THE MAIN METHOD. Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.arrow_forward.If the name of getBalance is changed to getAmount, does the return statement in the body of the method also need to be changed for the code to compile? Try it out within BlueJ. What does this tell you about the name of an accessor method and the name of the field associated with it?arrow_forward
- Make the changes we have described to the Room and Game classes.arrow_forwardTry removing the return statement from the body of getPrice. What error message do you see now when you try compiling the class?arrow_forwardI am not sure how to do this problem recursively DO NOT use System.exit(). DO NOT add project or package statements. DO NOT change the class name. DO NOT change the headers of ANY of the given methods. DO NOT add any new class fields (instance variables). ONLY display the result as specified by the example for each problem. DO NOT print other messages, follow the examples for each problem. You may USE the StdOut library. On RecursiveAppend.java write a recursive method appendNTimes that receives two arguments, a string and an integer. The method appendNTimes returns the original string appended to the original string n times. Use the following method header:public static String appendNTimes (String original, int n) Examples: appendNTimes("cat", 0) returns “cat” appendNTimes("cat", 1) returns “catcat” appendNTimes("cat", 2) returns “catcatcat” The following restrictions apply to method appendNTimes: the CODE MUST BE RECURSIVE Do not use loops (while, do/while, or for).…arrow_forward
- Can I use it for my assignment...?? Will this code have any plagiarism when checked??arrow_forwardUse the debugger to examine the clock-display project. Set breakpoints in the ClockDisplay constructor and each of the methods, and then singlestep through them. How do you feel about the way it's behaving? Have you gained any fresh insights as a result of this? If this is the case, what exactly were they?arrow_forwardThis is a new homework assignment. Fill in the blanks.arrow_forward
- What changes do you notice if you run the simulation for a much longer time, say for 4,000 steps? You can use the runLongSimulation method to do this.arrow_forwardWrite a mock Armor class. You will only need the protect() method. Paste it into the space below.arrow_forwardFor your final project, you will simply calculate the correct change due after purchase. In our previous assignment, we calculated quarters change in a void function. Here we are doing value returning functions. Do not overcomplicate this. I have provided ample instructions and hints. Plan your mode of attack before you start. If you need assistance, refer first to the hands-on exercise and tutorial you completed on Value Returning Functions in Kotlin in the Methods module. After that, ask me! 1. Create a local double variable called change and set it to a test value (e.g. 44.77) 2. Create five separate functions dollars0, quarters(), dimes(), nickels() and pennies(). 3. Each function will - accept a double amount as an argument - calculate and display that denominations number (e.g. 7 Dollars) - then return the recalculated change (e.g. 0.67) In Kotlin, the function signature for quarters would be: quarters(myChange: Double): Double For this to work, you will need to work from the…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education