Aug-25-2020, 11:42 AM
Hello there
New to python, I have a background in java, I'm finding oop in python confusing, this program simply prints out employee info and its suppose calculate their wage, when I run the program it just displays 0, any help appreciated thanks.
Total field is 0 but I want it to display total wage.
New to python, I have a background in java, I'm finding oop in python confusing, this program simply prints out employee info and its suppose calculate their wage, when I run the program it just displays 0, any help appreciated thanks.
class Pay(): def __init__(self, name, age, hoursWorked, amount_per_hour, total): self.name(name) self.age(age) self.hoursWorked(hoursWorked) self.amount_per_hour = amount_per_hour self.total = total def name(self): return self.__name def name(self, newname): if not newname: raise Exception("NAME FIELD CANNOT BE EMPTY") self.__name = newname def age(self): return self.__age def age(self, newvalue): if newvalue < 18: raise Exception("INVALID AGE") self.__age = newvalue def hoursWorked(self): return self.__hoursWorked def hoursWorked(self, newhours): if newhours < 0: raise Exception("HOURS MUST BE ENTERED") self.__hoursWorked = newhours def amount_per_hour(self): return self.__amount_per_hour def amount_per_hour(self, newamount): self.__amount_per_hour = newamount def total(self): return self.__total def total(self, newtotal): self.__total = newtotal def calculate_wage(self): self.total = self.hoursWorked * self.amount_per_hour return self.total def __str__(self): return "Name: " + self.__name + "\nAge: " + str(self.__age) + "\nHourWorked: " + str( self.__hoursWorked) + "\nAmount per Hour: " + str(self.amount_per_hour) + "\nTotal: " + str(self.total) p = Pay("Kevin", 34, 40, 9.80, 0) print(p)The output
Quote:Name: Kevin
Age: 34
HourWorked: 40
Amount per Hour: 9.8
Total: 0
Total field is 0 but I want it to display total wage.