public List<GroceryItem> calculateInvoice(List<GroceryItem> purchasedItems, Map<String, Double> prices, Map<String, Double> discounts) {
List<GroceryItem> invoiceItems = new ArrayList<>();
for (GroceryItem purchasedItem : purchasedItems) {
String itemName = purchasedItem.getItemName();
int quantity = purchasedItem.getQuantity();
// Calculate the total price for the item, including the discount.
double price = prices.get(itemName);
double discount = discounts.getOrDefault(itemName, 0.0);
double totalPrice = price * quantity - discount * quantity;
// Create a new GroceryItem object for the invoice.
GroceryItem invoiceItem = new GroceryItem(itemName, quantity, price, totalPrice);
invoiceItems.add(invoiceItem);
}
// Sort the invoice items in ascending order by product name.
invoiceItems.sort(Comparator.comparing(GroceryItem::getItemName));
return invoiceItems;
}
List<GroceryItem> invoiceItems = new ArrayList<>();
for (GroceryItem purchasedItem : purchasedItems) {
String itemName = purchasedItem.getItemName();
int quantity = purchasedItem.getQuantity();
// Calculate the total price for the item, including the discount.
double price = prices.get(itemName);
double discount = discounts.getOrDefault(itemName, 0.0);
double totalPrice = price * quantity - discount * quantity;
// Create a new GroceryItem object for the invoice.
GroceryItem invoiceItem = new GroceryItem(itemName, quantity, price, totalPrice);
invoiceItems.add(invoiceItem);
}
// Sort the invoice items in ascending order by product name.
invoiceItems.sort(Comparator.comparing(GroceryItem::getItemName));
return invoiceItems;
}
👍2🔥1
This media is not supported in your browser
VIEW IN TELEGRAM
Share our channel screenshot in large groups ✅✅✅✅✅
For coding answers & Sql 🏃🏃🏃🏃
For coding answers & Sql 🏃🏃🏃🏃
👍2
SELECT c.title AS category_title, p.title, SUM(p.stock_number) AS total_stock
FROM categories c
JOIN products p ON c.id = p.category_id
GROUP BY c.title, p.title
HAVING SUM(p.stock_number) > 10
ORDER BY category_title ASC, p.title ASC, total_stock
E commerce website
Share @coding_000✅
FROM categories c
JOIN products p ON c.id = p.category_id
GROUP BY c.title, p.title
HAVING SUM(p.stock_number) > 10
ORDER BY category_title ASC, p.title ASC, total_stock
E commerce website
Share @coding_000✅
👍3
SELECT
A.email AS "email account",
COUNT(O.account_id) AS "outputs",
SUM(LENGTH(O.output) - LENGTH(REPLACE(O.output, ' ', '')) + 1) AS "total words",
ROUND(SUM(LENGTH(O.output) - LENGTH(REPLACE(O.output, ' ', '')) + 1) / COUNT(O.account_id), 2) AS "avg words per output"
FROM accounts A
LEFT JOIN results O ON A.id = O.account_id
GROUP BY A.email
ORDER BY A.email ASC;
A.email AS "email account",
COUNT(O.account_id) AS "outputs",
SUM(LENGTH(O.output) - LENGTH(REPLACE(O.output, ' ', '')) + 1) AS "total words",
ROUND(SUM(LENGTH(O.output) - LENGTH(REPLACE(O.output, ' ', '')) + 1) / COUNT(O.account_id), 2) AS "avg words per output"
FROM accounts A
LEFT JOIN results O ON A.id = O.account_id
GROUP BY A.email
ORDER BY A.email ASC;
👍2
NoBody sharing 😢😕
Our channel @Coding_000❤️
Our channel @Coding_000❤️
❤5
SELECT
categories.title AS category,
products.title,
products.stock_number AS total_stock
FROM
products
INNER JOIN categories ON products.category_id = categories.id
WHERE
products.stock_number > 10
ORDER BY
category ASC,
products.title ASC,
total_stock DESC;
categories.title AS category,
products.title,
products.stock_number AS total_stock
FROM
products
INNER JOIN categories ON products.category_id = categories.id
WHERE
products.stock_number > 10
ORDER BY
category ASC,
products.title ASC,
total_stock DESC;
🔥3❤1
Share our channel screenshot in large groups ✅✅✅✅✅
For coding answers & Sql 🏃🏃🏃🏃
For coding answers & Sql 🏃🏃🏃🏃
👍7
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Jobs' AS source,
COUNT(*) AS total_number
FROM
jobs
GROUP BY
month_year
UNION ALL
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Freelancers' AS source,
COUNT(*) AS total_number
FROM
freelancers
GROUP BY
month_year
ORDER BY
month_year ASC,
source ASC;
Freelancer code✅ @coding_000❤️
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Jobs' AS source,
COUNT(*) AS total_number
FROM
jobs
GROUP BY
month_year
UNION ALL
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Freelancers' AS source,
COUNT(*) AS total_number
FROM
freelancers
GROUP BY
month_year
ORDER BY
month_year ASC,
source ASC;
Freelancer code✅ @coding_000❤️
👍6
Give reactions...check mark/type it carefully..✅
Share our channel..to get more ans..😅✅
Share our channel..to get more ans..😅✅
❤3🔥1
Q - E-commerce website admin
SELECT c.title AS category_title, p.title, SUM(p.stock_number) AS total_stock
FROM categories c
JOIN products p ON c.id = p.category_id
GROUP BY c.title, p.title
HAVING SUM(p.stock_number) > 10
ORDER BY category_title ASC, p.title ASC, total_stock DESC;
SELECT c.title AS category_title, p.title, SUM(p.stock_number) AS total_stock
FROM categories c
JOIN products p ON c.id = p.category_id
GROUP BY c.title, p.title
HAVING SUM(p.stock_number) > 10
ORDER BY category_title ASC, p.title ASC, total_stock DESC;
🔥3
This media is not supported in your browser
VIEW IN TELEGRAM
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Jobs' AS source,
COUNT(*) AS total_number
FROM
jobs
GROUP BY
month_year
UNION ALL
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Freelancers' AS source,
COUNT(*) AS total_number
FROM
freelancers
GROUP BY
month_year
ORDER BY
month_year ASC,
source ASC;
✅✅ share @coding_000✅
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Jobs' AS source,
COUNT(*) AS total_number
FROM
jobs
GROUP BY
month_year
UNION ALL
SELECT
DATE_FORMAT(date_field, '%Y-%m') AS month_year,
'Freelancers' AS source,
COUNT(*) AS total_number
FROM
freelancers
GROUP BY
month_year
ORDER BY
month_year ASC,
source ASC;
✅✅ share @coding_000✅
👍3🔥1🥰1