Question

In: Computer Science

QUESTION 14 The class COVIDTest has five private attributes, name, test date, age, gender, and a...

QUESTION 14

  1. 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

Solutions

Expert Solution

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()


Related Solutions

Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class should add private attributes for years of experience and the annual salary. This class should also provide...
The Person Class Uses encapsulation Attributes private String name private Address address Constructors one constructor with...
The Person Class Uses encapsulation Attributes private String name private Address address Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: name - "John Doe" address - use the default constructor of Address one constructor with all (two) parameters one input parameter for each attribute Methods public String toString() returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and havekids (Boolean) variables. You have to create constructors and prosperities for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from the “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the people's information from “PersonInfo.txt” file and save them into the array. Give the user the ability to...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
Write a Python class to represent a Salik account. The account has three attributes, a name,...
Write a Python class to represent a Salik account. The account has three attributes, a name, id, and the balance. The balance is a private attribute. The class has extra functions to add to the balance and reduce the balance. Both, these functions should return the current balance and if the balance is below AED 50.0 print the message “Note: Balance Below 50”. Your class must work for the code given below. #Test myCar = SalikAccount() myCar.setName("John") myCar.setID("190300300333") myCar.setBal(20.0) yourCar...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Pycharm Complete the Place class that has the following attributes for place(name, country, priority and visited...
Pycharm Complete the Place class that has the following attributes for place(name, country, priority and visited status) and the methods: __init__ __str__ two methods to mark the place as unvisited\visited Then in complete a list of Place objects in Places_Features class and the following methods. load_places (from txt file into Place objects in the list) save_places (from place list into output list) add_place (add a place in the place list) input.txt Lima,Peru,3,n Auckland,New Zealand,1,v Rome,Italy,12,n Can make the main.py give...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT