+ 2

Pls help me

Product =Sabon, Shampoo, Bulad, Noodles, Pan, Sardinas Price =21.50, 5.75, 15, 12, 10, 17.50 Enter Product Name: bulad Qty: 2 Amount: 30 //display Cash tendered: 20 Change: 20 //display Enter Product Name: Burger Product Not Found!

25th Sep 2021, 8:27 AM
Angel Mae Albo
Angel Mae Albo - avatar
3 odpowiedzi
+ 1
import java.util.*; public class Program { public static void main(String[] args) { HashMap<String,Double> map = new HashMap<>(); map.put("Sabon",21.50); map.put("Shampoo",5.75); map.put("Bulad",15.0); map.put("Noodles",12.0); map.put("Pan",10.0); map.put("Sardinas",17.50); Scanner sc = new Scanner(System.in); String name = sc.next(); int qty = sc.nextInt(); if(map.get(name) == null){ System.out.println("Product Not Found!"); }else{ double total = map.get(name) * qty; System.out.println("you will have to pay: "+total); } } } /*adding cash tendered would be a bad idea to do this here in sololearn since the entry is made only at the beginning*/
25th Sep 2021, 9:19 AM
Erlénio.RS
Erlénio.RS - avatar
+ 2
Another way to Erlénio.RS presented HashMap, is build own data type. You can see it here: https://code.sololearn.com/cPCn2QFFcZ3e/?ref=app
26th Sep 2021, 7:28 AM
JaScript
JaScript - avatar
+ 1
Angel Mae Albo You have completed 1% of the Java tutorial. Why don't you continue with the course and learn the syntax for this question
25th Sep 2021, 9:19 AM
Rik Wittkopp
Rik Wittkopp - avatar