Guest User

Untitled

a guest
Oct 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Exercicio2
  7. {
  8.     public class Investimento
  9.     {
  10.         public string NomeTitular { get; set; }
  11.         public int Tipo { get; set; }
  12.  
  13.         private float valorInicial;
  14.         private float rendimento;
  15.         private float valorLiquido;
  16.  
  17.         private Investimento[] carteira = new Investimento[0];
  18.  
  19.         public Investimento()
  20.         {
  21.             this.NomeTitular = "";
  22.             this.Tipo = 0;
  23.             this.valorInicial = 0;
  24.         }
  25.         public Investimento(string titular, int tipo, float valorInicial)
  26.         {
  27.             this.NomeTitular = titular;
  28.             this.Tipo = tipo;
  29.             this.valorInicial = valorInicial;
  30.         }
  31.  
  32.  
  33.         public void AddInvestimento(Investimento inv)
  34.         {
  35.            
  36.                 Investimento[] clone = new Investimento[this.carteira.Length];
  37.                 for (int i = 0; i < clone.Length; i++)
  38.                 {
  39.                     clone[i] = carteira[i];
  40.                 }
  41.  
  42.                 this.carteira = new Investimento[this.carteira.Length + 1];
  43.  
  44.                 for (int i = 0; i < clone.Length; i++)
  45.                 {
  46.                     carteira[i] = clone[i];
  47.                 }
  48.            
  49.             this.carteira[this.carteira.Length - 1] = inv;
  50.         }
  51.  
  52.         public float Rendimento()
  53.         {
  54.             float j = this.Tipo == 1 ? 0.055f :
  55.                 this.Tipo == 2 ? 0.064f :
  56.                 this.Tipo == 3 ? 0.089f :
  57.                 this.Tipo == 4 ? 0.032f : 0;
  58.  
  59.             this.rendimento = this.valorInicial + (this.valorInicial * j);
  60.  
  61.             return rendimento;
  62.         }
  63.  
  64.         public float ValorLiquido()
  65.         {
  66.             float j = this.Tipo == 1 ? 0f :    //0%
  67.                       this.Tipo == 2 ? 0.25f :    //25%
  68.                       this.Tipo == 3 ? 0.15f :    //15%
  69.                       this.Tipo == 4 ? 0.2f : 0; //20%
  70.  
  71.             this.valorLiquido = (this.rendimento + this.valorInicial) - (this.rendimento * j);
  72.             return valorLiquido;
  73.  
  74.         }
  75.  
  76.         public void ImprimirInvestimentos()
  77.         {
  78.             Console.WriteLine("Investimentos");
  79.             for (int i = 0; i < carteira.Length; i++)
  80.             {
  81.                 Console.WriteLine(
  82.                     "\n Tipo:{0} ValorInicial:{1} ValorLiquido:{2} Rendimento:{3}"
  83.                     , carteira[i].Tipo, carteira[i].valorInicial, carteira[i].ValorLiquido(), carteira[i].Rendimento());
  84.             }
  85.         }
  86.  
  87.  
  88.         /// <summary>
  89.         ///
  90.         /// </summary>
  91.         /// <returns></returns>
  92.         public  Investimento Maislucrativo()
  93.         {
  94.             Investimento temp;
  95.            
  96.             for (int i = 0; i < this.carteira.Length ; i++)
  97.             {
  98.                 for (int y = 0; y < this.carteira.Length; y++)
  99.                 {
  100.                     if (carteira[i].Rendimento() > carteira[y].Rendimento())
  101.                     {
  102.                         temp = carteira[i];
  103.                     }
  104.  
  105.                 }
  106.                
  107.             }
  108.  
  109.             return temp;
  110.         }
  111.         public static void InvestimentoMaisLucrativoDeTodos()
  112.         {
  113.             Titular[] t = Exercicio2.Titular.Titulares;
  114.  
  115.             for (int i = 0; i < t.Length; i++)
  116.             {
  117.                 Console.WriteLine("Investidor {0} ", t[i].);
  118.  
  119.                 t[i].Investimentos.ImprimirInvestimentos();
  120.  
  121.             }
  122.  
  123.         }
  124.  
  125.         private static void compare()
  126.         {
  127.  
  128.         }
  129.  
  130.         public static void TodosOsInvestimentos()
  131.         {
  132.           Titular[] t = Exercicio2.Titular.Titulares;
  133.  
  134.           for (int i = 0; i < t.Length; i++)
  135.           {
  136.               Console.WriteLine("Investidor {0} ",t[i].Nome);
  137.                
  138.                t[i].Investimentos.ImprimirInvestimentos();
  139.  
  140.           }
  141.          
  142.         }
  143.  
  144.  
  145.     }
  146. }
Add Comment
Please, Sign In to add comment