#question regarding OOP

1 messages ยท Page 1 of 1 (latest)

silver plank
#

hi i have a small question regarding OOP.

charred karmaBOT
#

<@&987246399047479336> please have a look, thanks.

silver plank
#

in this question how could i make it have id, name , and dose for each drug ?

thin fiber
#

that has the fields for id name dosage (min or max)

#

and then in your prescription class you can have a drug array as a field

#

so something like this

#
public class Drug{
  
  public int ID; 
  public string Name;
  public string dosage;


//implement the constructor and getters and setters for it 

}

//now the prescription class

public class Prescription{
    public int ID
    public string doctorname;
    public string specialty;
    public Drug drugs[];

//implement the constructor(make sure limit to the drug array is 10) and getters and setters for it 


}
charred karmaBOT
# thin fiber ```java public class Drug{ public int ID; public string Name; public s...

Detected code, here are some useful tools:

Formatted code
public class Drug {
  public int ID;
  public string Name;
  public string dosage;
  //implement the constructor and getters and setters for it 
}
//now the prescription class
public class Prescription {
  public int IDpublic string doctorname;
  public string specialty;
  public Drug drugs[] ;
  //implement the constructor(make sure limit to the drug array is 10) and getters and setters for it 
}
thin fiber
#

hope it helps @silver plank

versed canyon
#

Though it's String not string in Java, the declaration of the array of drugs should be Drug[] drugs, the names of fields should start with a lower-case letter, and we would usually make the fields private and only expose them through getters and setters.

eg

   private String name;

   ...

   public String name() {
       return name();
   }

   public void setName(String name) {
       this.name = name;
   }
#

Since they don't want any methods, we're obviously doing it less idiomatically (for Java)

thin fiber
silver plank
#

Ok thanks for both.

#

I have one last question

#

What is the reason that the make me do a default constructer then make a copy one ?

brave storm
#

that should be in your assigment, every constructor gives another way of initialzing the object. Also the higher code is an example so do not copy paste it. Your doing an asiment on OOP and there are OOP problems in the pasted code

#

a prescription is made by a Doctor, so all the info regarding the Doctor does NOT come from strings ๐Ÿ˜‰

#

@silver plank

silver plank
#

Ok i see

#

I wanna send my code but it says its too long.

thin fiber
silver plank
charred karmaBOT
brave storm
#

first thing to notice -> user proper capital letters. Methods have camelCasing and classes start with a capital letter

#

and try to keep your class names logical. Info on a doktor usually just goes into Doktor

half narwhal
#

I'd split up your classes a bit. It's also a bit strange to see PatientInfo in a Prescription package. A Prescription can have a PatientID.

brave storm
#

has ๐Ÿ˜‰

half narwhal
#

Hmm?

brave storm
#

in this case its has a patientId, not can have

half narwhal
#

Sorry, I should have phrased it better. I was talking about his package structure.

#

Also pay attention to your spelling:

public pationtInfo(){

}
public pationtInfo(String name,int age , int id){
    this.name=name;
    this.age=age;
    this.id=id;
}
#
public String getose (){
    return dose;
} 
public int GETID (){
    return id;
}   
brave storm
#

also the assigment says no methods, only design. So good info for the future

silver plank
#

ok ok i will redo it.

silver plank
charred karmaBOT
brave storm
#

@lag might i suggest u actually read the text u pasted on the assignment

#

esp the 1st item

silver plank
#

without the methods

brave storm
#

yes

#

not really what your doing, all u need is a class diagram, not actual code

silver plank
#
public class PatientInfo {
    private String patientName;
    private int patientID;
    private int patientAge;
}

public class Drug {
    private String name;
    private int id;
    private String dose;
}

public class DoctorInfo {
    private String name;
    private String specialty;
    private int license;
}

public class Prescription {
    public static void main(String[] args) {

    }
}
charred karmaBOT
# silver plank ``` public class PatientInfo { private String patientName; private int p...

Detected code, here are some useful tools:

Formatted code
public class PatientInfo {
  private String patientName;
  private int patientID;
  private int patientAge;
}
public class Drug {
  private String name;
  private int id;
  private String dose;
}
public class DoctorInfo {
  private String name;
  private String specialty;
  private int license;
}
public class Prescription {
  public static void main(String[] args) {
  }
}
silver plank
#

is this fine ?

brave storm
#

no, u lack items. Also remember your lessens that oop gets translated to real life objects. What is a 'PatientInfo'? Wouldnt it be more logical to just use Patient ?

half narwhal
#

You're missing your actual prescription record.

brave storm
#

And if u seen actuall oop with extended classes, u lack something huge ๐Ÿ˜‰

silver plank
#

i am having hard time understanding OOP.

thin fiber
#

its as simple as that

silver plank
#

package prescription;



public class DoctorInfo {
    private String name;
    private String specialty;
    private int license;
}

public class Drug {
    private String name;
    private int id;
    private String dose;
}


public class Patient {
    private String patientName;
    private int patientID;
    private int patientAge;
    private Drug[] drugs;
    
}```
brave storm
#

do not panic, your on the good way. However your guessing at this point. Grab your assigment next to u and have a look ๐Ÿ˜‰

U need a prescription, a doctor and a patient, and a drug

#

doctor and patient have things in common, so ( unless u havent seen extended / parent-child ) so there u might want to consider having a parent class

#

a prescription has a patient and a doctor and it may contain up to 10 drug(s) and it has a date

silver plank
#

the date could i make it as static int?

brave storm
#

no

#

if u make it static, each change u make will go on every single prescription

#

lets start at the beginning, have u seen classes with extend or parent / child relations ?

silver plank
#

no

brave storm
#

have u seen anything like

class Car extends Vehicle;
class Airplane extends Vehicle;
#

something like that ?

silver plank
#

no

brave storm
#

right then u dont need to worry on a superclass

silver plank
#

this is the whole question

brave storm
#

i know your not going to like this but see the last line ?

silver plank
#

yeah

brave storm
#

u made the assumption u needed code

#

u need a class diagram in UML

silver plank
#

ik but i think after i write the code i do the a uml for it

#

for my code

brave storm
#

other way around

#

first u design, then u code

#

for example ( based on your drug above )

#

don't waste time coding it first when u just need a simple schematic. There is software to desinging those ( starUml / plantUml )

silver plank
#

wait what is Long

brave storm
#

a bigger number then int

#

int only goes from -2147483648 to 2147483647 so for an id that's kinda limited

raw belfry
# silver plank wait what is Long

There are 6 primitive number types in Java. byte 2^8 short 2^16 int 2^32 long 2^64 and there are also floating point types like float and double

#

Long in uppercase, like in the image you shared is a wrapper class of long

#

Basically the same long just with additional methods and which can be used in generic context when u come so far

silver plank
#

how much practice do u think it will take to become a pro. can anyone share how he started.

raw belfry
silver plank
#

ONLY 2 months ?

#

3*

raw belfry
#

dont forget 8 hours per day

#

And its just core Java

silver plank
#

yeah ik

raw belfry
#

If you want to build things like backend application you will also need to learn a lot of frameworks and librarys

#

basically you can never master Java fully, you will always be learning

#

And keep in mind very advanced in core Java doesnt mean that you know every standard library. Thats impossible, but you will know everything to implement pretty much anything you want as long as it not need external libraries

silver plank
#

ok thank you ill try my best

half narwhal
#

You always keep learning new things, core java continuously evolves. Good luck!

brave storm