Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 9, Problem 1E
Program Plan Intro
To test that comments can be added, and to inspect the data element of the ArrayList object.
Expert Solution & Answer
Explanation of Solution
Explanation:
Java allows using the JUnit test framework to write and execute automated tests. It contains a set of assert methods to test method code. It uses @Test annotation to define the test case. It also includes two methods:
- setUp() method that runs before every test invocation.
- tearDown() method that runs after every test method.
Program:
The required Java code for JUnit test case is given below:
import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; // The test class SalesItemTest. public class SalesItemTest { // Default constructor public SalesItemTest() { } // Sets up the test fixture. @Before public void setUp() { } // Tears down the test fixture. @After public void tearDown() { } /& * Test case to add two comments and that check the size of ArrayList is correct afterwards. */ @Test public void testAddComments() { SalesItem salesItem1 = new SalesItem("Java for complete Idiots", 21998); assertEquals(true, salesItem1.addComment("James Duckling", "This book is great.", 4)); assertEquals(true, salesItem1.addComment("Jhoky Jonathan", "Super Java book.", 5)); assertEquals(2, salesItem1.getNumberOfComments()); } }
In the above JUnit test case, the two comments are added then test the size of ArrayList by comparing the return value of getNumberOfComments() method with 2.
The inspector to check for the comment list, their size, and elementData field of ArrayList object is as follows:
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Add the code to the end of your monitorLevels() method. It must become the last code of monitorLevels().
Study the comments and complete the code
# Loop through displayList
for i in range(0,len(displayList)):
# Test if the first item in the current sub-list contains the text "Price Level"
# Tip: Remember that each sub-list is a list within a list (displayList). So you have
# to access its items via displayList followed by TWO indexes.
. . .
# Extract the second item from the current sub-list into a variable called priceLevel
priceLevel = . . .
# Test if priceLevel is between previousPrice and currentPrice OR
# priceLevel == previousPrice OR
# priceLevel == currentPrice
if(
. . .
):
# Sound the alarm. Pass in the frequency and duration.…
Write out the header of a for-each loop to process an ArrayList called tracks. Don’t worry about the loop’s body.
Update it to create a class Student that includes four properties: an id (type Integer), a name (type String), a Major (type String) and a Grade (type Double). Use class Student to create objects (using buttonAdd) that will be read from the TextFields then save it into an ArrayList. Perform the following queries on the ArrayList of Student objects and show the results on the listViewStudents (Hint: add buttons as needed):
d) Use lambdas and streams to calculate the total average of all Students grades, then show the result.
1.
Ch3HW;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainApp extends Application{
@Override
publicvoidstart(StageprimaryStage) throwsException {
FXMLLoader loader =newFXMLLoader(getClass().getResource("StudentScreen.fxml"));
Parent parent = loader.load();
Scene scene =newScene(parent);…
Chapter 9 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Knowledge Booster
Similar questions
- Update it to create a class Student that includes four properties: an id (type Integer), a name (type String), a Major (type String) and a Grade (type Double). Use class Student to create objects (using buttonAdd) that will be read from the TextFields then save it into an ArrayList. Perform the following queries on the ArrayList of Student objects and show the results on the listViewStudents (Hint: add buttons as needed): d) Use lambdas and streams to calculate the total average of all Students grades, then show the result. e) Use lambdas and streams to group Students by major, then show the results. 1. Ch3HW; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class MainApp extends Application{ @Override publicvoidstart(StageprimaryStage) throwsException { FXMLLoader loader…arrow_forwardHow do you clear the whole canvas?arrow_forwardAdd a new method to ArrayTools with filter. Make this method accept a String array. Change all the Strings that are longer than 5 characters to uppercase. Write in Java and use test cases 1 & 2 as a result.arrow_forward
- Complete the following code. Attach the simulation too.arrow_forward3. Create an ArrayList of strings to store the names of celebrities or athletes. Add five names to the list. Process the list with a for loop and the get() method to display the names, one name per line. Pass the list to avoid method. Inside the method, Insert another name at index 2 and remove the name at index 4. Use a foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the arraylist and use it to display the list one more time. See Sample Output. SAMPLE OUTPUT Here is the list Lionel Messi Drake Adele Dwayne Johnson Beyonce Here is the new list * Lionel Messi * Drake * Taylor Swift * Adele * Beyonce Using an iterator, here is the list Lionel Messi Drake Taylor Swift Adele Beyoncearrow_forwardPlease explain how to get the genre list to filter and how to associate the i to the title of the movie and display it on the finish screen. You can press to view code on the top right of the screen and you can edit it by creating a remix. Thank you for you help it is due today at 12. var nameList = getColumn("Netflix Content", "Title");var typeList = getColumn("Netflix Content", "Type");var typeSelection;onEvent("typeDropdown", "click", function( ) {typeSelection = getText("typeDropdown");});onEvent("startButton", "click", function( ) {setScreen("typeScreen");console.log("in STARTBUTTON typeSelection = "+typeSelection);});onEvent("toRatingButton", "click", function( ) {setScreen("finishScreen");console.log("typeSelection = "+typeSelection);// for (var i = 0; i < nameList.length; i++) {for (var i = 0; i < 25; i++) {console.log(((" i="+i)+" "+typeSelection)+" "+ratingSelection+" "+genreSelection+"--"+typeList[i]+" "+ratingList[i]+" "+genreList[i]);// if ((typeList[i] ==…arrow_forward
- Guide to working through the project Steps: Write the GradeBook constructor that reads student information from the data file into the ArrayList roster). For now, ignore the grades. Test your GradeBook class before proceeding to the next step. Create the Grade class. Test your Grade class before proceeding to the next step. Modify the Student class to include an ArrayList of Grade. Test the Student class before proceeding to the next step. Finish writing the GradeBook constructor to process the grades as they are read in from the data file. Test the GradeBook class before proceeding to the next step. Add additional functionality to the GradeBook and Student classes one method at a time. Here is Grade.jave code is shown below. public class Grade { // TODO: complete this class as described in this task write-up } GradeBook Class The GradeBook class has a single instance variable roster, an ArrayList of Student. This class performs all operations related to the scores of all…arrow_forwardWrite out what you think the outer wrappers of the Student and LabClass classes might look like; do not worry about the inner part.arrow_forwardImplement the "paint fill"feature seen in several picture editing products.To put it another way, if you have a screen (represented by a two-dimensional array of colours), a point, and a new colour, Fill in the surrounding area until the colour shifts away from the original.arrow_forward
- Use the Iterator Pattern: Create a class called Exercise, and then, in its main method, create an ArrayList called stringArrayList. Add the following five strings to stringArrayList: “one”, “two”, ”three”, ”four”, ”five”. Then, use a for loop and the index of stringArrayList to print all these five strings out to the console. 2. For stringArrayList above, can you use an iterator to traverse the five strings inside, without using the index? 3. If change stringArrayList into a TreeSet, how do you traverse the five strings use an iterator? Implement an Iterator: 4. Create a class called StringArray that is able to store a number of String objects. Create an instance variable, String[] values, (internal data storage) of StringArray to store all the strings. 5. Create a constructor for StringArray, which is able to build an object of StringArray using the parameter. public StringArray(String[] values) 6. Make the class StringArray implements Iterable So that it…arrow_forwardComputer Science Write the client code to show how you make use of the LegacyCircle class with your new design.arrow_forwardThis is a sample data in my JSON file: {"firstName": "Juan","middleName": "Dela","lastName": "Cruz","username": "Juan111","password": "1234"} Please make a JAVA GUI code that will display all the array lists (please make an iterator) in my JSON file. Please make it similar to the image. For each user, please add an "accept" and "reject" option. This will allow the server to decide whether or not to accept the client to the application. You do not have to code the acceptance of the client, just add the buttons, I will be the one to continue the code.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education