JAVA PROGRAM

create a class medicine.provide a function displaylabel() in this class to print name and address of the company. Derive tablet,syrup and oinment classes from the medicine class.Override the display label() function in each of these classes to print additional information suitable to the type of medicine..for eg in case of tablet ,it could be "store in a cool place, in case of ointment it could be "for external use only" etc. Create a class testmedicinee ,which will contain main function. Create object of each class in test medicinee.

i created the program but the program i made is lacking in basic things and it is giving me many error. Please help me in correcting the program and making my concept clear. Do suggest how can i make this program more modified too.

Replies

  • simplycoder
    simplycoder
    zion
    create a class medicine.provide a function displaylabel() in this class to print name and address of the company. Derive tablet,syrup and oinment classes from the medicine class.Override the display label() function in each of these classes to print additional information suitable to the type of medicine..for eg in case of tablet ,it could be "store in a cool place, in case of ointment it could be "for external use only" etc. Create a class testmedicinee ,which will contain main function. Create object of each class in test medicinee.

    i created the program but the program i made is lacking in basic things and it is giving me many error. Please help me in correcting the program and making my concept clear. Do suggest how can i make this program more modified too.
    Have you posted the correct code? I havent seen it entirely, however the basic mistakes I can see are syntactical. Please refer any basic book on java and correct them.
  • Anoop Kumar
    Anoop Kumar
    #-Link-Snipped-#

    Few observations:
    --You have void display label() method. that means display is a return type.
    --You have declared following as integer.
    int name ;
    int address;
    --Following code: how can be same local variable declared 4 times
    tablet obj= new tablet();
    syrup obj = new syrup();
    medicine obj = new medicine();
    oinment obj = new oinment();
    --You have created objects but never used those objects to call a method.
    --Always follow Code standards for java language. ex. ClassName should start with capital letter.

    Here is your corrected code.
    class Medicine {
        String name;
        String address;
     
        void displayLabel() {
            name = "zion medical store";
            address = "India";
            System.out.println(name +"  "+ address);
        }
    }
        class Tablet extends Medicine {
            void displayLabel() {
                System.out.println("store in cool n dry place");
            }
        }
     
        class Syrup extends Medicine {
            void displayLabel() {
                System.out.println("take after taking eatables");
            }
        }
     
        class Ointment extends Medicine {
            void displayLabel() {
                System.out.println("for external use only");
            }
        }
     
     
    public class Testmedicine {
        public static void main(String args[]) {
       
            Medicine obj2 = new Medicine();
            obj2.displayLabel();
       
            Tablet obj0 = new Tablet();
            obj0.displayLabel();
            Syrup obj1 = new Syrup();
            obj1.displayLabel();
       
            Ointment obj3 = new Ointment();
            obj3.displayLabel();
        }
    }
    
    In last: first try to master Object Oriented Concepts.
    without it java will be a hell.
  • zion
    zion
    #-Link-Snipped-#
    Thanx that really helped...😀

You are reading an archived discussion.

Related Posts

Does anyone know what's the joining date of candidates recruited in 2012 by Cognizant?
dear friends i really want to know how we can increase a power of hammer attack and lso sugeest me a good dc motor which may be used in cutting...
Honda is becoming an all round transport company. Walking is transportation too, right? Honda is coming in with robotic stride assist devices to help people with walking problems:
Micro power consuming devices like body worn health monitors and watches may soon be powered by thermoelectric wrist bands. https://www.mnn.com/green-tech/gadgets-electronics/stories/power-a-device-using-only-your-body-heat
Hello everyone I have to make an MP3 player on FPGA but I am a little bit lost. I mean I know that I have to read about things before...