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
Expert Solution & Answer
Chapter 4, Problem 6E
Explanation of Solution
Given: Private field ‘tracks’ which stores a collection of objects named MusicTrack.
To find: The declaration to the private field tracks which stores a collection of objects named MusicTrack...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
How do I add several objects to an ArrayList in JAVA using a loop?
A Maze Room :
In this lab, we will make a maze game. The maze is based on Linked Lists. Instead of having one possible direction (next), we will have 4 possible directions.
Rooms:
Use the below code as a basis to build your own room class. Implement this class in the file room.py
A room will be the basic object for our maze game. A room can have 4 doors (pertaining to north, south, east, and west). Attached to each these directions we have either another room or None (we could also imagine that the None doors are just walls).
We want the player to be able to tell what room they are in. Each room will have a unique description. When the player enters a room, the program will describe the room. This way the player will know if they went back to a room that have already been to.
You MAY NOT change the method's arguments/names in ANY way.
class Room():def __init__(self, descr):#Description of the room to print out#These should be unique so the player knows where they areself.descr =…
Can someone help me write a class in Java.
The class will read a file of people: their name, year of birth, and year of death. The class must have at least one ArrayList.
The class's constructor will read the file specified by its parameter. Each line looks like the samplebelow:FirstName LastName YearOfBirth YearOfDeathThe items on each line are separated by tabs.
The class will also have these methods:
-preBoom() : This method will return the number of people born before 1945, the start ofthe Baby Boom
- minAge() : This method will return the age of the youngest person in the list
- maxAge() : This method will return the age of the oldest person in the list
- aveAge() : This method will return the average age of the people in the list. Theaverage value returned will be an integer.
- seniors() : This method will return the number of people aged 65 or over
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
- Write a declaration of a private field named library that can hold an ArrayList. The elements of the ArrayList are of type Book.arrow_forwardJAVA Write a METHOD named friendList that accepts a file name as a parameter and reads friend relationships from a file and stores them into a compound collection that is returned. You should create a map where each key is a person's name from the file, and the value associated with that key is a setof all friends of that person. Friendships are bi-directional: if Marty is friends with Danielle, Danielle is friends with Marty. The file contains one friend relationship per line, consisting of two names. The names are separated by a single space. You may assume that the file exists and is in a valid proper format. If a file named buddies.txt looks like this: Marty Cynthia Danielle Marty Then the call of friendList("buddies.txt") should return a map with the following contents: {Cynthia=[Marty], Danielle=[Marty], Marty:[Cynthia, Danielle]} Constraints: You may open and read the file only once. Do not re-open it or rewind the stream. You should choose an efficient solution. Choose data…arrow_forwardTask 1:The first task is to make the maze. A class is created called Maze, in which a 2D array for the maze is declared. Your job is to implement the constructor according to the given javaDoc. When you completed this task, write a set of Junit test case to test your code.As you probably noticed, the maze is defined as a private variable. The second job for you is to write an accessor(getter) method that returns the maze. Other information about what is expected for this method is given in the starter code. public class PE1 { MazedogMaze; /** * This method sets up the maze using the given input argument * @param maze is a maze that is used to construct the dogMaze */ publicvoidsetup(String[][]maze){ /* insert your code here to create the dogMaze * using the input argument. */ }arrow_forward
- 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…arrow_forwardWrite a declaration of a local variable called cs101 that can hold an ArrayList of Student.arrow_forwardQ2 Create MusicOrganizer project using BlueJ . (i) Create a MusicOrganizer class and declare an ArrayList for storing the file names of music files into the String object. (ii) Create a constructor for the music organizer class and assign the field to the ArrayList. (iii) Write a method to add a file to the collection. (iv) Write a method to return the number of files in the collection. (v) Write a method to remove a file from the collection. (vi) Make a screen shot of the coding and output.arrow_forward
- Create a Point classCreate a Point class as we did in the class. We'll use this to create Point objects that hold x,y coordinates of locations where we'll want to draw. Draw DotsWrite a drawDots(points) function that takes a list points as input and draws a dot on the drawing window for each Point. For example, you should be able to call your function as follows: >>> p = Point(10, 20) >>> q = Point(20, 30) >>> points = [p, q] >>> drawDots(points)arrow_forwardOCaml Code: The goal of this project is to understand and build an interpreter for a small, OCaml-like, stackbased bytecode language. Make sure that the code compiles correctly and provide the code with the screenshot of the output. The code must have a function that takes a pair of strings (tuple) and returns a unit. You must avoid this error that is attached as an image. Make sure to have the following methods below: -Push integers, strings, and names on the stack -Push booleans -Pushing an error literal or unit literal will push :error: or :unit:onto the stack, respectively -Command pop removes the top value from the stack -The command add refers to integer addition. Since this is a binary operator, it consumes the toptwo values in the stack, calculates the sum and pushes the result back to the stack - Command sub refers to integer subtraction -Command mul refers to integer multiplication -Command div refers to integer division -Command rem refers to the remainder of integer…arrow_forward2. The class PetShop has a single field as defined below: private ArrayList petList; Define a method to print out the details of all cats in petList in PetShop.arrow_forward
- Build two classes (Fraction and FractionCounter) and a Driver for use in counting the number of unique fractions read from a text file. We’ll also reuse the ObjectList class we built in lab to store our list of unique FractionCounters, instead of directly using arrays or the ArrayList. Remember NO DECIMALS! Handle input of any length Introduction Your project is to read in a series of fractions from a text file, which will have each line formatted as follows: “A/B”. A sample text file is listed below, and the purpose of your program is to read in one line at a time and build a Fraction object from A and B. For each unique Fraction seen, your program will create a FractionCounter object used to track the number of occurrences of that specific fraction. When all the input is consumed, your program will print out its ObjectList of unique FractionCounters, which should report the fraction and its count – see output below. You can assume no blank lines or misleading characters; see…arrow_forwardfindYoungestPlayer takes an array of Player objects and returns the youngest player. If there are no players in the array (all of the entries are null), it throws a NoSuchPlayerException. javaarrow_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_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