Created
June 27, 2019 16:55
-
-
Save celiosouza2013/4b2da2184bb52a756d2a2c6ba902b5da to your computer and use it in GitHub Desktop.
Cadastro de Produtos - Aplicando conceito de Construtores
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
using System.Globalization; | |
namespace Course | |
{ | |
class Produto | |
{ | |
public string Nome; | |
public double Preco; | |
public int Quantidade; | |
public Produto(string nome, double preco, int quantidade) | |
{ | |
Nome = nome; | |
Preco = preco; | |
Quantidade = 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) | |
{ | |
Console.WriteLine("Entre os dados do produto:"); | |
Console.Write("Nome: "); | |
string nome = Console.ReadLine(); | |
Console.Write("Preço: "); | |
double preco = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); | |
Console.Write("Quantidade no estoque: "); | |
int quantidade = int.Parse(Console.ReadLine()); | |
Produto p = new Produto(nome, preco, quantidade); | |
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