Explanation of Solution
Given: The project name music-organizer-v1 and the class name MusicOrganizer.
To find: The way to store the names of some audio files and the number of files returned by the numberOfFiles.
Solution:
Open BlueJ and then open a new project named Music-organizer-v1.
To make the instance of the class MusicOrganizer:
Right-click on the class MusicOrganizer.
Select construct new MusicOrganizer() of the class MusicOrganizer to make its instance.
A window would show up which will ask for the name of the instance.
So, enter the name of the instance as objMusicOrg1 in place of default instance name and click on OK button.
After that, right-click on that instance residing on the object bench and then click on the method addFile to add some file names to the instance.
A window would show up asking for the name of the file to add it to the collection.
Enter any file name (along with its location) within the text box linked with it and then click on the OK button.
Repeat this procedure two times to add two file names to the collection.
To examine the number of files stored, right-click on the instance objMusicOrg1 of the class MusicOrganizer and then click on the method getNumberOfFiles.
As we have added two files to the collection, the method result of getNumberOfFiles returned 2.
To print the files stored in the collection of the class instance objMusicOrg1, we require to method call listFile.
When the method listFile is called, a window would show up which will ask for the file index. Since we have stored 2 files in the collection and the indexing in any collection starts form 0, starting from 0 the index will end at 1, that is, from 0 to 1.
Here, 0 shows the first file index and 1 shows the second file index.
Output:
After clicking on the OK button in the window shown above, we get the following result.
Modifying the index at the time of calling the method listFile, we get the filenames stored in that index on the Terminal Window.
Want to see more full solutions like this?
Chapter 4 Solutions
EBK OBJECTS FIRST WITH JAVA
- Write a main method, in which you should have an Arralylist of students, in which you should include every student. You should have a PhD student named Joe Smith. In addition, you should create an Undergraduate student object for each of your team members (setting their names). If you’re only one person doing the assignment, then you should just create one undergraduate object. For each undergraduate student, you should add add two courses (COIS 2240 and COIS 1020). Loop over the arraylist of students, print their names, if the student is an undergraduate student, print their courses.arrow_forwardhow to write a method that reads in any csv file and extracts the data from the csv file into header and the remaining data using the csv module, and stores them in instance variables. also how to write a code to handle potential errors with file content such as empty file and file not found in python?arrow_forwardI need help creating the printAnimal() method that prints from the menu, I keep getting somethings to print but not the full list and I cannot figure out what I am doing wrong. I have included pictures of the first part of the menu loop and the print menu implement a printAnimals() method that provides easy-to-read output displaying the details of objects in an ArrayList. To demonstrate this criterion in a “proficient” way, your implemented method must successfully print the ArrayList of dogs or the ArrayList of monkeys. To demonstrate this criterion in an “exemplary” way, your implemented method must successfully print a list of all animals that are “in service” and “available”. This is what I have so far for the method: // Complete printAnimals // Include the animal name, status, acquisition country and if the animal is reserved. // Remember that this method connects to three different menu items. // The printAnimals() method has three different outputs…arrow_forward
- What is wrong with the following code? Why? How can you fix it? // Remove all the books which contain the given keyword in book title public void removeAllBooks(String keyword) { for(Book b: booksList) { if (b.getTitle().indexOf(keyword)>=0) { booksList.remove(b); } } }arrow_forwardhow to write a method thar reads in any csv file and extracts the data from the csv file into header and the remaining data using the csv module, and stores them in instance variables. also how to write a code to handle potential errors with file content for example empty file and file not foundarrow_forwardWe know that the first file name is stored at index zero in the ArrayList, and the list stores the file names as strings, so could we write the body of listAllFiles along the following lines? System.out.println(files.get(0)); System.out.println(files.get(1)); System.out.println(files.get(2)); etc. How many println statements would be required to complete the method?arrow_forward
- write the java mini project and upload the code .class as like this and also provide the screenshot of the code. use these method for insert ,remove and search public boolean insertBook(Book b) { for(int i=0; i<books.length; i++) { if(books[i] == null) { books[i] = b; return true; } } return false; } public boolean removeBook(Book b) { for(int i=0; i<books.length; i++) { if(books[i].getIsbn().equalsIgnoreCase(b.getIsbn())) { for(int j=i; j<books.length-1; j++) { books[j] = books[j+1]; } return true; } } return false; } public Book searchBook(String isbn) { for(int i=0; i<books.length; i++) { if(books[i] != null) {…arrow_forwardFirst, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).Then create a new Java application called "Parser" (without the quotation marks) that uses methods to:Get a comma-delimited String of integers (e.g. "4, 8, 16, 32") from the user at the command line and then convert the String to an ArrayList of integers (using the wrapper class) with each element containing one of the input integers in sequencePrint the integers to the command line, using a for loop, so that each integer is on a separate linearrow_forwardProblemYou want to use a library-level interface to EGADS for gathering entropy or gettingcryptographically strong pseudo-random data. For example, you may need entropyon a system such as Microsoft Windows, where there is no built-in API for getting itarrow_forward
- Use 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_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_forwardCan you implement the Student class using the concepts of encapsulation? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. You are given a Student class in the editor. Your task is to add two fields: ● String name ● String rollNumber and provide getter/setters for these fields: ● getName ● setName ● getRollNumber ● setRollNumber Implement this class according to the rules of encapsulation. Input # Checking all fields and getters/setters Output # Expecting perfectly defined fields and getter/setters. There is no need to add constructors in this class.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