1. (Display words in descending alphabetical order) Write a program utilizing list implementations that prompts the user to enter two lines of words. The words are separated by spaces. Extract the words from the two lines into two lists. Display the union, difference, and intersection of the two lists in descending alphabetical order. Here is a sample run: Enter the first line: red green blue yellow purple cyan orange Enter the second line: red black brown cyan orange pink The union is [yellow, red, red, purple, pink, orange, orange, green, cyan, cyan, brown, blue, black] The difference is [yellow, purple, green, blue] The intersection is [red, orange, cyan]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JAVA please

**Interactive Programming Exercise: Working with Lists**

**Exercise Objective: Display Words in Descending Alphabetical Order**

In this exercise, we will write a program that utilizes list implementations to prompt the user to enter two lines of words. The words are separated by spaces. The program will extract the words from each line into two separate lists and then display the union, difference, and intersection of these lists in descending alphabetical order. Below is a sample run of the program:

---

**Sample Run:**

**Instructions:**
1. Enter the first line: `red green blue yellow purple cyan orange`
2. Enter the second line: `red black brown cyan orange pink`

**Results:**
- **The union is**: `[yellow, red, red, purple, pink, orange, orange, green, cyan, cyan, brown, blue, black]`
- **The difference is**: `[yellow, purple, green, blue]`
- **The intersection is**: `[red, orange, cyan]`

---

**Explanation of Results:**

1. **Union**: The union of two lists includes all the elements from both lists without duplicates. In this example, the union list `[yellow, red, red, purple, pink, orange, orange, green, cyan, cyan, brown, blue, black]` includes all unique words from both lists.
  
2. **Difference**: The difference between two lists (first list - second list) includes elements that are present in the first list but not in the second list. Here, the difference list `[yellow, purple, green, blue]` contains words from the first list that are not present in the second list.

3. **Intersection**: The intersection of two lists includes only the elements that are present in both lists. In this example, the intersection list `[red, orange, cyan]` includes words that can be found in both the first and the second list.

---

This exercise provides a practical application for understanding how to manipulate and compare lists in Python, reinforcing key concepts such as list operations and set theory.
Transcribed Image Text:**Interactive Programming Exercise: Working with Lists** **Exercise Objective: Display Words in Descending Alphabetical Order** In this exercise, we will write a program that utilizes list implementations to prompt the user to enter two lines of words. The words are separated by spaces. The program will extract the words from each line into two separate lists and then display the union, difference, and intersection of these lists in descending alphabetical order. Below is a sample run of the program: --- **Sample Run:** **Instructions:** 1. Enter the first line: `red green blue yellow purple cyan orange` 2. Enter the second line: `red black brown cyan orange pink` **Results:** - **The union is**: `[yellow, red, red, purple, pink, orange, orange, green, cyan, cyan, brown, blue, black]` - **The difference is**: `[yellow, purple, green, blue]` - **The intersection is**: `[red, orange, cyan]` --- **Explanation of Results:** 1. **Union**: The union of two lists includes all the elements from both lists without duplicates. In this example, the union list `[yellow, red, red, purple, pink, orange, orange, green, cyan, cyan, brown, blue, black]` includes all unique words from both lists. 2. **Difference**: The difference between two lists (first list - second list) includes elements that are present in the first list but not in the second list. Here, the difference list `[yellow, purple, green, blue]` contains words from the first list that are not present in the second list. 3. **Intersection**: The intersection of two lists includes only the elements that are present in both lists. In this example, the intersection list `[red, orange, cyan]` includes words that can be found in both the first and the second list. --- This exercise provides a practical application for understanding how to manipulate and compare lists in Python, reinforcing key concepts such as list operations and set theory.
Expert Solution
steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education