Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Exercicio2
- {
- public class Investimento
- {
- public string NomeTitular { get; set; }
- public int Tipo { get; set; }
- private float valorInicial;
- private float rendimento;
- private float valorLiquido;
- private Investimento[] carteira = new Investimento[0];
- public Investimento()
- {
- this.NomeTitular = "";
- this.Tipo = 0;
- this.valorInicial = 0;
- }
- public Investimento(string titular, int tipo, float valorInicial)
- {
- this.NomeTitular = titular;
- this.Tipo = tipo;
- this.valorInicial = valorInicial;
- }
- public void AddInvestimento(Investimento inv)
- {
- Investimento[] clone = new Investimento[this.carteira.Length];
- for (int i = 0; i < clone.Length; i++)
- {
- clone[i] = carteira[i];
- }
- this.carteira = new Investimento[this.carteira.Length + 1];
- for (int i = 0; i < clone.Length; i++)
- {
- carteira[i] = clone[i];
- }
- this.carteira[this.carteira.Length - 1] = inv;
- }
- public float Rendimento()
- {
- float j = this.Tipo == 1 ? 0.055f :
- this.Tipo == 2 ? 0.064f :
- this.Tipo == 3 ? 0.089f :
- this.Tipo == 4 ? 0.032f : 0;
- this.rendimento = this.valorInicial + (this.valorInicial * j);
- return rendimento;
- }
- public float ValorLiquido()
- {
- float j = this.Tipo == 1 ? 0f : //0%
- this.Tipo == 2 ? 0.25f : //25%
- this.Tipo == 3 ? 0.15f : //15%
- this.Tipo == 4 ? 0.2f : 0; //20%
- this.valorLiquido = (this.rendimento + this.valorInicial) - (this.rendimento * j);
- return valorLiquido;
- }
- public void ImprimirInvestimentos()
- {
- Console.WriteLine("Investimentos");
- for (int i = 0; i < carteira.Length; i++)
- {
- Console.WriteLine(
- "\n Tipo:{0} ValorInicial:{1} ValorLiquido:{2} Rendimento:{3}"
- , carteira[i].Tipo, carteira[i].valorInicial, carteira[i].ValorLiquido(), carteira[i].Rendimento());
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public Investimento Maislucrativo()
- {
- Investimento temp;
- for (int i = 0; i < this.carteira.Length ; i++)
- {
- for (int y = 0; y < this.carteira.Length; y++)
- {
- if (carteira[i].Rendimento() > carteira[y].Rendimento())
- {
- temp = carteira[i];
- }
- }
- }
- return temp;
- }
- public static void InvestimentoMaisLucrativoDeTodos()
- {
- Titular[] t = Exercicio2.Titular.Titulares;
- for (int i = 0; i < t.Length; i++)
- {
- Console.WriteLine("Investidor {0} ", t[i].);
- t[i].Investimentos.ImprimirInvestimentos();
- }
- }
- private static void compare()
- {
- }
- public static void TodosOsInvestimentos()
- {
- Titular[] t = Exercicio2.Titular.Titulares;
- for (int i = 0; i < t.Length; i++)
- {
- Console.WriteLine("Investidor {0} ",t[i].Nome);
- t[i].Investimentos.ImprimirInvestimentos();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment