Create SoftDrink objects and store them in an ArrayList (see the Appendix) as each softdrink is entered.  • Alternatively, you can use an array. Take a number of items first, create an array of that size and read in the elements.  • Prompt the user to add a softdrink until they choose to quit.  • Once the user quits, print out a list of the softdrinks that the user has entered, sorted first by alphabetical order of name, then by colour, then by volume (ascending order). Name your driver class Question2.java.  NOTE:  • You can use the built-in static sort() method in the java.util.Collections class to sort your ArrayList of SoftDrink objects.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Write code that will accept as input the characteristics of an undefined number of different softdrinks. Each softdrink should have a colour (of the can), name and volume. 

• Create SoftDrink objects and store them in an ArrayList (see the Appendix) as each softdrink is entered. 

• Alternatively, you can use an array. Take a number of items first, create an array of that size and read in the elements. 

• Prompt the user to add a softdrink until they choose to quit. 

• Once the user quits, print out a list of the softdrinks that the user has entered, sorted first by alphabetical order of name, then by colour, then by volume (ascending order). Name your driver class Question2.java. 

NOTE: 

• You can use the built-in static sort() method in the java.util.Collections class to sort your ArrayList of SoftDrink objects. 

 

Sample I/O 

Enter option: (1) add soft drink (2) quit: 

Enter name, colour and volume in ml separated by space 

Fanta Orange 500 

Enter option: (1) add soft drink (2) quit: 

Enter name, colour and volume in ml separated by space

Fanta Orange 200 

Enter option: (1) add soft drink (2) quit: 

Enter name, colour and volume in ml separated by space 

Coke Red 500 

Enter option: (1) add soft drink (2) quit: 

Enter name, colour and volume in ml separated by space 

Coke Silver 500 

Enter option: (1) add soft drink (2) quit: 

Coke Red 500 

Coke Silver 500 

Fanta Orange 300 

Fanta Orange 500

Expert Solution
steps

Step by step

Solved in 2 steps with 1 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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage