Last active
October 1, 2020 14:47
-
-
Save peagape/65cb2c6827d883ea5e3bf8a0c184f9d3 to your computer and use it in GitHub Desktop.
carrinho_compras.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:io'; | |
| List<String> produtos = []; | |
| main() { | |
| bool codicao = true; | |
| while(codicao){ | |
| //print("\x1B[2J\x1B[0;0H"); | |
| stdout.writeln('======== ADD PRODUTO:'); | |
| String text = stdin.readLineSync(); | |
| //SAI DO SOFTWARE | |
| if(text == "sair"){ | |
| sair(); | |
| codicao = false; | |
| //REMOVE PRODUTOS CADASTRADOS | |
| }else if(text == "remover"){ | |
| remover(); | |
| //LISTA OS PRODUTOS ADICIONADOS | |
| }else if(text == "listar"){ | |
| imprimir(); | |
| //ADD PRODUTO AO SISTEMA | |
| }else{ | |
| produtos.add(text); | |
| print("\x1B[2J\x1B[0;0H"); //LIMPA O TERMINAL | |
| //print(produtos); | |
| } | |
| } | |
| } | |
| imprimir() { | |
| if(produtos.length <= 0){ | |
| print("=== Você ainda não tem nenhum produto cadastrado! ==="); | |
| }else{ | |
| for (var i = 0; i < produtos.length; i++) { | |
| print("ITEM ID: $i - ${produtos[i]}"); | |
| } | |
| } | |
| } | |
| remover(){ | |
| //Mostra os produtos e ID para escolher qual deseja remover | |
| for (var i = 0; i < produtos.length; i++) { | |
| print("ITEM ID: $i - ${produtos[i]}"); | |
| } | |
| //Fim for Mostra produtos | |
| stdout.writeln('======== Digite o ID do produto que deseja remover:'); | |
| //PARSE = Conversao da string da Int | |
| int removeIT = int.parse(stdin.readLineSync()); | |
| produtos.removeAt(removeIT); | |
| print("produto removido com sucesso! \n"); | |
| //MOSTRA OS PRODUTOS DPS DE REMOVIDOS | |
| for (var i = 0; i < produtos.length; i++) { | |
| print("ITEM ID: $i - ${produtos[i]}"); | |
| } | |
| } | |
| sair(){ | |
| print("\x1B[2J\x1B[0;0H"); | |
| print("=== Você saiu do software, até mais! ==="); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@peagape, ficou top! parabéns!