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 4, Problem 40E
Program Plan Intro
To define a field for the type ArrayList within the club that is intended to store the objects of membership.
Write a program in BlueJ using Java and achieve the target of storing membership objects in a collection. Also, to use appropriate import statement for the same to use the collection.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This 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.
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…
To demonstrate working with ArrayLists, we will be working with four source files: a Dessert class, two classes that extend Dessert called IceCream and Cake, and a TestDessert class. The TestDessert class contains a main() method that declares an ArrayList to hold Dessert objects. This ArrayList is referenced by the variable named "list".
Examine TestDessert's main() method and notice the four comments. You are to implement code that accomplishes the tasks described in each step.
For step 1, you are to populate the ArrayList with 10 IceCream and Cake objects. These objects should be inserted into the ArrayList at random. This means each run of the program should produce an ArrayList with different proportions of IceCream and Cake objects. After this operation, the ArrayList should contain 10 total objects (IceCream and Cake objects). Display the ArrayList after the operation.
For step 2, if the first and last dessert in the ArrayList are different (one is IceCream and the other is…
Chapter 4 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Ch. 4 - Prob. 1ECh. 4 - What happens if you create a new MusicOrganizer...Ch. 4 - Prob. 3ECh. 4 - Prob. 4ECh. 4 - Write a declaration of a local variable called...Ch. 4 - Prob. 6ECh. 4 - Write assignments to the library, cs101. and track...Ch. 4 - If a collection stores 10 objects, what value...Ch. 4 - Write a method call using get to return the fifth...Ch. 4 - Prob. 10E
Ch. 4 - Write a method call to add the object held in the...Ch. 4 - Write a method call to remove the third object...Ch. 4 - Suppose that an object is stored at index 6 in a...Ch. 4 - Add a method called checklndex to the...Ch. 4 - Write an alternative version of checkIndex called...Ch. 4 - Rewrite both the 1istFi1e and removeFi1e methods...Ch. 4 - Prob. 17ECh. 4 - Prob. 18ECh. 4 - We know that the first file name is stored at...Ch. 4 - Prob. 20ECh. 4 - Create a MusicOrganizer and store a few file names...Ch. 4 - Create an ArrayList<String> in the Code Pad by...Ch. 4 - If you wish, you could use the debugger to help...Ch. 4 - Challenge exercise The for-each loop does not use...Ch. 4 - Prob. 25ECh. 4 - Prob. 26ECh. 4 - Prob. 27ECh. 4 - Write out the header of a for-each loop to process...Ch. 4 - Suppose we express the first version of the key...Ch. 4 - Write a while loop (for example, in a method...Ch. 4 - Write a while loop to add up the values 1 to 10...Ch. 4 - Write a method called sum with a while loop that...Ch. 4 - Challenge exercise Write a method isPrime (int n)...Ch. 4 - In the findFirst method, the loop's condition...Ch. 4 - Prob. 35ECh. 4 - Have the MusicOrganizer increment the play count...Ch. 4 - Prob. 37ECh. 4 - Prob. 38ECh. 4 - Prob. 39ECh. 4 - Prob. 40ECh. 4 - Complete the numberOfMembers method to return the...Ch. 4 - Prob. 42ECh. 4 - Prob. 43ECh. 4 - Prob. 44ECh. 4 - Challenge exercise Write a method to play every...Ch. 4 - Prob. 46ECh. 4 - Prob. 47ECh. 4 - Add a close method to the Auction class. This...Ch. 4 - Add a getUnsold method to the Auction class with...Ch. 4 - Suppose the Auction class includes a method that...Ch. 4 - Rewrite getLot so that it does not rely on a lot...Ch. 4 - Prob. 52ECh. 4 - Prob. 53ECh. 4 - Prob. 54ECh. 4 - Prob. 55ECh. 4 - Open the products project and complete the...Ch. 4 - Implement the findProduct method. This should look...Ch. 4 - Implement the numberInStock method. This should...Ch. 4 - Prob. 59ECh. 4 - Challenge exercise Implement a method in...Ch. 4 - Java provides another type of loop: the do-while...Ch. 4 - Prob. 85ECh. 4 - Prob. 86ECh. 4 - Find out about Java's switch-case statement. What...
Knowledge Booster
Similar questions
- The UnsortedTableMap class is located in the maps folder. In the attachment, you will find a partially implemented class called UnsortedMapOfLists, which extends UnsortedTableMap. The values associated with the keys in UnsortedMapOfLists are arrays. So you have an array with each key. Off course you can save an array in the value of UnsortedTableMap class without the class we are going to develop, but our class makes this easier, as it allows using a syntax like this: myMap["somekey", 1] to reach element at index 1 in the array associated with key "somekey". I already implemented methods __setitem__ and __getitem__. Your task is to: implement method __delitem__ . Deletion will be performed for an element in the array. If index is not given, delete the array associated with the key. implement a function (not a method in the class) to swap the arrays associated with two given keys. Add the required comment in method __getitem__. implement a main to verify that your code is working…arrow_forwardQ8. Write a declaration of a private field named department that can hold an ArrayList. The elements of the ArrayList are of type Student. Write an assignment to the department variable to create an appropriate ArrayList object. Q9. (A) If a collection stores 20 objects, what value would be returned from a call to its size method? (B) Write a method call using get to return the fifth object stored in a collection called department. Q10. Write a method call to add the object held in the variable student1 to a collection department files.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
- A for construct is used to build a loop that processes a list of elements in programming. To do this, it continues to operate forever as long as there are objects to process. Is this assertion truthful or false? Explain your response.arrow_forwardHow do I add several objects to an ArrayList in JAVA using a loop?arrow_forwardcontinue from first question, Client class:The client program will allow entry of these data for several different student into an ArrayList and then perform some analysis and queries.Your client class (program) will provide the user with a menu to perform the following operations. You will also need to load the information of the students from a CSV file (student.csv) before displaying the menu. You only need one ArrayList and one menu for this. For the csv file, your first item can be U or G to differentiate whether the entry is creating a UndergraduateStudent object, or a GraduateStudent object. You can then decide how you want other data to be listed in the csv file. You should specify clearly in your documentation the data format of the CSV files used in this assignment.1. Quit (exit the program)2. Add (to the ArrayList) all the marks information about an undergraduate or graduate student by reading it from another CSV file. Your program will ask for the file name.3. Given student…arrow_forward
- Say we are about to build an ArrayList. Your ArrayList should guarantee that the array capacity is at most four times the number of elements. What would you like to do to maintain such a limit on the capacity? What is the benefit of using iterators? Can you describe your first experience of GUIs? And could you describe what is the advantage of using GUIs over Command-Line Interface (CLI) operations?arrow_forwardPart 2: Sorting the WorkOrders via dates Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class. The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters. You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you…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_forward
- Write code that will accept as input the characteristics of an undefined number of different softdrinks. Each softdrink should have a colour (of the can), name and volume. • Create SoftDrink objects and store them in an ArrayList (see the Appendix) as each softdrink is entered. • Alternatively, you can use an array. Take a number of items first, create an array of that size and read in the elements. • Prompt the user to add a softdrink until they choose to quit. • Once the user quits, print out a list of the softdrinks that the user has entered, sorted first by alphabetical order of name, then by colour, then by volume (ascending order). Name your driver class Question2.java. NOTE: • You can use the built-in static sort() method in the java.util.Collections class to sort your ArrayList of SoftDrink objects. Sample I/O Enter option: (1) add soft drink (2) quit: 1 Enter name, colour and volume in ml separated by space Fanta Orange 500 Enter option: (1) add soft drink (2)…arrow_forwardCreate a new class, called ConstantList that stores a "constant" list of integers (ints). Once created the list is fixed (none of the items can be changed, no items can be added or removed, the order is fixed). Use an array to store your list. Your class will have a single constructor that takes an array of ints as input that will be used to specify the constant list. You must provide appropriate methods to give the user of your class access to the list elements. A user should be able to access individual elements (by position) and the entire list of numbers. Your class must use encapsulation. Explain how your solutions solves the problem. That is, explain why your ConstantList really is a constant list of numbers.arrow_forwardCreate a new class, called ConstantList that stores a "constant" list of integers (ints).Dnce created the list is fixed (none of the items can be changed, no items can be added or removed, the order is fixed). Use an array to store your list. Your class will have a single constructor that takes an array of ints as input that will be used to specify the constant list. You must provide appropriate methods to give the user of your class access to the list elements. A user should be able to access individual elements (by position) and the entire list of numbers. Your class must use encapsulation. Explain how your solutions solves the problem. That is, explain why your ConstantList really is a constant list of numbers.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