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

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...
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...
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
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an integer à The age of the vehicle       Price, a float à The price of the vehicle       Behaviors: Vehicle() à default constructor sets age=0, and price=0.0 setAge()   à Takes an integer parameter, returns nothing setPrice() à Takes a float parameter, returns nothing getAge()   à Takes no parameters, returns the vehicle’s age getPrice() à Takes no parameters, returns the vehicle’s price End Class Vehicle...
Write a class Car that contains the following attributes: The name of car The direction of...
Write a class Car that contains the following attributes: The name of car The direction of car (E, W, N, S) The position of car (from imaginary zero point) The class has the following member functions: A constructor to initialize the attributes. Turn function to change the direction of car to one step right side (e.g. if the direction is to E,it should be changed to S and so on.) Overload the Turn function to change the direction to any...
Name: Jessica Villasenor Date: June 14, 2020 Class: Principles of Microeconomics Professor: Priti Verma Assignment #4...
Name: Jessica Villasenor Date: June 14, 2020 Class: Principles of Microeconomics Professor: Priti Verma Assignment #4 1. Explain each of the following statements using supply-and-demand diagrams. a. “When a cold snap hits Florida, the price of orange juice rises in supermarkets throughout the country.” b. “When the weather turns warm in New England every summer, the price of hotel rooms in Caribbean resorts plummets.” c. “When a war breaks out in the Middle East, the price of gasoline rises and...
public class Person { private String name; public Person() { name = "No name yet"; }...
public class Person { private String name; public Person() { name = "No name yet"; } public Person(String initialName) { name = initialName; } public void setName(String newName) { name = newName; } public String getName() { return name; } public void writeOutput() { System.out.println("Name: " + name); } public boolean hasSameName(Person otherPerson) { return this.name.equalsIgnoreCase(otherPerson.name); } } 2- Write a Program Patient. Java Class that extends Person to include  Social security Gender  Appropriate construtors, accessors, and mutators....
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE-...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE- class-level attribute initialized to 1000 -acctID: int -bank: String -acctType: String (ex: checking, savings) -balance: Float METHODS: <<Constructor>>Account(id:int, bank: String, type:String, bal:float) +getAcctID(void): int                        NOTE: retrieving a CLASS-LEVEL attribute! -setAcctID(newID: int): void           NOTE: PRIVATE method +getBank(void): String +setBank(newBank: String): void +getBalance(void): float +setBalance(newBal: float): void +str(void): String NOTE: Description: prints the information for the account one item per line. For example: Account #:        ...
Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT