ThinkVireo
  • Home (current)
  • About
  • TCS IPA/DCA(new)
    TCS DCA TCS IPA Python TCS IPA JAVA
  • FAQs
    TCS 2025
  • Contact
  • India
  • Leetcode

OOPS Q: Medicines

Watch Video on Youtube

Create class Medicine with below attributes:

  • MedicineName - String
  • Batch- String
  • State - String
  • Price- Int

Create class Solution and implement static method "getPriceByDisease" in the Solution class. This method will take array of Medicine objects and adisease String as parameters. And will return another sorted array of Integer objects where the disease String matches with the original array of Medicine object's disease attribute (case insensitive search).return the Price. ​

Write necessary getters and setters. Before calling "getPriceByDisease" method in the main method, read values for four Medicine objects referring the attributes in above sequence along with a String disease. Then call the "getPriceByDisease" method and print the result.


Sample Input:​
4
dolo650
FAC124W
fever
100
paracetamol
PAC545B
bodypain
150
almox
ALM747S
fever
200
aspirin
ASP849Q
flu
250
fever

​
Sample Output:​
100
200

  1. Python Code:
    
    class Medicine:
        def __init__(self, MedicineName, batch, disease, price):
            self.MedicineName = MedicineName
            self.batch = batch
            self.disease = disease
            self.price = price
            
    class Solution:
        @classmethod
        def getPriceByDisease(cls,list_med, dis):
            result = []
            for i in list_med:
                if i.disease.lower() == dis.lower():
                    result.append(i.price)
                    
            return result    
            
    
    n =int(input())
    list_med = []
    
    for i in range(n):
        MedicineName = input()
        batch = input()
        disease = input()
        price = int(input())
        
        list_med.append(Medicine(MedicineName,batch,disease,price))
        
    dis = input()
    answer = Solution.getPriceByDisease(list_med,dis)
    
    for i in answer:
        print(i)
    
                
                

ThinkVireo

ThinkVireo

TCS IPA Leetcode Python Java Partners Careers
FAQ Contact About Support Blog Services
Privacy & Policy

©ThinkVireo 2025 . All rights reserved.