Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 4, Problem 1E

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  1

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  2

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  3

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  4

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  5

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  6

As we have added two files to the collection, the method result of getNumberOfFiles returned 2.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  7

To print the files stored in the collection of the class instance objMusicOrg1, we require to method call listFile.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  8

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  9

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.

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition), Chapter 4, Problem 1E , additional homework tip  10

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Please answer the JAVA OOP Programming Assignment scenario below: Patriot Ships is a new cruise line company which has a fleet of 10 cruise ships, each with a capacity of 300 passengers. To manage its operations efficiently, the company is looking for a program that can help track its fleet, manage bookings, and calculate revenue for each cruise. Each cruise is tracked by a Cruise Identifier (must be 5 characters long), cruise route (e.g. Miami to Nassau), and ticket price. The program should also track how many tickets have been sold for each cruise. Create an object-oriented solution with a menu that allows a user to select one of the following options: 1. Create Cruise – This option allows a user to create a new cruise by entering all necessary details (Cruise ID, route, ticket price). If the maximum number of cruises has already been created, display an error message. 2. Search Cruise – This option allows to search a cruise by the user provided cruise ID. 3. Remove Cruise – This op…
I need to know about the use and configuration of files and folders, and their attributes in Windows Server 2019.
Southern Airline has 15 daily flights from Miami to New York.  Each flight requires two pilots.  Flights that do not have two pilots are canceled (passengers are transferred to other airlines).  The average profit per flight is $6000.  Because pilots get sick from time to time, the airline is considering a policy of keeping four *reserve pilots on standby to replace sick pilots.  Such pilots would introduce an additional cost of $1800 per reserve pilot (whether they fly or not). The pilots on each flight are distinct and the likelihood of any pilot getting sick is independent of the likelihood of any other pilot getting sick.  Southern believes that the probability of any given pilot getting sick is 0.15.  A) Run a simulation of this situation with at least 1000 iterations and report the following for the present policy (no reserve pilots) and the proposed policy (four reserve pilots): The average daily utilization of the aircraft (percentage of total flights that fly) The…

Chapter 4 Solutions

Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)

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
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning