Kotlinlearncs.online LogoJava
Return to List

Solve: Calculate Grocery Bill

Created By: Pranav Narayanan
/ Version: 2024.9.1

Write a method groceryBill that takes a String input of a grocery bill and returns the subtotal. Each new item is on a new line, and each line will be in CSV format:

item(String), quantity(int), price(double)
"Apples", 3, 2.00

This one line would have a total of 3 * 2.00 = 6.00. There will be a variable amount of whitespace surrounding the values. You should assert that the passed string is non-null, but otherwise you can assume that the it follows this format (it may be empty however).

You will need the Integer.parseInt() and Double.parseDouble() methods to turn a String into a int/double value.

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/java/calculate-grocery-bill/[email protected]