Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class StartUp
- {
- public static void Main()
- {
- try
- {
- string[] studentTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string[] workerTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- Student student = new Student(studentTokens[0], studentTokens[1], studentTokens[2]);
- Worker worker = new Worker
- (workerTokens[0]
- , workerTokens[1]
- , decimal.Parse(workerTokens[2])
- , decimal.Parse(workerTokens[3]));
- Console.WriteLine(student.ToString());
- Console.WriteLine(worker.ToString());
- }
- catch (ArgumentException argEx)
- {
- Console.WriteLine(argEx.Message);
- }
- }
- }
- using System;
- using System.Text;
- public class Human
- {
- private string firstName;
- private string lastName;
- public Human(string firstName, string lastName)
- {
- this.FirstName = firstName;
- this.LastName = lastName;
- }
- public string FirstName
- {
- get { return this.firstName; }
- set
- {
- if (char.IsLower(value[0]))
- {
- throw new ArgumentException($"Expected upper case letter! Argument: firstName");
- }
- if (value.Length < 4)
- {
- throw new ArgumentException($"Expected upper case letter! Argument: firstName");
- }
- this.firstName = value;
- }
- }
- public string LastName
- {
- get { return this.lastName; }
- set
- {
- if (char.IsLower(value[0]))
- {
- throw new ArgumentException($"Expected upper case letter! Argument: lastName");
- }
- if (value.Length < 3)
- {
- throw new ArgumentException($"Expected upper case letter! Argument: lastName");
- }
- this.lastName = value;
- }
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- sb
- .AppendLine($"First Name: {this.FirstName}")
- .AppendLine($"Last Name: {this.LastName}");
- return sb.ToString();
- }
- }
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- public class Student : Human
- {
- private const string facultyValidation = @"^[A-Za-z\d]{5,10}$";
- private string facultyNumber;
- public Student(string firstName, string lastName, string facultyNumber)
- : base(firstName, lastName)
- {
- this.FacultyNumber = facultyNumber;
- }
- public string FacultyNumber
- {
- get { return this.facultyNumber; }
- set
- {
- if (value.Length < 5 || value.Length > 10)
- {
- throw new ArgumentException("Invalid faculty number!");
- }
- if (!Regex.IsMatch(value, facultyValidation))
- {
- throw new ArgumentException("Invalid faculty number!");
- }
- this.facultyNumber = value;
- }
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- sb.Append(base.ToString())
- .AppendLine($"Faculty number: {this.FacultyNumber}");
- return sb.ToString();
- }
- }
- using System;
- using System.Text;
- public class Worker : Human
- {
- private const int workDays = 5;
- private decimal weekSalary;
- private decimal workHours;
- public Worker(string firstName, string lastName, decimal weekSalary, decimal workHours)
- : base(firstName, lastName)
- {
- this.WeekSalary = weekSalary;
- this.WorkHours = workHours;
- }
- public decimal WeekSalary
- {
- get { return this.weekSalary; }
- set
- {
- if (value <= 10)
- {
- throw new ArgumentException($"Expected value mismatch! Argument: weekSalary");
- }
- this.weekSalary = value;
- }
- }
- public decimal WorkHours
- {
- get { return this.workHours; }
- set
- {
- if (value < 1 || value > 12)
- {
- throw new ArgumentException($"Expected value mismatch! Argument: workHoursPerDay");
- }
- this.workHours = value;
- }
- }
- private decimal CalculateSalaryPerHour()
- {
- return this.WeekSalary / (workDays * this.WorkHours);
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- sb.Append(base.ToString())
- .AppendLine($"Week Salary: {this.WeekSalary:f2}")
- .AppendLine($"Hours per day: {this.WorkHours:f2}")
- .AppendLine($"Salary per hour: {this.CalculateSalaryPerHour():f2}");
- return sb.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment