Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 17.1, Problem 17.3CP
Suppose we use the following statement to instantiate the ArrayList class. What type of objects will we be allowed to store in the ArrayList?
ArrayList<Rectangle> myList = new ArrayList<>();
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given these three ArrayLists:
ArrayList collectionA = new ArrayList();
ArrayList collectionB = new ArrayList(15);
ArrayList collectionC = new ArrayList(25) ;
After adding 390 items to each collection, answer the following two questions:
Blank 1: Which ArrayList has the largest capacity for the array data member being
used internally for storing the items in the object?
Blank 2: What is the capacity for the object in blank one?
Blank # 1
A
Blank # 2
A
Library class:
Fields: books as arraylist to store all the books available in the library
B3
B1
B2
В4
B5
Constructor:
Library()
}
: No parameterized constructor to create the books object
Methods:
1. addBook(Book bookobj): to add a new book to the arraylist; send the book object as a
parameter to this method.
2. searchBook(String name): search a book by a given name in the arraylist. if exits print
bookX found; otherwise print not found!!!
3. RemoveBook(String name): to delete a book object from arraylist by a given name:
Hint: you need to use iterator class and remove method.
Book class:
Fileds: bookld, bookname.
Constructor: two parameterized constructor that accepts name
a parameter
Book(int ID, String name)
.....
Methods:
1. Accessor method to return the name of the book
2. Mutator method to change the id of the book.
Use this Main method: in your program:
public static void main(String args[])
{
Library lib=new Library();
lib.addBook(new Book("b1"));
lib.addBook(new Book("b2"));…
Define a class called Book. This class should store attributes such as the title, ISBN number, author, edition, publisher, and year of publication. Provide get/set methods in this class to access these attributes. Define a class called Bookshelf, which contains the main method. This class should create a few book objects with distinct names and store them in an ArrayList. This class should then list the names of all books in the ArrayList. Enhance the program by providing a sort function, which will sort the books in ascending order of their year of publication. Create a few more Bookobjects with the same names but with different edition numbers, ISBNs, and years of publication. Add these new Book objects to the ArrayList, and display the book list sorted by book name; for duplicate books of the same name, sort the list by year of publication. (Hint: You will need to define a comparator class that takes two Book objects as parameters of the compareTo This method should do a two-step…
Chapter 17 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - When ArrayList is used as a non-generic class, why...Ch. 17.1 - Suppose we use the following statement to...Ch. 17.1 - Assume we have used the statement shown in...Ch. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Prob. 17.7CPCh. 17.2 - Prob. 17.8CPCh. 17.3 - Prob. 17.9CPCh. 17.3 - Prob. 17.10CP
Ch. 17.3 - Prob. 17.11CPCh. 17.3 - Prob. 17.12CPCh. 17.3 - Prob. 17.13CPCh. 17.3 - Prob. 17.14CPCh. 17.4 - Prob. 17.15CPCh. 17.5 - Prob. 17.16CPCh. 17.5 - Prob. 17.17CPCh. 17.6 - Prob. 17.18CPCh. 17.6 - Prob. 17.19CPCh. 17.6 - Prob. 17.20CPCh. 17.8 - Prob. 17.21CPCh. 17.8 - Prob. 17.22CPCh. 17.9 - Prob. 17.23CPCh. 17.9 - During the process of erasure, when the compiler...Ch. 17.9 - Prob. 17.25CPCh. 17 - Prob. 1MCCh. 17 - Prob. 2MCCh. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Prob. 7MCCh. 17 - Prob. 8MCCh. 17 - Prob. 9MCCh. 17 - The process used by the Java compiler to remove...Ch. 17 - True or False: It is better to discover an error...Ch. 17 - Prob. 12TFCh. 17 - True or False: Type parameters must be single...Ch. 17 - Prob. 14TFCh. 17 - Prob. 15TFCh. 17 - True or False: You cannot create an array of...Ch. 17 - Prob. 17TFCh. 17 - Prob. 18TFCh. 17 - Prob. 1FTECh. 17 - Assume the following is a method header in a...Ch. 17 - public class MyClassT { public static void...Ch. 17 - public class PointT extends Number super Integer {...Ch. 17 - Assume there is a class named Customer. Write a...Ch. 17 - Assume names references an object of the...Ch. 17 - Prob. 3AWCh. 17 - Prob. 4AWCh. 17 - Prob. 5AWCh. 17 - Prob. 6AWCh. 17 - Prob. 7AWCh. 17 - Prob. 1SACh. 17 - Look at the following method header: public T...Ch. 17 - Prob. 3SACh. 17 - Do generic types exist at the bytecode level?Ch. 17 - Prob. 5SACh. 17 - When the compiler encounters a class, interface,...Ch. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In Exercises 53 through 56, determine the output produced by the lines of code where Courier New is the font se...
Introduction To Programming Using Visual Basic (11th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (8th Edition)
What is the output of the following code? (You may need to use a calculator.) const int SIZE = 5; int time[SIZE...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Give an example of each of the following, other than those described in this chapter, and clearly explain why y...
Modern Database Management
What is the value of the program counter in the Vole immediately after executing the instruction 0xB0CD?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Bug Collector A bug collector collects bugs every day for seven days. Design a program that keeps a running tot...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. ArrayListsCreate a class called OurArrayList and implement the following methods. Do NOT create any auxiliary memory.Include a main method and test all your methods with appropriate examples.Assume the following classes have been defined:a. Write a method called scaleByK() that takes an ArrayList of integers as a parameter and replaces every integer of value K with K copies of itself. For example, if the list stores the values (4, 1 , 2, 0 ,3) before the method is called, it should store the values (4, 4, 4, 4, 1, 2, 2, 3, 3, 3) after the method finishes executing. Zeroes and negative numbers should be removed from the list by this method.b. Write a method markLength4() that takes an ArrayList of Strings as a parameter and that places a String of four asterisks ("****") in front of every String of length 4. For example, suppose that an ArrayList called "list" contains the following values:(this, is, lots, of, fun, for, every, Java, programmer)And you make the following…arrow_forwardThis program is going to maintain a list of customers’ names and bank account balances. 1. Create a class called CustomerList with a main method that instantiates an ArrayList of String objects called customerName. Invoke the add method to add the following names into the ArrayList: Cathy Ben Jorge Wanda Freddie 1. Print each name in the ArrayList using a for a loop. 2. Create another ArrayList object called customerBalance, to save users’ balance. What is the type of this ArrayList? double or Double? You just need to declare this ArrayList and leave it empty for now. 3. For each customer, print the name and ask the user to enter the initial balance for this customer. Save the initial balance into ArrayList customerBalance. Use a loop to get this done for all 5 customers. The program should print out this for the first customer: Example: Please enter the account balance for Cathy: (waiting for user’s input …) Code: for(int i=0; i<5;i++) { Print(“Please enter the account balance…arrow_forwardgetListRowIndices Method public static java.util.ArrayList<java.lang.Integer> getListRowIndices(int[][] array, int rowLength) This method returns an ArrayList with the indices of rows of the two-dimensional having a length that corresponds to rowLength. You may only use one auxiliary method. The method should create an ArrayList that is passed to the auxiliary in order to place the indices (if any). If no indices are found, an empty (size of 0) ArrayList will be returned. You can assume the array parameter will not be null and every row of the two-dimensional array has an array with a size of at least 0. Your implementation must be recursive and you may not use any loop construct. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: array - rowLength - Returns: ArrayList<Integer>arrow_forward
- Add a getUnsold method to the Auction class with the -following header: public ArrayList getUnsold() This method should iterate over the lots field, storing unsold lots in a new ArrayList local variable. What you are looking for is Lot objects whose highestBid field is null. At the end of the method, return the list of unsold lots.arrow_forwardThis lab was designed to reinforce programming concepts from this lab, you will practice: Declaring and initializing ArrayList. Add elements to the Arraylist. Display the content of the ArrayList. Write a class name PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and the appropriate accessor and mutator methods. Then write a program that creates at least 5 PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.arrow_forwardTask 4. Utility classes Implement a Menu-Driven program of ArrayList class using the above scenario and perform the following operations. a. Create an object of ArrayList class based on the scenario with explanations of the method used. b. Create a method that will allow inserting an element to ArrayList Class based on the scenario. The input field must be validated as necessary. C. Create a method to delete specific elements in the ArrayList with explanations of the method used.arrow_forward
- Use this exercise to test your code that you wrote in the previous exercise. CookBook Class In this exercise, you are going to complete the CookBook class. public class CookBook { private ArrayList<Recipe> recipes; private String name; public CookBook(String name){ this.name = name; recipes = new ArrayList<Recipe>(); } /** * This method adds a recipe to the ArrayList of Recipes * @param recipe a recipe object to be added to the list */ public void addRecipe(Recipe recipe){ /* Implement this method */ } /** * This method removes all recipes from the * ArrayList of Recipes where the title matches the input * string * * @param title the title of the recipe to remove * @return the number of recipes removed */ public int removeRecipe(String title){ /* Implement this method */ } /** * This method lists the title of all the recipes in the * cook book * */ public void listAll(){ /* Implement this method */ } } The addRecipe method should take a recipe and add it to the end of the…arrow_forwardMake a shopping cart program that implements the ArrayList class. Make a class named Item.java that contains the following data members, item_name, quantity, and price. Create the appropriate constructors and methods to initialize, access, and manipulate the data members, also create a toString method to print the item name, quantity, and price. Create an ArrayList of Items in the Main.For the INPUTThe user will enter the item name, quantity, and price of each item. A 'Y' will add another item to the shopping cart, and 'N' will stop the input.For the OUTPUTThe program then lists the items in the shopping cart using the toString method in the Item class. Calculate for the subtotal and total of the items in the cart.Format your toString method to have a double tab, "\t\t", after the item name, single tab, "\t", after quantity and double tab, "\t\t", after price. EXAMPLEINPUTPencil215.25yYellow Paper150.00nOUTPUTPencil 2 15.25 30.50Yellow Paper 1 50.00…arrow_forwardGiven a base Plant class and a derived Flower class, complete main() to create an ArrayList called myGarden. The ArrayList should be able to store objects that belong to the Plant class or the Flower class. Create a method called printArrayList(), that uses the printInfo() methods defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the myGarden ArrayList, and output each element in myGarden using the printInfo() method. Ex. If the input is: plant Spirea 10 flower Hydrangea 30 false lilac flower Rose 6 false white plant Mint 4 -1 the output is: Plant 1 Information: Plant name: Spirea Cost: 10 Plant 2 Information: Plant name: Hydrangea Cost: 30 Annual: false Color of flowers: lilac Plant 3 Information: Plant name: Rose Cost: 6 Annual: false Color of flowers: white Plant 4 Information: Plant name: Mint Cost: 4 import java.util.Scanner;import java.util.ArrayList;import…arrow_forward
- create a driver program, CarTestDriver that uses a Garage object to store Cars. The Garage object is an instantiation of a Garage class that contains “parking”, an array of Car types. You must use a Car[] not an ArrayList<Car> for the “parking” in the garage. I suggest setting up the Car class with a default constructor that generates random values to create each new Car object. The rules for driving the cars from the garage are: The size of the garage is specified by the user. The user may only use cars from the garage A Car is removed from the Garage when a user retrieves a Car from the Garage. The Car is returned to the Garage, after it is driven if it does not run out of fuel. The user interacts with the Car object after the Car object is retrieved from the garage. The program should not fail due to a user selection. A car may only be refueled when the user selects the Car for use, prior to being removed from the Garage The user may select to drive any car that is currently…arrow_forwardPart #2: Write a class called Test equallists having main method to test the application. In main method create following: 1- Object of type ArrayList list1. 2- Add the following data to list1 (4 13 3- Object of type ArrayList list2. 4- Add the following data to list2 (4 2 1 12 5- Object of type ArrayList list3. 6- Test the equallists method to print the result. Example: list1: 4 13 1 list2: 4 2 1 list3: 1 0 8 12 1 9 0 9 0 2 0 OOL 1 0 (generated by the method) 0 150 10 18 19 01). 9205).arrow_forwardHow do you do this? JAVAarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License