Level 2 : Project 7
We want to write a program that manages the cost of teachers at a university.
Each teacher has a name, a first name and a certain number of hours of lessons during the year. There are several categories of teachers.
Teacher-researchers are paid with a fixed salary ($ 2,000) plus income from additional hours ($ 40 per hour). Additional hours are hours worked after 192 hours. Thus, a teacher-researcher who gives 200 hours of lessons in the year will receive 2000 * 12 + 8 * 40 = 24320 $ over the year.
Temporary contractors are teachers from an organization outside the university. This organism is described by a string of characters. Temporary workers are paid 40 $ per hour for all their hours.
3rd cycle students (doctoral students) can teach lessons and are paid 30 $ per hour, but cannot exceed 96 hours of lessons. A doctoral student who does more than 96 hours will only receive the salary corresponding to 96 hours of lessons.
Finally, on all salaries paid, charges equal to a certain percentage of the salary are applied, this percentage is the same for all teachers (for example 10%, which means that the amount of charges is equal to 10% of the amount of salaries). We want, for each teacher, to be able to know his annual salary before and after taxes.
Submit Dart code that represents this information and most closely conforms to the principles of object-oriented programming.
Example Of Main Program :
void main() {
Teacher.charges = 0.15;
var t1 = Researcher("Vahagn", "Sona", 214),
t2 = TemporaryContractors("Harut", "Kohar", 71, "Cornell University"),
t3 = DoctoralStudents("Toros", " Azat", 52),
t4 = DoctoralStudents("Yeva", "Ani", 122);
t1.salary();
t2.salary();
t3.salary();
t4.salary();
}
Annual Salary :
++ Before Taxes : 23120.0
++ After Taxes : 19652.0
Kohar Harut :
Annual Salary :
++ Before Taxes : 2840.0
++ After Taxes : 2414.0
Azat Toros :
Annual Salary :
++ Before Taxes : 1560.0
++ After Taxes : 1326.0
Ani Yeva :
Annual Salary :
++ Before Taxes : 2880.0
++ After Taxes : 2448.0
Solution:
abstract class Teacher {
String _firstName, _lastName;
int _hoursOfLessons;
static double charges = 0.0;
Teacher(String fn, String ln, int h) {
_firstName = fn;
_lastName = ln;
_hoursOfLessons = h;
}
void salary();
}
class Researcher extends Teacher {
Researcher(String fn, String ln, int h) : super(fn, ln, h) {}
void salary() {
double s = 2000.0 * 12;
if (_hoursOfLessons > 192) {
s += (192 - _hoursOfLessons) * 40;
}
print("$_lastName $_firstName :");
print(
"Annual Salary : \n ++ Before Taxes : $s \n ++ After Taxes : ${s * (1 - Teacher.charges)} \n");
}
}
class TemporaryContractors extends Teacher {
String _organism;
TemporaryContractors(String fn, String ln, int h, String o)
: super(fn, ln, h) {
_organism = o;
}
void salary() {
double s = _hoursOfLessons * 40.0;
print("$_lastName $_firstName :");
print(
"Annual Salary : \n ++ Before Taxes : $s \n ++ After Taxes : ${s * (1 - Teacher.charges)} \n");
}
}
class DoctoralStudents extends Teacher {
DoctoralStudents(String fn, String ln, int h) : super(fn, ln, h) {}
void salary() {
double s = _hoursOfLessons > 96 ? 96 * 30.0 : _hoursOfLessons * 30.0;
print("$_lastName $_firstName :");
print(
"Annual Salary : \n ++ Before Taxes : $s \n ++ After Taxes : ${s * (1 - Teacher.charges)} \n");
}
}
void main() {
Teacher.charges = 0.15;
var t1 = Researcher("Vahagn", "Sona", 214),
t2 = TemporaryContractors("Harut", "Kohar", 71, "Cornell University"),
t3 = DoctoralStudents("Toros", " Azat", 52),
t4 = DoctoralStudents("Yeva", "Ani", 122);
t1.salary();
t2.salary();
t3.salary();
t4.salary();
}
Annual Salary :
++ Before Taxes : 23120.0
++ After Taxes : 19652.0
Kohar Harut :
Annual Salary :
++ Before Taxes : 2840.0
++ After Taxes : 2414.0
Azat Toros :
Annual Salary :
++ Before Taxes : 1560.0
++ After Taxes : 1326.0
Ani Yeva :
Annual Salary :
++ Before Taxes : 2880.0
++ After Taxes : 2448.0