Use a HashMap to create a reusable class for choosing one of

Use a HashMap to create a reusable class for choosing one of the 13 predefined colors in class Color. The names of the colors will be used as keys, and the predefined Color objects will be used as values. Place this class in a package that can be imported into any Java program. Use your new class in a GUI application that allows the user to select one of the colors from a JList. The JList should receive its values from the HashMap programmatically. When the user clicks a button, the application must change the background color of a JPanel to the currently selected color in the JList.

Exercise 2

Create an Invoice class with 4 attributes: PartNumber (type int), PartDescription (type String), Quantity (type int), and Price (type double).

Create a constructor that allows you to initialize all 4 attributes from values passed in as parameters.

Override the toString() method to display all 4 attributes in a format of your choosing.

Create a List of 10 Invoices containing data of your choosing.

Use lambdas and streams to perform the following queries on the list of Invoice objects and display the results:

Sort the Invoice objects by PartDescription, then display the results.

Sort the Invoice objects by Price, then display the results.

Map each Invoice to its PartDescription and Quantity, sort the results by Quantity, then display the results.

Map each Invoice to its PartDescription and the value of the Invoice (i.e., Quantity * Price). Order the results by Invoice value.

Modify Part (d) above to select the Invoice values in the range of $200 to $500 (inclusive) and display the results separately.

Solution

Exercise 1:

Exercise 2:

// Invoice Generator

// Invoice Handler

Use a HashMap to create a reusable class for choosing one of the 13 predefined colors in class Color. The names of the colors will be used as keys, and the pred

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site