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.
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:
1
Enter name, colour and volume in ml separated by space
Fanta Orange 500
Enter option: (1) add soft drink (2) quit:
1
Enter name, colour and volume in ml separated by space
Fanta Orange 200
Enter option: (1) add soft drink (2) quit:
1
Enter name, colour and volume in ml separated by space
Coke Red 500
Enter option: (1) add soft drink (2) quit:
1
Enter name, colour and volume in ml separated by space
Coke Silver 500
Enter option: (1) add soft drink (2) quit:
2
Coke Red 500
Coke Silver 500
Fanta Orange 300
Fanta Orange 500
Step by step
Solved in 2 steps with 1 images