#question regarding OOP
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
I think you can have a drug class
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
}
Detected code, here are some useful tools:
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
}
hope it helps @silver plank
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)
ahh got it, sorry bro still new to coding as a whole but makes sense tysm!
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 ?
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
send the file bro
I uploaded your attachments as Gist.
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
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.
has ๐
Hmm?
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;
}
also the assigment says no methods, only design. So good info for the future
ok ok i will redo it.
Idk if this is enough.
I uploaded your attachments as Gist.
@lag might i suggest u actually read the text u pasted on the assignment
esp the 1st item
without the methods
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) {
}
}
Detected code, here are some useful tools:
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) {
}
}
is this fine ?
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 ?
You're missing your actual prescription record.
And if u seen actuall oop with extended classes, u lack something huge ๐
i am having hard time understanding OOP.
ur pretty much creating blueprints of real world entities to simulate the real world bro
its as simple as that
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;
}```
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
the date could i make it as static int?
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 ?
no
have u seen anything like
class Car extends Vehicle;
class Airplane extends Vehicle;
something like that ?
no
right then u dont need to worry on a superclass
i know your not going to like this but see the last line ?
yeah
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 )
wait what is Long
a bigger number then int
int only goes from -2147483648 to 2147483647 so for an id that's kinda limited
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
thx
how much practice do u think it will take to become a pro. can anyone share how he started.
To become very advanced in core Java, its based on how much time you spend per day and the quality. If you spend everyday 8 hours coding (mostly projects instead of thousends Leedcode DSA problems) you will take about ~3 months.
yeah ik
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
ok thank you ill try my best
You always keep learning new things, core java continuously evolves. Good luck!
i started back in the days when Basic was still new. Actual basic, not visual basic. And do not focus on mastering the language. Focus on how to break down the assigment u need to do , so u can get it to work. Code evolves and reinvents itself every x days. Imposssible to learn and master it all. Its like the english saying Jack of all trades, Master of none