Advertisement
Nannoka

Lista de exercícios 2 Pessoa

Mar 4th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. //Classe Program//
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApplication2
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Pessoa p1 = new Pessoa("João" ,20);
  16.             while (true)
  17.             {
  18.                 Console.Clear();
  19.                 Console.WriteLine("Nome: " + p1.nome + " Idade: " + p1.Idade);
  20.                 Console.WriteLine("Para fazer aniverssário digite 1");
  21.                 Console.WriteLine("Para Sair digite <<Qualquer tecla>>");
  22.  
  23.                 int op = int.Parse(Console.ReadLine());
  24.  
  25.                 if (op==1)
  26.                  {
  27.                     p1.FazerAniverssario();
  28.                  }else{
  29.                     //Console.WriteLine("Opção invalida.");
  30.                     break;
  31.  
  32.                  }
  33.  
  34.              }
  35.             Console.ReadLine();
  36.           }
  37.        }
  38. }
  39.  
  40. //Classe Pessoa//
  41.  
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Text;
  46. using System.Threading.Tasks;
  47.  
  48. namespace ConsoleApplication2
  49. {
  50.     class Pessoa
  51.     {
  52.         public int Idade { get; set; }
  53.         public string nome { get; set; }
  54.  
  55.         public Pessoa(string nome, int idade){
  56.  
  57.             this.nome = nome;
  58.             this.Idade = idade;
  59.         }
  60.  
  61.             //Metodo void//
  62.             public void FazerAniverssario(){
  63.  
  64.                 this.Idade++;
  65.  
  66.             }
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement