Last active
June 25, 2019 21:59
-
-
Save celiosouza2013/f17c539db2287945630fe3da680c0f1f to your computer and use it in GitHub Desktop.
Cadastro de Produtos
This file contains 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
//Criando Classe | |
using System.Globalization; | |
namespace Course | |
{ | |
class Produto | |
{ | |
public string Nome; | |
public double Preco; | |
public int Quantidade; | |
public double ValorTotalEmEstoque() | |
{ | |
return Preco * Quantidade; | |
} | |
public void AdicionarProdutos(int quantidade) | |
{ | |
Quantidade += quantidade; | |
} | |
public void RemoverProdutos(int quantidade) | |
{ | |
Quantidade -= quantidade; | |
} | |
public override string ToString() | |
{ | |
return Nome | |
+ ", $ " | |
+ Preco.ToString("F2", CultureInfo.InvariantCulture) | |
+ ", " | |
+ Quantidade | |
+ " unidades, Total: $ " | |
+ ValorTotalEmEstoque().ToString("F2", CultureInfo.InvariantCulture); | |
} | |
} | |
} | |
//________________________________________ | |
using System; | |
using System.Globalization; | |
namespace Course | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Produto p = new Produto(); | |
Console.WriteLine("Entre os dados do produto:"); | |
Console.Write("Nome: "); | |
p.Nome = Console.ReadLine(); | |
Console.Write("Preço: "); | |
p.Preco = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
Console.Write("Quantidade no estoque: "); | |
p.Quantidade = int.Parse(Console.ReadLine()); | |
Console.WriteLine(); | |
Console.WriteLine("Dados do produto: " + p); | |
Console.WriteLine(); | |
Console.Write("Digite o número de produtos a ser adicionado ao estoque: "); | |
int qte = int.Parse(Console.ReadLine()); | |
p.AdicionarProdutos(qte); | |
Console.WriteLine(); | |
Console.WriteLine("Dados atualizados: " + p); | |
Console.WriteLine(); | |
Console.Write("Digite o número de produtos a ser removido do estoque: "); | |
qte = int.Parse(Console.ReadLine()); | |
p.RemoverProdutos(qte); | |
Console.WriteLine(); | |
Console.WriteLine("Dados atualizados: " + p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment