backlight0815

Untitled

Jun 16th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.66 KB | None | 0 0
  1. class Covid {
  2.  
  3.   var population: Int
  4.   var cases: Int
  5.  
  6. init(population :Int, cases: Int) {
  7.   self.population = population
  8.   self.cases = cases
  9. }
  10.  
  11. func infection(){
  12.   population -= 243
  13. }
  14.  
  15. func Recover(){
  16.   cases += 1
  17. }
  18. func wasDeath() {
  19.    population -= 1
  20.   if population <= 0{
  21.     print("The population are reducing")
  22.   }
  23.  
  24.   }
  25. }
  26.  
  27. class Doctor: Covid{
  28.   let doctor: String
  29.   var remainingPatient: Int
  30.  
  31.   init(doctor: String, remainingPatient: Int, population: Int, cases: Int ){
  32.     self.doctor = doctor
  33.     self.remainingPatient = remainingPatient
  34.     super.init(population :population, cases: cases)
  35.    
  36.   }
  37.  
  38.   func manpower(){
  39.     if remainingPatient > 0 {
  40.       remainingPatient -= 1
  41.     } else{
  42.       print("You have no enough of doctor")
  43.     }
  44.   }
  45. }
  46.  
  47. class Hospital: Doctor {
  48.   var slots: Int
  49.  
  50.   init(slots: Int, doctor: String, remainingPatient: Int, population: Int, cases: Int)
  51.   {
  52.     self.slots = slots
  53.     super.init(doctor: doctor,remainingPatient: remainingPatient, population: population, cases: cases)
  54.   }
  55.  
  56. override func wasDeath(){
  57.   if slots > 0{
  58.     slots -= 1
  59.   } else {
  60.     super.wasDeath()
  61.   }
  62. }
  63. }
  64. let Malaysia = Covid( population:100, cases:0)
  65.  
  66. let Hospitals = Covid(population:12345,cases:1256)
  67.  
  68. let recover = Doctor(doctor:"First Line",remainingPatient:100,population:234,cases:98)
  69.  
  70. let Hospitalss = Hospital(slots:100, doctor:"RegencyHospital", remainingPatient:10, population:120, cases:10)
  71.  
  72. let Malaysias = Covid(population:1020,cases:2)
  73.  
  74. let people = Malaysias
  75. print(Malaysias.population)
  76. print(people.population)
  77. people.infection()
  78. print(Malaysias.population)
  79. print(people.population)
Add Comment
Please, Sign In to add comment