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 4E
Explanation of Solution
Given:
A private field named library.
ArrayList.
The type of elements in ArrayList is Book.
To find: The assertion of private field which is named as library also can hold ArrayList with elements of Book type.
Solution:
Following will be the declaration of the private field called l...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Task 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.
Blackjack is a card game where the goal is to reach a score of 21. Create a java version of this game with the following requirements. Extend the JPanel class and create an array of 52 cards. Add four sets of numbers from 1 to 10. Use J for Jack, Q for queen, K for king, and A for ace. Jack through king will have a value of 10, and the ace will have a value of 11. Deal two cards to the user and two cards to the computer. Do not show the value of the computer's first two cards to the user. Add buttons Hit, Stay, and Reset. If the user selects the "Hit" button, randomly select one of the cards from the array, and give it to the user. (After selecting a card, do not reuse this index during the rest of the game.) If the dealer has less than 21, "hit" the dealer, too. When the user selects the "Stay" button, add up the card values. The winner is the person who is closest to 21 without going over. Name the class Blackjack.java.
This 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…
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
- Create a player class and a Key class. A Player hasa name, HP, and a key. A character may only have one key at a time, a Key contains a String array that lists the names of all the placed the key can go. The key should have a use() function that takes in a string of what it is trying to be used on, the function will return true if it can be used on that door, and false if it cannot. The player can pick Up and Drop a key.arrow_forwardLibrary 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"));…arrow_forwardpublic class Product { private String name; private double cost; public Product(String n, double c) { name=n; cost=c; } public String getName() { return name; On the left is code for a class called Product. Fill in the blanks in the code on the right in order to create three appropriate Product instances and add them to the cart ArrayList. Use the output of the code, shown below the code, to guide you. } public double getCost() { return cost; } public String toString() { return (name + "$" + cost); } public static void addProducts (ArrayList c) { add(new Product("Shampoo", 13.89)); add(new Product("Bread",4.99)); add(new Product("Cereal", 7.49)); } public static void main(String[] args) { ArrayList cart = new ArrayList(); ddProducts (cart); for (Product p : cart) { System.out.println(p); } } Output: Shampoo $13.89 Bread $4.99 Cereal $7.49arrow_forward
- Using java Hamburger ClassWrite a Hamburger class with the following six attributes:• bun - the type of bun the burger will be on• patties - the number of patties on the burger• cheese - whether or not the burger will have cheese• price - the price of the burger• toppings - an array of five toppings; it will need to start empty Write getters/setters for all attributesexcept the toppings array.Your constructor should create a single on white with no cheese and no toppings with a price of $2.99.Your class should include the following methods in this order, please: addCheese - this method has noparameters that adds cheese to the burger and increases the price by 75 centssuperSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.50addToppings - this method would present the user with at least five toppings (your choice) stored in an array of Stringobjects. If the user indicates the wants the item, store the String in the toppings array. There…arrow_forwardQ#: Create a class Book that has the following data members: Name ISBN Author Edition Create a constructor to initialize all data members. Write a method PrintInfo to print information containing the fields of class. Write another class called Library that must contain a Main method. Inside Main, make at least 10 instances of Book, stored in an array (or list) of type Book. Call the method printInfo() for each instance. (Hint: use of foreach loop will be beneficial).arrow_forwardThis program is going to maintain a list of customers’ names and bank account balances. 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 2. Print each name in the ArrayList using a for loop. 3. 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. 4. 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. For example, the program should print out this for the first customer: Please enter the account balance for Cathy: (waiting for user’s input …) Code skeleton: for(int i=0; i<5;i++) { Print(“Please enter…arrow_forward
- Part #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_forwardWrite the source code of enum CrewType.arrow_forwardWrite code for a test class with the following details:1. Create an object of each class mentioned in Question 3, assuming the values for the data members of each class. Create an array that takes the objects of ALL the classes as its elements. Write an enhanced for loop to display the object details. 2. the dealer in Question 4 decides to offer 2% percent discount on the commission at runtime. Write codewith explanation. 3. Add code to the test class that writes the invoice details of Question 6 to a txt document Syntax of the q3 code is given below: import java.util.*; class Car{ //class car String[] name; int reg_number,eng_number, chassis_num,status; String[] city, model, color, date_reg,date_arr,type; float price; float abstract calculate (float price); } class Dealer extends Car{ //inherits from Car String[] deal_name, deal_id, deal_add, deal_pno; float dealer_com ; float abstract calculate (float price) { dealer_com= 0.01*price +…arrow_forward
- 1. Declare a (local) variable of type Person, create a new Object and assign the variable to this object. 2. Declare an ArrayList variable which can hold objects of type Person 3. Create a new ArrayList with objects of type Person and assign it to the existing variable persons.arrow_forward1. Declare an array to save 4 Dog objects. The Dog class is provided below. Look into the Dog class and find what attributes are needed for a dog object. Then initialize five dogs with the following information: Lily, 5 years old Jacob, 2 years old Sugar, 8 years old Bush, 3 years old 2. Print out every dog using a for loop (use either regular for loop or for-each loop, your choice). But you may find when you print out, the name and age are not displayed. Why? 3. Fix this problem by implementing the toString method in the Dog class. Dog Class: public class Dog { private String name; private int age; public Dog(String name, int age) { this.name = name; this.age = age; } public void setName(String name) { this.name = name; } }arrow_forwardWritten in Python with docstring please if applicable Thank youarrow_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