public static void Main() { ClassEmp[] employee = new ClassEmp[4]; employee[0] = new ClassEmp(); employee[1] = new PartTime(); employee[2] = new FullTime(); employee[3] = new TempTime(); //created an array of base class and to each element we assigned a different type of base class object // now create an array to loop through each base class object // since we have a base class reference variable referenceing to child classses, though we have the method in child overriding parent class //the base class method is called // the new keyword is used to hide the base class but our intension is to override the definition provided by base class, use override // for this mark the parent method virtual // this indicated the child class that it can override the parent class if it wishes to do so //though the ref variable is of type parent, the runtime checks the type of object, then it invokes the overriden method in the child class // this is called polymorphism // Polymorphism enables us to invoke the derived class methods using base class reference variables at run time // if the child class do not have any implementation overriding the parent class, then the parent class method is executed foreach (ClassEmp E in employee) { E.printfullname(); } }
static void Main(string[] args) { double gastoTotalSueldo = 0; FullTime Empleado1 = new FullTime("Juan", "DeLosPalotes", 23666666, 25000); FullTime Empleado2 = new FullTime("Amalita", "Fortava", 3222222, 35000); FreeLancer Empleado3 = new FreeLancer("Juanita", "Otrola", 24222222, 250, 50); FreeLancer Empleado4 = Empleado3; FreeLancer Empleado5 = new FreeLancer("Juanita", "Otrola", 24222222, 250, 50);; List <Empleado> empleadosEmpresa = new List <Empleado>(); empleadosEmpresa.Add(Empleado1); empleadosEmpresa.Add(Empleado2); empleadosEmpresa.Add(Empleado3); foreach (Empleado emp in empleadosEmpresa) { Console.WriteLine($"El sueldo de {emp.ToString()} es: ${emp.Sueldo()}."); gastoTotalSueldo += emp.Sueldo(); } Console.WriteLine($"\n\nEl gasto total en sueldos es: ${gastoTotalSueldo}."); Console.WriteLine($"\nCompara Empleado1 con Empleado2 con Equals y luego con Object.ReferenceEquals:"); Console.WriteLine($"Contenido: {Empleado1.Equals(Empleado2)}. \tPosicion de memoria: {Object.ReferenceEquals(Empleado1, Empleado2)}."); Console.WriteLine($"\nCompara Empleado3 con Empleado4 con Equals y luego con Object.ReferenceEquals:"); Console.WriteLine($"Contenido: {Empleado3.Equals(Empleado4)}. \tPosicion de memoria: {Object.ReferenceEquals(Empleado3, Empleado4)}."); Console.WriteLine($"\nCompara Empleado3 con Empleado5 con Equals y luego con Object.ReferenceEquals:"); Console.WriteLine($"Contenido: {Empleado3.Equals(Empleado5)}. \tPosicion de memoria: {Object.ReferenceEquals(Empleado3, Empleado5)}."); Console.WriteLine($"\n\n\n\nPresione cualquier tecla para finalizar."); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("ENTER ID"); int id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("ENTER NAME"); string Name = Console.ReadLine(); Console.WriteLine("ENTER ADDRESS"); string Address = Console.ReadLine(); Console.WriteLine("ENTER PAN NO"); string panno = Console.ReadLine(); Console.WriteLine("Press 1 Calculate PartTime Salary"); Console.WriteLine("Press 2 Calculate FullTime Salary"); int ch = Convert.ToInt32(Console.ReadLine()); switch (ch) { case 1: PartTime p1 = new PartTime(); Console.WriteLine("Enter Number Of Hour"); p1.noofhours = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Number Of Salary Per Hour"); p1.salaryperhour = Convert.ToInt32(Console.ReadLine()); int sal = p1.Salary(); p1.GetData(id, Name, Address, panno); p1.Display(); Console.WriteLine("YOUR PART TIIME SALARY IS :-" + sal); break; case 2: FullTime fl = new FullTime(); Console.WriteLine("ENTER BASIC SALARY"); fl.Basic = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("ENTER DA AMOUNT"); fl.DA = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("ENTER HRA AMOUNT"); fl.HRA = Convert.ToInt32(Console.ReadLine()); int fullsal = fl.Salary(); fl.GetData(id, Name, Address, panno); fl.Display(); Console.WriteLine("YOUR FULL TIIME SALARY IS :-" + fullsal); break; } Console.ReadLine(); }
public static void Main(string[] args) { Console.WriteLine("Hello World!"); // TODO: Implement Functionality Here FullTime ft = new FullTime(); PartTime pt = new PartTime(); ft.firstName = "babak"; ft.lastName = "slf"; ft.printFullName(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
/// <inheritdoc/> public override int GetHashCode() { int hash = 13; int mul = 7; hash = (hash * mul) + base.GetHashCode(); hash = (hash * mul) + FullTime.GetHashCode(); hash = (hash * mul) + NumberOfSatellites; hash = (hash * mul) + (byte)PositionMode; hash = (hash * mul) + (byte)VelocityMode; hash = (hash * mul) + (byte)OrientationMode; return(hash); }
static void Main() { Employee[] E = new Employee[4]; //Array of Employee E[0] = new Employee(); E[1] = new FullTime(); E[2] = new PartTime(); E[3] = new Temporary(); foreach (Employee e in E) { e.print(); } Console.Read(); }
static void Main(string[] args) { //Employment obj = new PartTime("Brahmi", 5000); //obj = new FullTime("s:",5); Employment fobj = new FullTime("Kowsik", 10000); //CAl objc = new PartTime("shu", 500); Console.WriteLine("*******"); fobj.AllDetails(); //obj.AllDetails(); Console.Read(); }
static void Main(string[] args) { FullTime pe = new FullTime(); pe.FirstName = "Aji"; pe.LastName = "Mustofa"; pe.PrintFullName(); // kita bisa juga menggunakan base class sebagai type, lalu instantiated ke kelas turunan Employee po = new PartTime(); po.FirstName = "Nur"; po.LastName = "Big boutty"; // kita bisa menggunakan type cast, untuk memanggil base class member //((Employee)po).PrintFullName(); po.PrintFullName(); }
public void loadData() { string fileSource = "../../..Baza Danych/Employers.txt"; //Load employee data from file/database etc. using (StreamReader file = new StreamReader(fileSource)) { int counter = 0; string ln; while ((ln = file.ReadLine()) != null) { var data = ln.Split(','); var firstName = data[0]; var lastName = data[1]; var contractType = data[2]; int monthlySalary = Int32.Parse(data[3]); int overtime = Int32.Parse(data[4]); var employee = new Employee(firstName, lastName); Contract contract; switch (contractType) { case "fullTime": contract = new FullTime(monthlySalary, overtime); employee.ChangeContract(contract); break; case "intership": contract = new Intership(monthlySalary); employee.ChangeContract(contract); break; default: // Do nothing, throw error break; } Employers.Add(employee); Console.WriteLine(ln); counter++; } file.Close(); Console.WriteLine($"File has {counter} lines."); } }
public void SetUp() { _database = Substitute.For <IMongoDatabase>(); _collection = Substitute.For <IMongoCollection <Match> >(); _matchDao = new MatchDao(_database, _collection); _team1 = new Team { Name = "test", Email = "test", ShortName = "test", Tla = "test", CrestUrl = "test", Address = "test", Phone = "test", Colors = "test", Venue = "test" }; _team2 = new Team { Name = "test", Email = "test", ShortName = "test", Tla = "test", CrestUrl = "test", Address = "test", Phone = "test", Colors = "test", Venue = "test" }; _fullTime = new FullTime { AwayTeam = 1, HomeTeam = 1 }; _halfTime = new HalfTime { AwayTeam = 1, HomeTeam = 1 }; _extraTime = new ExtraTime { AwayTeam = 1, HomeTeam = 1 }; _penalties = new Penalties { AwayTeam = 1, HomeTeam = 1 }; _score = new Score { Winner = "test", Duration = "test", ExtraTime = _extraTime, FullTime = _fullTime, Penalties = _penalties }; _match = new Match { Status = "test", LastUpdated = DateTime.Now, HomeTeam = _team1, AwayTeam = _team2, Score = _score }; }
private void btnModify_Click(object sender, EventArgs e) { Employee emp = null; string ccode = ""; int temp_seq = 0; try { if (cmbCategory.Text == "FullTime") { ccode = "FT"; if (!DataValidator.verifyData(txtFTAnnualSalary.Text, new Regex(DataValidator.patternMoney))) { MessageBox.Show("Annual Salary must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new FullTime((EnumPosition)cmbFTPosition.SelectedItem, Convert.ToDouble(txtFTAnnualSalary.Text)); temp_seq = emp.getId(); //Store last sequence } else if (cmbCategory.Text == "PartTime") { ccode = "PT-"; if (cmbPTContractType.Text == "Consultant_Trainers") { ccode += "CON"; if (!DataValidator.verifyData(txtPTContractMonth.Text, new Regex(DataValidator.patternNumber))) { MessageBox.Show("Contract Month must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!DataValidator.verifyData(txtPTTCHourlySal.Text, new Regex(DataValidator.patternHours))) { MessageBox.Show("Week hours must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!DataValidator.verifyData(txtPTCTWeekHours.Text, new Regex(DataValidator.patternHours))) { MessageBox.Show("Hours must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new ConsultantTrainer((EnumContractType)cmbPTContractType.SelectedItem, Convert.ToInt16(txtPTContractMonth.Text), Convert.ToDouble(txtPTTCHourlySal.Text), Convert.ToDouble(txtPTCTWeekHours.Text)); temp_seq = emp.getId(); //Store last sequence } else if (cmbPTContractType.Text == "Internship_Student") { ccode += "INT"; if (!DataValidator.verifyData(txtPTInternSal.Text, new Regex(DataValidator.patternMoney))) { MessageBox.Show("Internship Salary must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new Internship(Convert.ToDouble(txtPTInternSal.Text), (EnumContractType)cmbPTContractType.SelectedItem, Convert.ToInt16(txtPTContractMonth.Text)); temp_seq = emp.getId(); //Store last sequence } else { MessageBox.Show("Must be selected a Contract Type...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Must be selected an Employee's Category...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { emp.setFname(txtFirstName.Text); emp.setLname(txtLastName.Text); if (!DataValidator.verifyData(txtSIN.Text, new Regex(DataValidator.patternSIN))) { MessageBox.Show("Social Security must be a code like this ###-###-###", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setDepartment((EnumDepartment)cmbDept.SelectedItem); emp.setCategory((EnumCategory)cmbCategory.SelectedItem); if (!DataValidator.verifyData(txtHDay.Text, new Regex(DataValidator.patternDay))) { MessageBox.Show("Wrong day...Must be between 1 and 31", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHMonth.Text, new Regex(DataValidator.patternMonth))) { MessageBox.Show("Wrong month...Must be between 1 and 12", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHYear.Text, new Regex(DataValidator.patternYear))) { MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setHire_date(new Date(txtHDay.Text, txtHMonth.Text, txtHYear.Text)); if (!DataValidator.verifyData(txtBDay.Text, new Regex(DataValidator.patternDay))) { MessageBox.Show("Wrong day...Must be between 1 and 31", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtBMonth.Text, new Regex(DataValidator.patternMonth))) { MessageBox.Show("Wrong month...Must be between 1 and 12", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtBYear.Text, new Regex(DataValidator.patternYear))) { MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setBirthday(new Date(txtBDay.Text, txtBMonth.Text, txtBYear.Text)); if (!DataValidator.verifyData(txtAddStrNo.Text, new Regex(DataValidator.patternNumber))) { MessageBox.Show("Wrong Street No... Must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtAddApt.Text, new Regex(DataValidator.patternApt))) { MessageBox.Show("Wrong Appartment/House No... Must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtAddApt.Text, new Regex(DataValidator.patternApt))) { MessageBox.Show("Wrong Zip Code... Must be like this X#X-#X#", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setAddress(new Address(txtAddStrNo.Text, txtAddStrName.Text, txtAddApt.Text, txtAddCity.Text, txtAddState.Text, txtAddCountry.Text, txtAddZipCode.Text)); if (!DataValidator.verifyData(txtHCountCode.Text, new Regex(DataValidator.patternCountcode))) { MessageBox.Show("Wrong Phone Country Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHCityCode.Text, new Regex(DataValidator.patternCitycode))) { MessageBox.Show("Wrong Phone City Code...Must be a 3 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHLocalCode.Text, new Regex(DataValidator.patternLocalcode))) { MessageBox.Show("Wrong Phone Local...Must be a 7 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setHome_ph(new Phone(txtHCountCode.Text, txtHCityCode.Text, txtHLocalCode.Text)); if (!DataValidator.verifyData(txtCCountCode.Text, new Regex(DataValidator.patternCountcode))) { MessageBox.Show("Wrong Phone Country Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtCCityCode.Text, new Regex(DataValidator.patternCitycode))) { MessageBox.Show("Wrong Phone City Code...Must be a 3 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtCLocalCode.Text, new Regex(DataValidator.patternLocalcode))) { MessageBox.Show("Wrong Phone Local...Must be a 7 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setCel_ph(new Phone(txtCCountCode.Text, txtCCityCode.Text, txtCLocalCode.Text)); if (!DataValidator.verifyData(txtEmail.Text, new Regex(DataValidator.patternEmail))) { MessageBox.Show("Wrong email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setEmail(txtEmail.Text); emp.setSocial_security(tempsin); //Assign last displayed SIN txtTwoWeeksSal.Text = emp.getTwoWeeks_salary().ToString("#.##") + " $"; emp.setId(temp_id); emp.setContract(ccode); txtKey.Text = emp.getContract(); if (txtSIN.Text != emp.getSocial_security()) { MessageBox.Show("Can't to modify the SIN in the Modify option. It should use Add button", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (update_index > -1) { // Update list Box and list of employees //listBoxEmployees.Items.Insert(update_index, emp); employees.modify(emp, emp.getSocial_security()); listBoxEmployees.Items.Clear(); foreach (Employee temp in employees.ReturnList()) { this.listBoxEmployees.Items.Add(employees.ShowListInBox(temp)); } btnReset.PerformClick(); update_index = -1; save_flag = true; MessageBox.Show("Employee Mofified", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("It must to select an item and display it. Use Display Option", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Missing or incorrects values to enter...Check and Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("2222222222222Missing or incorrects values to enter...Check and Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { Console.WriteLine("PLEASE ENTER THE FOLLOWING DETAILS:"); Console.WriteLine("Enter the Name:"); string name = Console.ReadLine(); Console.WriteLine("Enter the Id:"); int id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the Address:"); string address = Console.ReadLine(); Console.WriteLine("Enter the PAN Number:"); string panno = Console.ReadLine(); Console.WriteLine("Press 1)PartTime Salary 2)FullTime Salary"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("Enter the no of hours:"); int no = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Salary per hour:"); int sal = Convert.ToInt32(Console.ReadLine()); PartTime p = new PartTime(); p.noofhours = no; p.salperhour = sal; p.Get(id, name, address, panno); Console.WriteLine("PartTime Salary is: " + p.Salary()); p.Display(); break; case 2: Console.WriteLine("Enter the basic salary:"); int basic = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the HRA:"); int hra = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the TA:"); int ta = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the DA:"); int da = Convert.ToInt32(Console.ReadLine()); FullTime f = new FullTime(); f.basic = basic; f.HRA = hra; f.TA = ta; f.DA = da; f.Get(id, name, address, panno); Console.WriteLine("FullTime Salary is: " + f.Salary()); f.Display(); break; default: Console.WriteLine("Invalid Choice!"); break; } Console.ReadKey(); }