1. Home >
  2. Apps >
  3. Groups >

JAVA PROGRAM

Question asked by zion in #Java on Oct 8, 2012
zion
zion · Oct 8, 2012
Rank D2 - MASTER
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. Posted in: #Java
simplycoder
simplycoder · Oct 9, 2012
Rank B3 - LEADER
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 · Oct 9, 2012
Rank A2 - PRO
zion

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 · Oct 9, 2012
Rank D2 - MASTER
ianoop
Thanx that really helped...😀

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up