Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a class named \"Lab\" write a public static method named \"computeProfit\" th

ID: 3729890 • Letter: I

Question

In a class named "Lab" write a public static method named "computeProfit" that takes three parameters and returns a double. The first parameter is a HasMap representing the selling price of each item in our store that we have been using throughout this lab. The second parameter is a HashMap but this one represent our cost for us to purchase each type of item for our inventory. the third parameter is an ArrayList representing all the orders that have been made in a day. the is an ArrayList where each element is a HashMap representing a customer’s cart in the same format as the previous part. this method compute and return our total profit for this day. both that the profit of selling an item is the cost to the customer (prices in the first parameter) minus our cost to purchase the item for our inventory (second parameter). in all computation, use the following prices. Selling prices:{eggs = 1.79, orange = 2.5, yogurt = 1.99, bread = 2.49, butter = 2.39, peppers = 1.49} Purchase prices:{eggs = 1.2, orange =1.0, yogurt = 1.0, bread = 1.15, butter = 1.95, peppers = 0.99}

Explanation / Answer

package com.vinoth.chegg2702;
import java.util.arraylist;
import java.util.hashmap;
import java.util.iterator;
import java.util.list;
public class lab {
public static double computeprofit(hashmap sellingprice, hashmap purchaseprice, list lstcart) {
double profit = 0;
iterator it = lstcart.iterator();
while (it.hasnext()) {
string item = it.next();
if (sellingprice.containskey(item) && purchaseprice.containskey(item)) {
profit += sellingprice.get(item) - purchaseprice.get(item);
}
}
return profit;
}
public static void main(string[] args) {
ashmap sellingprice = new hashmap();
hashmap purchaseprice = new hashmap();
list cart = new arraylist();
sellingprice.put("eggs", 1.79);
sellingprice.put("orange", 2.5);
sellingprice.put("yogurt", 1.99);
sellingprice.put("bread", 2.49);
sellingprice.put("butter", 2.39);
sellingprice.put("peppers", 1.49);
purchaseprice.put("eggs", 1.2);
purchaseprice.put("orange", 1.0);
purchaseprice.put("yogurt", 1.0);
purchaseprice.put("bread", 1.15);
purchaseprice.put("butter", 1.95);
purchaseprice.put("peppers", 0.99);
cart.add("eggs");
cart.add("eggs");
cart.add("eggs");
cart.add("eggs");
cart.add("eggs");
cart.add("orange");
cart.add("orange");
cart.add("orange");
cart.add("orange");
cart.add("peppers");
cart.add("peppers");
cart.add("peppers");
cart.add("peppers");
cart.add("bread");
cart.add("bread");
cart.add("bread");
cart.add("bread");
cart.add("bread");
system.out.println("total profit: " + computeprofit(sellingprice, purchaseprice, cart));
}
}

Output

Total Profit : 17.65