In: Computer Science
QUESTION 14
The class COVIDTest has five private attributes, name, test date, age, gender, and a Boolean value telling us whether test was positive or negative. Implement the function nextTest() based on the logic, if the number of days from the test date to the current date is more than or equal to 15 days, then print the message “Note: Time to do a COVID 19 Test”, otherwise print “Test not required”.
The following test case reveals the use of the class. Define a Python class to match the test case given below.
#Test: Do NOT change this code test1 = COIVDTest() test1.setname('Jamal K') test1.setdate('09/10/2020') test1.setage(45) test1.setgender('Male') test1.setresult(False) print(test1.nextTest()) # Print if next test is needed print(test1.displaytest()) # Print all details of a test
from datetime import date
class COVIDTest:
def init(self,name = "", age = 0,gender = "", result =
False, Date = ""):
self.__age = age
self.__name = name
self.__gender = gender
self.__result = result
self.__Date = Date
# setter method
def setname(self, name):
self.__name = name
def setage(self, age):
self.__age = age
def setgender(self, gender):
self.__gender = gender
def setresult(self, result):
self.__result = result
def setdate(self, Date):
self.__Date = Date
#print(Date)
def nextTest(self):
day, month, year = map(int,
self.__Date.split('/'))
test_date = date(year, month,
day)
#print(test_date)
today = date.today()
today_date =
date(today.year,today.month,today.day)
if(abs((today_date -
test_date).days) >=15):
print("Time to
do a COVID 19 Test")
else :
print("Test not
required")
def displayTest(self):
if self.__result==True :
print("Take care
your self wear mask get well soon bp high ...")
else :
print("Healty
man")
test1 = COVIDTest()
test1.setname('Jamal K')
test1.setdate('09/09/2020')
test1.setage(45)
test1.setgender('Male')
test1.setresult(False)
test1.nextTest()
test1.displayTest()