Question: I need the Java code for the following: Implement a Java class using the following UML diagram. Be sure to use the correct access specifiers
I need the Java code for the following:
Implement a Java class using the following UML diagram. Be sure to use the correct access specifiers for the class, instance variables and methods. Mutators and accessors must be implemented in your class as specified in the UML diagram. The createList method is a static method, as indicated by the underlined signature. This method takes two parallel arrays; one array contains the food name and the other the food price. It declares an ArrayList containing FoodPrice Objects, creates FoodPrice objects out of each parallel array element, then inserts each FoodPrice object into an ArrayList. The ArrayList is returned to the caller.
To declare an ArrayList named "fp" which stores FoodPrice objects, use the following:
ArrayList
To add FoodPrice objects the the ArrayList fp using the 2-argument constructor shown in the UML diagram, use the following:
fp.add(new FoodPrice(items[i], prices[i]));
Use the following main method in your class to test it (don't modify this code)
// Main method for unit test public static void main(String[] args) { final String[] food = { "Tomatoes", "Ground Beef", "Pasta", "Bread", "Cheese" }; final double[] prices = { 1.99, 5.49, 0.99, 2.57, 3.59 }; System.out.println("Original list: "); ArrayList
Expected output:
Original list: Item: Tomatoes, Price: $1.99 Item: Ground Beef, Price: $5.49 Item: Pasta, Price: $0.99 Item: Bread, Price: $2.57 Item: Cheese, Price: $3.59 New List: Item: Tomatoes, Price: $1.99 Item: Ground Beef, Price: $5.49 Item: Pasta, Price: $0.99 Item: Bread, Price: $2.57 Item: American Cheese, Price: $4.59
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
