Shopping Cart


Submit solution

Points: 10
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C#, Go, Java

Crea les classes necessàries.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;


// escriu el codi aqui

public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        ShoppingCart shoppingCart = new ShoppingCart();

        int nProducts = scanner.nextInt();
        scanner.nextLine();

        shoppingCart.products = new Product[nProducts];

        for (int i = 0; i < nProducts; i++) {
            shoppingCart.products[i] = new Product();
            shoppingCart.products[i].name = scanner.nextLine();
            shoppingCart.products[i].price = scanner.nextFloat();
            scanner.nextLine();
        }

        System.out.println("ShoppingCart");
        for (int i = 0; i < nProducts; i++) {
            System.out.format("%40s  %6.2f%n", shoppingCart.products[i].name, shoppingCart.products[i].price);
        }
    }
}

Input Format

-

Constraints

-

Output Format

-

Sample Input 0

4
FREKVENS Altavoz, 10x20 cm
59
SYMFONISK Altavoz wifi, 31x10x15 cm
105.9
ENEBY Altavoz Bluetooth, 20x20 cm
49.99
ENEBY Altavoz Bluetooth, 30x30 cm
89.99

Sample Output 0

ShoppingCart
              FREKVENS Altavoz, 10x20 cm   59.00
     SYMFONISK Altavoz wifi, 31x10x15 cm  105.90
       ENEBY Altavoz Bluetooth, 20x20 cm   49.99
       ENEBY Altavoz Bluetooth, 30x30 cm   89.99

Sample Input 1

2
LILLHULT MiniUSB cable, 0.4 m
2.25
LILLHULT USB tipo C cable, 1.5 m
4.45

Sample Output 1

ShoppingCart
           LILLHULT MiniUSB cable, 0.4 m    2.25
        LILLHULT USB tipo C cable, 1.5 m    4.45

Autoria: Gerard Falcó


Authorship: Gerard Falcó

CC BY-NC-SA 4.0