static void Main(string[] args) { HashSet <Worker> workers = new HashSet <Worker>(); Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Department department = new Department(deptName); Worker worker1 = CreateWorker(department); Console.WriteLine(); Console.Write("How many contracts to this worker? "); int num = int.Parse(Console.ReadLine()); for (int i = 1; i <= num; i++) { HourContract contract = CreateContract(i); worker1.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate the income (MM/yyyy): "); //DateTime date = DateTime.ParseExact(Console.ReadLine(), "MM/yyyy", CultureInfo.InvariantCulture); //Console.WriteLine($"Name: {worker1.Name}"); //Console.WriteLine($"Department: {worker1.Department}"); //Console.WriteLine($"Income to {date.Month:D2}/{date.Year:D4}: {worker1.Income(date.Year, date.Month):F2}", CultureInfo.InvariantCulture); string monthAndYear = (Console.ReadLine()); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine($"Name: {worker1.Name}"); Console.WriteLine($"Department: {worker1.Department}"); Console.WriteLine($"Income to {monthAndYear}: {worker1.Income(year, month):F2}", CultureInfo.InvariantCulture); }
static void Escolhas(int escolha, Worker worker) { switch (escolha) { case 1: Console.WriteLine("Quantos contratos esse trabalhador tem ?"); Console.WriteLine("Contratos: "); int contratos = int.Parse(Console.ReadLine()); for (int i = 0; i < contratos; i++) { Console.WriteLine($"Contrato #{i}"); worker.AddContract(); Console.Clear(); } break; case 2: worker.RemoveContract(); Console.ReadLine(); Console.Clear(); break; case 3: worker.Income(); Console.ReadLine(); Console.Clear(); break; default: Console.WriteLine("Invalido"); Console.ReadLine(); Console.Clear(); break; } }
static void Main(string[] args) { /* Order order = new Order { * Id = 1080, * Moment = DateTime.Now, * Status = OrderStatus.PendingPayment * }; * * Console.WriteLine(order); * * string txt = OrderStatus.PendingPayment.ToString(); * * OrderStatus os = Enum.Parse<OrderStatus>("Delivered"); * * Console.WriteLine(os); * Console.WriteLine(txt); */ Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.Write("Enter worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine($"Enter #{i} contract data: "); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value Per Hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month) .ToString("F2", CultureInfo.InvariantCulture)); }
private static void Inputs() { Console.Write("Enter departament's name: "); string deptName = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name:"); string workerName = Console.ReadLine(); Console.WriteLine(); Console.Write("Level (Junior/MidLevel/Senior):"); WorkerLevel workerLevel = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.WriteLine(); Console.Write("Base salary:"); double workerSalary = double.Parse(Console.ReadLine()); Console.WriteLine(); Console.Write("How many contracts to this worker? "); double workerNumberContracts = double.Parse(Console.ReadLine()); Console.WriteLine(); Worker worker = new Worker(workerName, workerLevel, workerSalary, new Departament(deptName)); for (int i = 1; i <= workerNumberContracts; i++) { Console.WriteLine("Enter #{0} contract data:", i); Console.Write("Date (DD/MM/YYYY):"); DateTime contractDate = DateTime.Parse(Console.ReadLine()); Console.WriteLine(); Console.Write("Value per hour:"); double contractValueHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.WriteLine(); Console.Write("Duration (hours):"); int contractHour = int.Parse(Console.ReadLine()); Console.WriteLine(); worker.AddContract(new HourContract(contractDate, contractValueHour, contractHour)); } Console.Write("Enter month and year to calculate income (MM/YYYY):"); DateTime dateConsult = DateTime.Parse(Console.ReadLine()); Console.WriteLine(); Console.WriteLine(worker); Console.WriteLine($"Income for {dateConsult.ToString("MM/yyyy")}: {worker.Income(dateConsult.Year, dateConsult.Month)}"); }
static void Main(string[] args) { Worker worker = new Worker("Alex", Enum.Parse <WorkerLevel>("MidLevel"), 1200.00, new Departament("Design")); worker.AddContract(new HourContract(new DateTime(2018, 08, 20), 50.00, 20)); worker.AddContract(new HourContract(new DateTime(2018, 06, 13), 30.00, 18)); worker.AddContract(new HourContract(new DateTime(2018, 08, 25), 80.00, 10)); Console.Write("Enter month and year to calculate income (MM/YYYY):"); DateTime dateConsult = DateTime.Parse(Console.ReadLine()); Console.WriteLine(); Console.WriteLine(worker); Console.WriteLine($"Income for {dateConsult.ToString("MM/yyyy")}: {worker.Income(dateConsult.Year, dateConsult.Month):C}"); }
static void Main(string[] args) { //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=--=-=-=-=-=-=-=-=--=-=-=- // Solicita dados do trabalhador para o usuário Console.Write("Digite o nome do departamento: "); string depart = Console.ReadLine(); Console.WriteLine("Informe abaixo os dados do funcionário"); Console.Write("Nome: "); string name = Console.ReadLine(); Console.Write("Nivel (Junior/MidLevel/Senior): "); // Converte a string do usuário em objeto WorkerLevel tipo Enumeração WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Salário base: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); // Aqui após instanciar, passa os valores de argumento na chamada >> Departament(depart); Departament departament = new Departament(depart); // Aqui após instanciar, passa os valores de argumento na chamada >> Worker(name,level,baseSalary,departament) Worker worker = new Worker(name, level, baseSalary, departament); //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=--=-=-=-=-=-=-=-=--=-=-=- // Solicita informações do contrato para o usuário Console.Write("Quantos Contratos para este funcionário?: "); int qtd = int.Parse(Console.ReadLine()); // Instancia a quantidade de contratos informado pelo usuário for (int i = 1; i <= qtd; i++) { Console.Write($"Infome os dados do {i}º contrato"); Console.Write("Data do contrato (dd/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Valor da hora trabalhada?: "); double valorPerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Horas trabalhada?: "); int hours = int.Parse(Console.ReadLine()); // Passa os parametros para o novo contrato HourContract contract = new HourContract(date, valorPerHour, hours); // Faz a chamada para adição worker.AddContract(contract); } //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=--=-=-=-=-=-=-=-=--=-=-=- // Imprime o resultado Console.WriteLine(); Console.Write("Informe o mês e ano para calcular o pagamento (MM/YYYY): "); string mesAno = Console.ReadLine(); int mes = int.Parse(mesAno.Substring(0, 2)); int ano = int.Parse(mesAno.Substring(3, 4)); double tot = worker.Income(mes, ano); Console.WriteLine("Nome: " + worker.Name); Console.WriteLine("Departamento: " + worker.Departament.Name); Console.WriteLine($"Pagamento referênte a {mesAno}: " + worker.Income(ano, mes).ToString("F2", CultureInfo.InvariantCulture)); // Fim //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=--=-=-=-=-=-=-=-=--=-=-=- }
static void Main(string[] args) { Console.Write("Enter department's name: "); Department department = new Department { Name = Console.ReadLine() }; Console.WriteLine("\nEnter worker date: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("\nBase salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("\nLevel [Junior-MidLevel-Senior]: "); string level = Console.ReadLine(); Worker worker = new Worker { Name = name, BaseSalary = baseSalary, Level = Enum.Parse <WorkerLevel>(level), Department = department }; Console.Write("\nHow many contracts to this worker?: "); int numberOfContracts = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfContracts; i++) { Console.Write("\nDate [DD/MM/YYYY]: "); string date = Console.ReadLine(); Console.Write("\nValue per hour: "); double valuePerHour = double.Parse(Console.ReadLine()); Console.Write("\nDuration(hours): "); int hours = int.Parse(Console.ReadLine()); HourContract hc = new HourContract { Date = DateTime.Parse(date), Hours = hours, ValuePerHour = valuePerHour }; worker.AddContract(hc); } Console.WriteLine(worker.ToString()); Console.WriteLine(); Console.Write("Enter the month to calculate income [DD/MM/YYYY]: "); string yearMonth = Console.ReadLine(); Console.WriteLine($"Name: {worker.Name}\nDepartment: {worker.Department}\n" + $"Income for {yearMonth}: {worker.Income(int.Parse(yearMonth.Substring(0, 2)), int.Parse(yearMonth.Substring(3)))}"); }
static void Main(string[] args) { // date of department Console.WriteLine("Enter department's name: "); string depName = Console.ReadLine(); // date of worker Console.WriteLine("Enter worker data: "); Console.WriteLine("Name: "); string name = Console.ReadLine(); Console.WriteLine("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.WriteLine("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); // associating the values Department dept = new Department(depName); Worker worker = new Worker(name, level, baseSalary, dept); // setting the number of contracts Console.WriteLine("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { // registering the contracts Console.WriteLine($"Enter #{i} contract data: "); Console.WriteLine("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.WriteLine("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.WriteLine("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); // time of contract HourContract contract = new HourContract(date, valuePerHour, hours); // add contract to the worker worker.AddContract(contract); } // searching for a registered contract Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); // showing search Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for: " + monthAndYear + ": " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Exercício Resolvido\n"); Console.Write("Enter department's name: "); string dptName = Console.ReadLine(); Console.WriteLine("Enter Worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine());//converter de string para WorkerLevel; Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(dptName); Worker worker = new Worker(name, level, baseSalary, dept);// dept já vai instanciado; Console.Write("\nHow many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine($"Enter #{i} contract data: "); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); //ponteiro com a classe instanciada; worker.AddContract(contract); //levado como parametro; } Console.Write("\nEnter month and year to calculate income(MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); //substring(posição onde começa, onde termina); int year = int.Parse(monthAndYear.Substring(3)); //onde vai começar apenas(vai até a ultima posição); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); /* * a partir do objeto worker, se pode acessar a propriedade Department, e a partir * do Department se pode acessar o Nome. */ Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.ReadKey(); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string department = Console.ReadLine(); Department newDepartment = new Department(department); Console.WriteLine("Enter worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); string level = Console.ReadLine(); WorkerLevel workerLevel = Enum.Parse <WorkerLevel>(level); Console.Write("Base Salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Worker worker = new Worker ( name, workerLevel, baseSalary, newDepartment ); Console.Write("How many contracts to this worker? "); int numberContracts = int.Parse(Console.ReadLine()); for (int i = 1; i <= numberContracts; i++) { Console.WriteLine($"Enter #{i} contract data: "); Console.Write("Date (MM/DD/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valueHour = double.Parse(Console.ReadLine()); Console.Write("Duration (hours): "); int numberHours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract ( date, valueHour, numberHours ); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthYear = Console.ReadLine(); int month = int.Parse(monthYear.Substring(0, 2)); int year = int.Parse(monthYear.Substring(3)); Console.WriteLine($"Name: {worker.Name}"); Console.WriteLine($"Department: {worker.Department.Name}"); Console.WriteLine($"Income for {monthYear}: {worker.Income(year, month).ToString("F2",CultureInfo.InvariantCulture)}"); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkeLevel level = Enum.Parse <WorkeLevel>(Console.ReadLine()); Console.Write("Base Salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); // agora vou instânciar as entidades department worker Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.WriteLine(); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { Console.Write($"Enter #{i} contract data dd/mm/yyyy: "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); // chamo o metodo adicionar contrato worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); Console.WriteLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); // Console.WriteLine(month); int year = int.Parse(monthAndYear.Substring(3)); //Console.WriteLine(year); Console.WriteLine("Name " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYear + " : " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.WriteLine(); }
static void Main(string[] args) { Console.Write("Enter departament's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); //uma variável do tipo WorkerLevel que é o nosso enum, irá receber, porém será preciso ser convertida de string para WorkerLevel WorkerLevel level = (WorkerLevel)Enum.Parse(typeof(WorkerLevel), Console.ReadLine()); Console.Write("Base Salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); //Instâncias //Instanciar o objeto departamento Departament dept = new Departament(deptName); //Instanciar o objeto Worker Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { //Vamos usar a interpolação, para apresentação da variável no texto, por isso usamos $ no inicio Console.WriteLine($"Enter #{i} contract data:"); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); //Convertendo para o formato DateTime Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); //Depois do usuário digitar os dados do contrato, vamos instanciar o contrato HourContract contract = new HourContract(date, valuePerHour, hours); //Agora vamos adicionar o contrato ao trabalhador worker.AddContract(contract); //--------------------------------------------------------------------- } Console.WriteLine(""); Console.Write("Enter month and year to calculate income (MM/YYYY): "); //vamos guardar o mes e ano em uma string, depois vamos recortar a string nas posições desejadas string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3, 4)); //se colocar só o 3 ele corta do 3 em diantes, outra forma de fazer Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Departament: " + worker.Departament.Name); Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.ReadLine(); }
static void Main(string[] args) { string nameDept, nome; double salarioBase; int numContratos, mes, ano; string mesAno; Console.Write("Entre com o nome do departamento: "); nameDept = Console.ReadLine(); Console.WriteLine("Entre com os dados do trabalhador"); Console.Write("Nome: "); nome = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Insira o salário do trabalhador: "); salarioBase = double.Parse(Console.ReadLine()); Department department = new Department(nameDept); Worker worker = new Worker(nome, level, salarioBase, department); Console.Write("Quantos contratos para esse trabalhador? "); numContratos = int.Parse(Console.ReadLine()); for (int i = 0; i < numContratos; i++) { DateTime date; double valorPorHora; int duracao; Console.WriteLine($"Entre com dos dados do contrato #{i+1} "); Console.Write("Insira a data: DD/MM/AAAA: "); date = DateTime.Parse(Console.ReadLine()); Console.Write("Valor por hora: "); valorPorHora = double.Parse(Console.ReadLine()); Console.Write("Duração (em horas) do contrato: "); duracao = int.Parse(Console.ReadLine()); HourContract contrato = new HourContract(date, valorPorHora, duracao); worker.AddContract(contrato); } Console.WriteLine(); Console.Write("Entre com o mês e o ano no formato MM/AAAA para calcular os ganhos: "); mesAno = Console.ReadLine(); mes = int.Parse(mesAno.Substring(0, 2)); ano = int.Parse(mesAno.Substring(3)); Console.WriteLine($"Nome: {worker.Name}"); Console.WriteLine($"Departamento: {worker.Department.Name}"); Console.WriteLine($"Ganhos em {mesAno}: {worker.Income(ano, mes)}"); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base Salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); //instanciando os objetos com os valores arrecadados Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this worker "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine($"Enter #{i} contract data: "); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); //alimentando os contratos com os dados informados acima HourContract contract = new HourContract(date, valuePerHour, hours); //associando os contratos ao worker worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter the month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month).ToString("F2"), CultureInfo.InvariantCulture); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("\nEnter worker data:"); Console.Write("\nName: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel> (Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); //Instanciando a entidade departamento: Department dept = new Department(deptName); //Instanciando o objeto worker que vai ser o trabalhador: Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("\nHow many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine($"\nEntre com os dados do contrato #{i}:"); Console.Write("\nDate (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); //Instanciando um contrato: HourContract contract = new HourContract(date, valuePerHour, hours); //Adicionando o contrato nos contratos do trabalhador: worker.AddContract(contract); } Console.WriteLine(); Console.WriteLine("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); //Função subtring para cortar: int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.Write("\nName: " + worker.Name); Console.Write("\nDepartment: " + worker.Department.Name); Console.Write("\nIncome for " + monthAndYear + ": " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); }
static void Main(string[] args) { Console.Write("Insira o nome do Departemento:"); string deptName = Console.ReadLine(); Console.WriteLine("Insira as informações do trabalhador:"); Console.Write("Nome: "); string nomeFuncionario = Console.ReadLine(); Console.Write("Salário Base: "); double salarioBase = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.WriteLine("Cargo: 1 - Junior | 2 - MidLevel | 3 - Senior"); WorkerLevel cargo = Enum.Parse <WorkerLevel>(Console.ReadLine()); Department dept = new Department(deptName); Worker worker = new Worker(nomeFuncionario, salarioBase, cargo, dept); Console.WriteLine("-------------"); Console.WriteLine("Quantos contratos o funcionário está trabalhando"); int numberContracts = int.Parse(Console.ReadLine()); for (int i = 0; i < numberContracts; i++) { Console.Write($"Informe a data do contrato {i}: "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write($"Informe o valor hora do contrato {i}: "); double valorHora = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write($"Horas trabalhadas dentro do contrato {i}: "); int horaTrabalhada = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valorHora, horaTrabalhada); worker.AddContract(contract); Console.WriteLine("-----------------"); } Console.Write("Entre com o mês e ano (MM/YYYY) desejado para o cálculo de salário: "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Nome: {0}", worker.Name); Console.WriteLine("Departamento: {0}", worker.Department.Name); Console.WriteLine("Cargo: {0}", worker.Level); Console.WriteLine("Salário do mês solicitado: {0}", worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.ReadLine(); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.WriteLine("Level (Junior/MidLevel/Senio): "); WorkerLevel level = Enum.Parse<WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(deptName); Worker worker = new Worker(name,level,baseSalary,dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i<= n; i++) { Console.WriteLine($"Enter #{i} contract data: "); // $ -> Habilitar interpolação e colocar o {i} p/ funcionar Console.Write("Date (DD/MM/YYYY: "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for" + monthAndYear + ": " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture); }
static void Main(string[] args) { string data = DateTime.Now.ToLongDateString(); Console.WriteLine(data + "\n\n"); Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("\nWorker area:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine()); Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine("\nEnter the " + i + "º contract data: "); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", null); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine()); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month).ToString("F2")); }
static void Main(string[] args) { Console.WriteLine("Enter department's name:"); string deptName = Console.ReadLine(); Console.Write("Enter Worker Data :"); Console.Write("----------------------"); Console.WriteLine("Name :"); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior):"); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Enter with the Base salary:"); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dpt = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dpt); Console.Write("How many contracts to this worker?"); int contracNumber = int.Parse(Console.ReadLine()); for (int i = 1; i <= contracNumber; i++) { Console.Write($"Enter with #{i} contract data:"); // interpolacao Console.Write("Enter with the Date (DD/MM/YYYY):"); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour R$:"); double valueHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours):"); int duration = int.Parse(Console.ReadLine()); //Instanciar cada elemento HourContract contract = new HourContract(date, valueHour, duration); worker.AddContract(contract); } Console.WriteLine(); Console.WriteLine("Enter month and year to calculate income (MM/YYYY)"); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name : " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for :" + monthAndYear + " : " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); }
static void Main(string[] args) { Console.WriteLine("\n=-=-=-=-=-=-=Olar=-=-=-=-=-"); Console.Write("Digite o nome do departamento: "); string departamento = Console.ReadLine(); Console.WriteLine("Digite os dados do trabalhador"); Console.Write("Digite Nome: "); string name = Console.ReadLine(); Console.Write("Digite o Level (Junior, Midlevel, Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.WriteLine("Digite o salario base: "); double salario = Convert.ToDouble(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(departamento); Worker wk = new Worker(name, level, salario, dept); Console.WriteLine("Digite a quantidade de contratos: "); int contrato = Convert.ToInt32(Console.ReadLine()); for (int a = 0; a < contrato; a++) { Console.WriteLine("Vamos informar os dados do " + a + "º colaborador:"); Console.Write("Digite a data: "); DateTime date = Convert.ToDateTime(Console.ReadLine()); Console.Write("Digite o valor de Horas: "); int hour = Convert.ToInt32(Console.ReadLine()); Console.Write("Digite o tempo de duração: "); int valuePerHour = Convert.ToInt32(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hour); wk.AddContract(contract); Console.WriteLine(); } Console.WriteLine(); Console.Write("\nDigite o mes/ano para realizar o calculo: "); string periodo = Console.ReadLine(); int month = int.Parse(periodo.Substring(0, 2)); int year = int.Parse(periodo.Substring(3)); Console.WriteLine("Nome do trabalhador: " + wk.Name); Console.WriteLine("Departamento: " + wk.Department.Name); Console.WriteLine("Renda do período: " + periodo + ": " + wk.Income(year, month), CultureInfo.InvariantCulture); }
static void Main(string[] args) { //department name Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); //worker data Console.WriteLine("Enter worker data"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); string lvl = Console.ReadLine(); WorkerLevel level = (WorkerLevel)Enum.Parse(typeof(WorkerLevel), lvl, true); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); //department Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { Console.WriteLine($"Enter #{i} contract data:");; Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year do calcule income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine($"Income for {monthAndYear}: " + worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); Console.ReadLine(); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter Worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseS = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseS, dept); Console.Write("How many contracts to this worker? "); int contracts = int.Parse(Console.ReadLine()); for (int i = 0; i < contracts; i++) { Console.WriteLine("Enter #{0} contract data:", i + 1); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double value = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract c = new HourContract(date, value, hours); worker.AddContract(c); } Console.Write("Enter month and year to " + "calculate income (MM/YYYY): "); string[] dateIncome = Console.ReadLine().Split("/"); int month = int.Parse(dateIncome[0]); int year = int.Parse(dateIncome[1]); Loading.Load(); Console.WriteLine("Name: {0} " + "\nDepartment: {1} " + "\nIncome for {2}/{3}: {4}", worker.Name, worker.Department.Name, month.ToString("D2"), year, worker.Income(year, month) .ToString("C2", CultureInfo.CurrentCulture)); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string department = Console.ReadLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = (WorkerLevel)Enum.Parse(typeof(WorkerLevel), Console.ReadLine()); Console.Write("Base salary: "); double salary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(department); Worker worker = new Worker(name, level, salary, dept); Console.Write("How many contracts to this worker? "); int numberOfContracts = int.Parse(Console.ReadLine()); for (int i = 1; i <= numberOfContracts; i++) { Console.WriteLine("Enter #" + i + " contract data:"); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string[] read = Console.ReadLine().Split('/'); int month = int.Parse(read[0]); int year = int.Parse(read[1]); Console.WriteLine("Name: " + name); Console.WriteLine("Department: " + department); if (month < 10) { Console.WriteLine("Income for " + "0" + month + "/" + year + ": " + worker.Income(year, month)); } else { Console.WriteLine("Income for " + month + "/" + year + ": " + worker.Income(year, month)); } }
static void Main(string[] args) { Console.Write("Enter departmenet's name: "); string dpName = Console.ReadLine(); Console.WriteLine("Enter worker data: "); Console.Write("Name: "); string wkName = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel wkLevel = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); // instancia de department Department dept = new Department(dpName); // instanciando work e relacionando work com department Worker work = new Worker(wkName, wkLevel, baseSalary, dept); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { Console.WriteLine($"Enter #{i+1} contract data: "); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valueHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int durationHours = int.Parse(Console.ReadLine()); //intanciando um novo contrato, com data, valorHora, e duracao HourContract contract = new HourContract(date, valueHour, durationHours); //adcionar um contrato para um trabalhador work.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine("Name: " + work.Name); Console.WriteLine("Department: " + work.Department.Name); Console.WriteLine("Income for: " + monthAndYear + ": " + work.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)); }
//ContractCreation; public static void CreateContractLoop(Worker work) { Console.Write("How Many contracts to this worker? "); int repeatX = DefaultTexts.UserInput(); for (int i = 1; i <= repeatX; i++) { Console.WriteLine($"Enter #{i} contract data:"); work.AddContract(ContractData()); } }
static void Main(string[] args) { /* * Ler os dados de um trabalhador com N contratos (N fornecido pelo usuário). Depois, solicitar do usuário um mês * e mostrar qual foi o salário do funcionário nesse mês, conforme exemplo. */ Console.Write("Enter department's name: "); string departmentName = Console.ReadLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double salary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department department = new Department(departmentName); Worker worker = new Worker(name, level, salary, department); Console.Write("How many contracts to this worker? "); int numberOfContracts = int.Parse(Console.ReadLine()); for (int i = 1; i <= numberOfContracts; i++) { Console.WriteLine($"Enter #{i} contract data:"); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hours): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine($"Name: {worker.Name}"); Console.WriteLine($"Department: {worker.Department.Name}"); Console.WriteLine($"Income for {monthAndYear}: {worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)}"); }
static void Main(string[] args) { Console.Write("Enter department's name: "); string dp = Console.ReadLine(); Console.WriteLine("Enter worker data:"); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double salary = double.Parse(Console.ReadLine()); Department dep = new Department(dp); Worker worker = new Worker(name, level, salary, dep); Console.Write("How many contracts to this worker?"); int x = int.Parse(Console.ReadLine()); for (int i = 0; i < x; i++) { Console.WriteLine("Enter #" + (i + 1) + " contract data:"); Console.Write("Date (DD/MM/YYYY):"); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour:"); double value = double.Parse(Console.ReadLine()); Console.Write("Duration (hours):"); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, value, hours); worker.AddContract(contract); } Console.WriteLine(); Console.WriteLine("Enter month and year to calculate income (MM/YYYY):"); string monthAndYears = Console.ReadLine(); int month = int.Parse(monthAndYears.Substring(0, 2)); int year = int.Parse(monthAndYears.Substring(3)); Console.WriteLine(); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYears + ": R$ " + worker.Income(year, month)); }
static void Main(string[] args) { Worker worker; string departmentName, name, level; double baseSalary; int ammountOfContracts; Console.ForegroundColor = ConsoleColor.White; Console.Write("Enter department's name: "); departmentName = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Enter worker data:"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Name: "); name = Console.ReadLine(); Console.Write("Level (Junior/MidLevel/Senior): "); level = Console.ReadLine(); Console.Write("Base Salary: $"); baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); worker = new Worker(name, Enum.Parse <WorkerLevel>(level), baseSalary, new Department(departmentName)); Console.Write("How many contracts to this worker: "); ammountOfContracts = int.Parse(Console.ReadLine()); for (int i = 0; i < ammountOfContracts; i++) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine($"Enter #{i + 1} contract data:"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: $"); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Durantiom (Hours): "); int hours = int.Parse(Console.ReadLine()); worker.AddContract(new HourContract(date, valuePerHour, hours)); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string[] monthAndYear = Console.ReadLine().ToString().Split("/"); Console.WriteLine("Name: " + worker.Name); Console.WriteLine("Department: " + worker.Department.Name); Console.WriteLine("Income for " + monthAndYear[0] + "/" + monthAndYear[1] + ": $" + worker.Income(int.Parse(monthAndYear[1]), int.Parse(monthAndYear[0])).ToString("F2", CultureInfo.InvariantCulture) ); }
static void Main(string[] args) { try { Console.Write("Enter department's name: "); string deptName = Console.ReadLine(); Console.WriteLine("Enter worker data: "); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Leve (Junior/MidLevel/Senior): "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); Console.Write("Base salary: "); double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Department dept = new Department(deptName); Worker worker = new Worker(name, level, baseSalary, dept); Console.Write("How many contracts to this workers? "); int qtde = int.Parse(Console.ReadLine()); for (int i = 1; i <= qtde; i++) { Console.WriteLine($"Enter #{i} contract data:"); Console.Write("Date (DD/MM/YYYY): "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour: "); double valuePerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Duration (hour): "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY): "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine($"Name: {worker.Name}"); Console.WriteLine($"Department: {worker.Department.Name}"); Console.WriteLine($"Income for {monthAndYear}: {worker.Income(year, month).ToString("F2", CultureInfo.InvariantCulture)}"); } catch (FormatException e) { Console.WriteLine($"Erro de formatação: {e.Message}"); } catch (Exception e) { Console.WriteLine($"Erro inesperado: {e.Message}"); } }
static void Main(string[] args) { CultureInfo CI = CultureInfo.InvariantCulture; Console.Write("Enter department's name = "); string deptName = Console.ReadLine(); Console.WriteLine(); Console.Write("Enter Worker Data:"); Console.WriteLine(); Console.Write("Name = "); string workerName = Console.ReadLine(); Console.Write("Level (Junior/Midlevel/Senior) = "); WorkerLevel level = Enum.Parse <WorkerLevel>(Console.ReadLine()); // Conversão String-Enum Console.Write("Base Salary = "); double baseSalary = double.Parse(Console.ReadLine(), CI); Department dept = new Department(deptName); Worker worker = new Worker(workerName, level, baseSalary, dept); Console.WriteLine(); Console.Write("How many contracts to this worker? "); int n = int.Parse(Console.ReadLine()); Console.WriteLine(); for (int i = 1; i <= n; i++) { Console.WriteLine($"Enter #{i} contract data: "); Console.Write("Date (MM/DD/YYYY) = "); DateTime date = DateTime.Parse(Console.ReadLine()); Console.Write("Value per hour = "); double valuePerHour = double.Parse(Console.ReadLine(), CI); Console.Write("Duration (hours) = "); int hours = int.Parse(Console.ReadLine()); HourContract contract = new HourContract(date, valuePerHour, hours); worker.AddContract(contract); Console.WriteLine(); } Console.WriteLine(); Console.Write("Enter month and year to calculate income (MM/YYYY) = "); string monthAndYear = Console.ReadLine(); int month = int.Parse(monthAndYear.Substring(0, 2)); int year = int.Parse(monthAndYear.Substring(3)); Console.WriteLine(); Console.WriteLine("Worker Name = " + worker.WorkerName); Console.WriteLine("Department = " + worker.Department.DepartmentName); Console.WriteLine("Income for " + monthAndYear + ": $" + worker.Income(year, month)); }