Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 20.8, Problem 20.8.2CP
Explanation of Solution
The following modification of the code is to remove the ball when “-”button is clicked.
//Define the method subtract()
public void subtract() {
//Check whether the list is greater than 0
if (list.size() > 0)
// Remove the last ball
list.remove(list.size() - 1);
}
Explanation:
- The “MultipleBallApp...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code
provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only
even ints.
You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll
need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator.
1 def only_evens (1st: list[list[int]]) -> list[list[int]]:
"""Return a list of the lists in 1st that contain only even integers.
4
>>> only_evens ([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]])
[[4, 0, 6], [2]]
6.
8.
even_lists =
[]
10
for sublist in 1st:
11
12
# write your code here (please read above for a suggested approach)
13
14
return even_lists
This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code
provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only
even ints.
You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll
need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator.
1 def only evens (1st: list[list[int]]) -> list[list[int]]:
**"Return a list of the lists in 1st that contain only even integers.
2.
3.
>>> only_evens ([[1, 2, 4], [4, e, 6], [22, 4, 3], [2]])
4.
[[4, e, 6], [2]]
8.
even_lists = []
10
for sublist in 1st:
11
12
13
14
return even_lists
History
Submit
P Type here to search
100%
1:1
8°C Cloudy
A 4) ENG
10/2
In Java please.
Add comments as well. Thank you!
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
Knowledge Booster
Similar questions
- Q.Create an interesting educational information chat box that asks the user to give an input question and then answers the question given by user with a suitable answer. You can make use of list for different questions and answers.Save two to three answers for a single question and then for random selection of elements from those answers use random choice(list) method from random module that returns a random element. Also for a user question that doesn't matches with the questions present in the chat box it should display statement like "oops i can't answer that" "sorry i am not intelligent enough" "could u please ask something else" using random method so that every time one of these statements appear **coding language python ***try using basic programming techniques in python without using arrays and pointers * * * copy paste the program itself and also the screenshot of program and output * * * use any type of data for questions such as name details of cities species etc depends on…arrow_forwardWhat happens when you add two entries to a map with the same value and two different keys?arrow_forwardCreate 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 a void 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.arrow_forward
- What happens when you remove the entry from position 4 from a List? Select one: a. All of these b. The entry in the 4th position is returned (if there was a 4th entry) c. If the List has 3 or fewer entries, an IndexOutOfBoundsException is thrown d. If the List has 5 or more entries, the entries in positions 5 and up will move up 1 spot earlier to close up the gap vacated by removing the 4th entryarrow_forwardWrite out the header of a for-each loop to process an ArrayList called tracks. Don’t worry about the loop’s body.arrow_forwardcan you please do this in java eclipse idearrow_forward
- Your task is to take the list from the user and then print all the elements which appeared at even position without using any external loops. Programming language: Pythonarrow_forwardThe code below prompts the user to enter their full name, and then converts the name to a list. Complete the code to output the person's initials. For example, if the user enters 'Adam Jones', then your code will output 'AJ'. If the user enters 'Adam Daniel Jones', then your code will output 'ADJ'. name = input('Enter your full name: ')nameList = name.split()nameListarrow_forwardWhat happens when you add an entry into position 4 into a List? Select one: a. If the List has 4 or more entries, entries in positions 4 and up will move over 1 spot to make room for the new entry to be added to position 4 b. All of these c. If the List has 2 or fewer entries, an IndexOutOfBoundsExecption is thrown d. If the List has exactly 3 entries, the new entry will be added to the end of the Listarrow_forward
- Build two different lists, one with bullet points and one with numbers.arrow_forwardCreate an array of three string values that the fullName variable will use as a point of reference. Make an initialization list for the array using string values for the first, middle, and last names.arrow_forwardPYTHON: For remote access, it’s often better to use a Command Line Interface (CLI), rather than a Graphical User Interface (GUI). A CLI does not use a mouse. However, a program can interact with the user via a menu driven interface. In this assignment, you will implement a menu driven interface for maintaining a list of guests. You will also validate user input to make sure that the name entered is not already in the list. Since some of the objectives of this assignment include demonstrating your proficiency with for loops, lists and the 'in' operator, please be sure to do the following: use the list sort() method to sort your list use a for loop to display each element in the list be sure to create the list with three items already in it use the title() string method for title capitalization Not that all of the bullet items above are included in the Week 4 Exercises, including Supplemental Exercise 4, which is not in the book but is in this week's Canvas module. Your program should…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage