Build your first OOP application in Java with example - Building a School Management System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's happening guys this video is going to be a totally different type of video so far when we compare it with the previous ones alright now in this video we are so far you know we have been covering theory theory theory and we have not gotten into practicality right so let's dive into practicality by building a basic school management system so you know what let's let me rephrase it properly so let let me get started by creating a new package and then say school management system alright now here is a school management system package and then I'm going to first of all let's just even think about this and what is the purpose of this application and let us do a little bit of groundwork before we delve into actual development all right let's create a new file and close close all oh man ok let me create that's let's even remove folder from this project yeah so you know I I just don't like it that way so bear with me guys all right now what are we trying to do we are trying to first of all create let me save this and I will call it specification in my desktop spec spec txt all right so now we are going to create a school management system right it is this is not going to manage everything about school you know it's not going to manage certain things which are also important still trivial let me just say I know both of them sound conflicting but however so let's think about this the school's management system is is involved in maintaining students teachers and then and then the funds that's it it's not going to maintain every single detail about student such as attendance or whatever so it's going to just maintain things only pertinent to students teachers so what do I mean by that students teachers and funds okay so basically we are trying to build what is now we have to rephrase it as what is called as a money management system for school because that's what I'm trying to build I am NOT going to build every single detail because we don't have all the time I'm trying to finish this within an hour or so so this becomes more consumable all right now let's even think about this so we have defined what we should do let me explain what we should do we have to keep a track of student visas yeah okay students total fees and students fees paid okay and teachers let me just make them real quick keep a track off keep track of students fees that is total fees okay teacher and then piece and then fees that is paid already paid okay and so and then teacher's salary now so this is the basic core idea of our project in Java that we are trying to build now let us take a look at this this is the Eagle view let us go little down the by step now when we talk about the school basically the school contains what and what the school contains teachers right the school contains students right and the school contains a total money earned because that is the money that's coming from the students right and then the school contains total money spent okay now and obviously when I say spent I am just taking into account just the teacher salary I know this is this type of school will never survive but but just for the sake of our understanding and developing our program this is what I would say so I am just taking into account total money spent that is teacher's salary that's it okay now let us these you know this is what a school object will contain you know then we have a teacher right now let us take a look at the teacher what would what characteristics would a teacher contain well the teacher can contain characteristics such as maybe a teacher ID right because that is a unique reference to the ID and let us just keep keep an account of the teachers name his or her name and then let us keep an account of his or her salary because obviously when salary is there that is sent out to teacher right that's it is there something else let me think just for this small set of requirement I think that should be it teacher contains name ID salary and then maybe events once once we release wasn't to maybe you guys can help me collaborate then you will have your own idea all right now let us talk about a student now in a student you know so in a student object right what would a student contain let us think about it like this a student would contain an ID right the student could contain a name a student would contain a class that he he takes right basically which grade I would say something like this grade just make things clear so which grade and then the student would contain fees that is supposed to be paid correct and fees that is total total fees or let's make it like this let's make it fees and then these total I think that should be sufficient at this point when we start just understanding the concept of building classes and everything so here right now we come to a point where we start all applying applying all the auto P concept that we have learned object-oriented program concept that we have so far learned in our course so far now let us try to to to kind of you know as decompose what it is that we want to have we have students name grade fees paid fees total and then let's do we want to have a class object I don't think we need a class object at this point because you know it's kind of irrelevant at this point all right now that we have this you know decided what we want let us try to build something like this now that we know what our requirements are now that okay now you can have have a question you know you can ask me hey rocks it you said you want to build a money management system for school and then this was respected specification to keep a track of students total fees to keep a track of fees paid to keep a track of teachers salary okay now you can ask me hey but how did you get to know that we have to build classes like this you know when I said objects I mean classes right so I mean we have to build a school class a teacher class a student class you can ask me how did I get to know well the answer is that you know you have to realize that as much in the Indian spec try and find out as many nouns as you can okay so if you find enough number of nouns basically so school is a noun students that is a noun fees yeah let's say that and then teachers is definitely enough noun so once you find out all these nouns then you start to uh you know find out the property for all these moms you know then you say okay so I'm going to build this class what could a class of school look like you know you have to try to reverse engineer and then get to what you want so for instance we we saw that we saw that you know school is is a noun and what could an object of school look like what would what could an object of teachers look like what could an object of student look like you know you have to be able to are try and and and try to fix a standard grounding framework so based on that you can proceed further so that is the basic idea for our design I said it's a simple application this is just for someone who just learned object-oriented programming and that should be quite as what it is that we should take care of at this point so let's get into it the first class that we would be building is called as a what you want me to build the first class is school well school has teachers objects students object so you know what let's go from the groundwork which is student object okay now so let us get into our development now let us let me pull up IntelliJ and create a new java class called as student now this is a student class now what we do and very important it's a very good practice to start commenting what it is that you are trying to build so this class is responsible for keeping the track of students you know whatever you wish to type you can type right at this point then we'll get to you know building something much much better as a matter of fact even I am learning how to comment properly how to get the best part of the code you know it's a learning process for me and for you guys so so we both are learning and it's it's fine if we stumble across with some some some wrong things but you have to get into working you know you have to get into doing then that is how you build leverage to proceed further to continue anyway so this class is responsible for keeping the track of students you know fees name whatever what else did we say name ID I think here ID name grade be spared yeah grade and fees paid yep so that is the basic introduction I mean this is not how you comment but anyway that's fine so let's get into it so what is the first thing that we should always think about so student has to be represented by an ID right so ID is going to be always an integer and I'll make it ID and now let us come back to our object-oriented concept so let us should we give a access specifier if you said yes you're right so you should say private int ID why did we do this private that's because you want to protect somebody from accessing this ID outside the student class all right next is name so what field is it obviously this is going to be a private and then this is a strength and I will call it name okay then let us look at this that is a grade right so grade here it's great now grade let us just make it simple by making private int grade okay and we'll get to a point where we define the accepted grade is from one to twelve but anyway at this point grade is this then oh and by the way I said nouns right that is a tip from Kay Hoffman you know he is a great author who check out his book anyway so that is something that I picked up from that book so that's about it yeah let's get back to what we were doing we stayed and peace total all right so let's make it private int C Spade correct and then I will make it private end fees total okay so these are all our fields in in ma student class correct now let us proceed further what what should you know how should a new student object look like as soon as we create a student object so you know what let us let us try to just get it started by creating a constructor so a constructor is something and trying to give you a recap which is a constructor is something that's going to create a new object it's going to create as soon as we call the new keyword as soon as the compiler encounters the new keyword the constructor is called constructors a special function so let's start creating the constructor public student okay and all right let us look at what we have to do now so when you create a student object what should be required well number one is always ID right ID is very essential you should pass the ID for a student okay number two you should pass the name for the student right without name how do I if I a student up you know we have ID and then there could be a case where the the names could be exactly matching so that is why we need a name okay and then we want to basically set up the grade if you will if you want you can you can choose to pass the grade object as well okay then now as we have all these objects we have to initialize you know the role of a constructor is to create a new object new which object student object the role of a constructor is to create a new student object by doing what by initializing the values that is the job of the constructor you know sometimes I hate it when I I type the wrong spinning but but you know I'm just impatient to go and search for it so I right click and fix it by using until it is helped anyway that's a good thing so parameter ID ID is basically the ID for the student which is going to be a unique value right which is going to be a unique value name of the student that could be occurring to be unique but that's fine again grade of the student could be unique couldn't be unique I mean these are all good practices that is why I'm going and typing alarmed when we do this and by the way if you have a question where or access how did you create this all you have to do is press forward slash and start start twice and hit enter you get this anyway I'm just going to get rid of this at this point and paste my stuff okay now what should we do we have pro key or the ID object right ID value we have protrude the name and we have procured the bridge so how do we proceed further well you should do something like this before we do anything let us try to validate the values because because you know we don't want ID to be repeated right we don't want any IDs to be repeated okay so you know what let me do it later let's let's first do the basic set up and then we can always fix all of that this so basically I am trying to initialize all the values this dot ID equals ID what are we doing here we are telling ID from our object here that is this ID ID from the student class that is what it is this dot ID is equal to ID from the argument which is the ID to the right hand side likewise what should we do this dot name equals name you got it so this dot name means basically the name from from our field by the way the these are all called as fields you know these are all foreigners fields this dot name equals name from our constructor and again what should we do come on guys tell me this dot grade if you told it you're awesome equals grade from the argument right so this is how you create a new student object so that is the idea behind the constructor okay and then let me let us just then proceed further with the student class now that we have procured the ID the name and so I have a question what is the fees paid would be what let us just assume that every student has to pay about $30,000 for the school I don't know what kind of school that is but it's a pretty expensive school so so what do you do you have to initialize that value right so basically you set you say okay the fees is going to be fees for every student is going to be $30,000 per year pretty expensive school $40,000 per year okay now and also whenever an object is created whenever a new student is enrolled what is the fees for that student what would be the fees that you have paid you wouldn't have paid anything right so fee is paid initially is what is just zero right oh man yeah okay thank you IntelliJ for that okay so the fees paid is going to be zero right so what do we do we say fees paid equals zero and this time notice I am not using this why am I not using this because you know if I left okay let's just take a take a step back and review what what we did here if I get rid of the this keyword here what is going to happen IntelliJ is confused what are you doing Roxette it's like I don't understand what are you even trying to do but then when you say this dot ID now into the King is recognizing ah oh I got it my ID from the class is going to be equal to IDs from the argument in the method now oh until junior like this oh that's cool thing that's fine but but do we want to have this keyword 4c Spade no why because C spade is not passed as an argument right so there is no possibility for a conflict there is no possibility for an ambiguity so that is why we don't use this but nevertheless it's not an offence to use this so it's up to the developer you get to decide what you have to do right so this dot C spade is 0 this dot fils total for every student is 30,000 so now that we accept we have initialized all the fields we are good to go always always try to initialize all the fields from the class okay so now you have done everything let us go proceed further what should I do if I want to set a value to what should I do if I have to set a value to you know we are not going to alter a student's name the first thing you should realize is we are not going to order students name now if we don't alter a student's name do you think setname method is required do you think a set name method is required I don't think so because see once if you want to alter a student's name then you would prefer to set it but if you are not altering then it's a good idea to just keep it just like that right so I am NOT going to alter student's name again the same thing is applicable for ID as well so I am NOT going to alter students ID also because these are all locked fields I am NOT going to keep altering all these fields so that is also taken care so we are not going to add the students and ID then what is it that we are going to order are we going to order students grade do you think that we are going to order students grade maybe yeah when student gets promoted we would you know promote the student right so in that case yes so we we kind of you know promote the student so public let us let us try and give a permission to alter the value so public why do you remember I said setter should always be wide and Gators would would always be returning some particular datatype now since I'm dealing with a setter it's going to be wide public wide set grade okay my question to you is would I be using set ID set name oops what did I do yeah would I be using satire Lee set name yes or no no so that's why I added this line of comment here all right set ID set grade is okay set ID and set name is not going to be used we are only going to use set grade now let us do now and you to set grade you are going to accept a grade okay so you say end grade okay and then you say this dot grade equals grade did you understand what's going on when we do a set grade basically we are updating the grade of that particular student to the grade that is coming from the argument so that is what is set grade and is its you know are we going to do something else apart from that with the student yes we are going to update the fee speed right now before that let me comment it real quick set grade okay used to update the students grade and then parameter grade is going to return I'm sorry the parameter grade is the grade is the new grade of the student all right now that we we came to a point where we realized okay so we are going to update and that's good now let us let us think about this now are we going to change fees paid at some point yes we are going to change the fees paid all right and then are we going to change the fees total no we are not going to change the piece totals right okay now what I'm going to do right now is I am going to create another setter method that basically updates the fees you know what it's just an updating method so I'll say public wide-set you know what I will say update fees paid okay and then this update fees paid will receive an integer value called fees just like that now let us think about what this function is going to do if you let me just try to comment so it becomes much good and much much you know visually good-looking okay now when you want to do a fees update what are you going to do basically we have to first take into account that the school is going to receive yeah that's a good spelling right okay the school is going to receive the funds okay first of all the school is going to receive the funds but basically before even that happens what's happening is just add the fees to the fees paid right so let let's just even think about this now for a second what are we trying to do with updates update fees so basically if the fees initially was zero now let us say the student pays the fees are ten thousand dollars at this point now if the student pays $10,000 so what should the fees paid me the fees paid should become ten thousand dollars correct now it should become ten thousand dollars but then after some point student now pays another $5,000 what should the fees paid now become fifteen thousand dollars correct and then at some point again the student pays another fifteen thousand dollars so what happens is fifteen thousand dollars is here now what so did the student pay effectively the fees yes he did so so basically our update method should keep adding the fees so receive the fees and then keep adding it to the fees of you know the fees field that we are created so basically keep adding the fees to - what - fees paid - fees paid field that's it so let's try and okay now this parent fee is basically what is the piece that student pays okay now let us try and update the fees so basically now it's going to say 3-speed is equal to c state that was the original fees that was paid initially it is set to zero remember this fees paid was set to zero so that's why I'm telling fees paid plus fees that's it now this could be one step are reduced this line of code can be done and as fees paid equals actually fees paid plus equals fees that's it so basically we are continuously adding the fees okay so that is the role of update fees method I'm sorry update fees paid method and then should we do anything else should we do anything else think about it think about it should we do anything else I think that should be it right but then we will revisit it I know that is I know we have to do a couple more tweaks but this is not the final version but this is the basic setup so so always remember you know I'm not going to go this depth when we create the teachers class I am going to go a little fast but at this point you should realize that there are certain rules you should initialize a field and then I'm sorry you should you know declare a field and then initialize the field inside the constructor and then try to give proper comments and everything so you know once you refer back to it you'll be able to realize oh this is why I wrote this method anyway so let's get started by creating our new class which is teachers class so basically the teachers class is containing an ID a name and the sound that's it teachers of a teacher okay so this teacher class is containing what what what since containing a private int ID and then it's containing a name private string name and then it contains a salary right private int I mean yeah I realize the salary could have been a double but for the sake of all you know simplicity and and that our our this is our first program let us not go fully real world okay now come on guys what should i type here so this class is responsible for keeping the track of teachers name ID actually I should have written ID first and then name but but that's fine you know em ID and the salary okay yeah I think that should be it at this point let's just proceed further now let us go and create a constructor now let's just think about this let us imagine that the salary for every teacher is unique you know it depends on the seniority of the teacher the experience of the teacher and everything so what are the what are the fields you know that I should Ennis initialize in the constructor so let's first of all create a constructor public teacher okay and the parameters are come on guys tell me what are the parameters first of all I D is going to be obviously a parameter ladies always unique for a teacher right and then again name is going to be there as a parameter right and then there is the salary which is also unique so I cannot directly initialize the salary like how I did it here I cannot do that because salary keeps changing okay now so this are now guys come on tell me this is like the simplest thing you could do this dot ID equals ID okay this dot name equals name and this dot salary equals salary so now that we are you know so this constructor is responsible for creating a new creates a new teacher object right so so you know let's let's set up the values ID for the teacher okay and name of the teacher okay and the salary of the teacher all right now do we want to get the ID yes we need to get the ID do you want to get the name yes we need to get the name and then do we want to get the salary yes we need to get the salary likewise oh okay let me just finish this off and then let's jump back to student so do I want to get the ID yes do I want to get the name yes do I want to get the salary yes for sure so public public when I say get the name what should be the Routan type string right public string get me okay now what is this going to do it is all it is going to do is return this this dot knee okay so basically it is going to return the name of the teacher now you could either use this keyword or not it's up to you but at this point I am going to just use return name now likewise let us create another Gator for public salary okay so you know what let me just go in order I don't like to be half-ass oddly writing code that is not so good so public int get ID okay now what should I do I should say return ID that's it simple as that then let us look at this public int salary so basically public and get salary and then what should I do return salary right that's it so now we have we are you know trying to get so basically get get get what is this get doing it's going to just send out the salary value return the salary Oh return the ID for the teacher you know it returns the ID for the current teacher okay likewise I am NOT going to write full full code because we don't have all the time in the world I mean another thread fulfill comment yeah so return name of the teacher right okay then return the salary of the teacher right okay Heidi of the teacher okay so now now that we we have done we have retrieved the salary so we have taken care about the Gator now let us talk about the second so let us look at this so setter are we going to set the ID once if it is already set no right likewise are we going to change the teacher's name if it is already set no right so do we want a setter for ID and name know so we are so we don't want any sucker but but we want a getter I'm sorry we want a setter for the salary because today the teacher might be drawing $500 but tomorrow because of her because of her you know progress and much better experience she is going to draw $700 so we have to be able to account for that right so I'm going to say public I am going to just set salary by passing int salary and I'm going to say this dot salary equals salary you I hope you understand what's going on here don't be twisted if you see sandwich angry twice I hope I really hope you know update the salary all right now I should say sector sundry not update the salary I would say set the salary okay so now that we have taken care of the teacher object the student object here we just if you remember we just did we just set the values we never got the values right so do you want to get the grade yes do you want to get the name of the student yes ID of the student yes please total yes please paid yes so how do you do that I mean yeah you can start typing every single thing but you know what there is a shortcut if you remember so I am going to press ctrl alt and insert now this would give me this I would say just get er and I'm going to get for all the fields and just hit OK now basically it's going to return every single things so here this would return the return ID of the student right oh man is tu de NT yeah now this get mean what is getting I'm going to do it's going to return the name of the student okay now get great it's what is this get great going to do this get grade is going to return the grade of the student you know when I say grade I am talking about the class you know class grade 1 grade 2 I'm not talking about you know a grade B grade hopefully if that makes sense to you guys I know it's a dumb way to explain that because you know when we say grade it's already an integer that you guys already realize that anyway return a C speed by the student man I hate it when I type things like that okay now this is going to return what the total fees of the student okay now that we have taken care of all the setters and getters but we are still remaining to do certain things which I'll be covering you know okay let me just do this thing now I will say you know what let me just do it later once I start once after I create me to school class now school if we create a new school a school as teachers school has students the school will have you know how much ever it has earned it has spent let us let us try and take care of this so let me create a new java class called as school okay now a school has rightfully it has teachers so let's account for teachers I'm going to say private teacher and I would say teacher that's it you know a school basically has teachers and students right now when I say something like this you have to realize that the school is going to contain multiple teachers at the same time you should also realize that the score is going to contain multiple student okay but but we are accounting for just one teacher and one student which is kind of like a bad thing to do and then let us let us come back to that but but before we come back we are we are to take care of the total money earned now so it's going to contain private int total money earned okay and then let us see so the school is now also going to contain total money spent right private int total money spent all right so now like I said before we have to take into consideration the concept that a school can have many teachers okay let me write it here the school can have many teachers correct many students right so if we do something like this this is not absolutely a good way to account for all the teachers what is a good way well think about this guys I I asked you a question how do I have count how do I create multiple teachers well you can tell me Rach sure you can you would tell me maybe let's just create teacher 1 comma teacher 2 comma teacher three comma so on until how many other teachers that you want to have in your school yeah that's a good idea but it's a bad bad idea I'll tell you why I mean yeah I appreciate you for telling me this but if you recall what I define what I talked about in the previous video when we when we when we considered talking about arrays you wouldn't tell me this then what would you say well probably since I gave you the pointer and a hint you would say Rock you know what you have to create an array you know what Rock says you have to create an array of students you know what you have to create an array of student array of teachers yes but what if what if you know I don't know the number of teachers today I have three teachers in my school tomorrow I will have four teachers because array when we say array see we have to define something like this array equals new teacher and then set the size as Phi or four or or or you know 36 whatever what if I don't know the number of teachers in my school today I have three tomorrow I I get a lot of students so I keep adding more teachers to my school you know that number is going to keep changing now what should I do for that how do i account for that well think about this so the answer is is obviously not erase because we don't know exactly how many students are going to be there how many teachers are going to be there in my school ok now what is a good way is by making use of what is called as an array list which I have not discussed to you guys so far so let us talk about array list in clip implements teachers and students using an ArrayList okay so what do I mean by that let's let's just think about this for a second now you know I said it's going to be an ArrayList and everything on the side you know what I'm going to create a new Java class I'll call it delete mean ok so this class is going to be deleted I'll this is just for the sake of our demonstration and to make sure you understand what is list now you know what guys I am going to create a new type of object that you have never ever seen in your life that can contain multiple numbers okay multiple numbers okay now so you know that array is also a container of multiple numbers but but actually array is a container of yes I every container of multiple numbers but the count of the numbers is defining right if you are talking about an array the count of the numbers are defined correct so like I showed you before new teacher file new int of seven you have to define the value but what if I don't know how do I automatically allow a new location to be added you know for that we have a real list it's actually called as a list I am NOT going to confuse you too much I'm going to talk about it later if you are interested then please comment in the description maybe I'm sorry please come it in your comment box below then maybe I'll try and explain what is an ArrayList I'm sorry a different types of list you know linkedlist ArrayList and all of that so anyway at this point I am just trying to help you guys by trying to you know teach you array you know teaching you I realized okay comment in the description if you want me to talk about that in a different separate video so let's first understand what is going on list let's create something that's called as a list as soon as I hit enter Java automatically does this job for me import java.util list that's a good thing this time you know what I'm going to do I'm going to say integer in a capital letter please understand I am NOT doing something like this no I'm doing in teacher okay then I would say numbers okay and I would say something like this new ArrayList okay now I still have to do what I list this thing also got imported notice on the left hand side it is list on the right hand side it is ArrayList now what is this Rock that is your question I know that but right now I'll show you a very good way to incorporate list and understand it so now I am just trying to use this numbers object and I would say add and say five okay next I am going to say numbers dot add 32 and say next time numbers dot add 45 again and say numbers dot add 76 whatever you know keep adding as many numbers as you wish until you die it still works haha right yeah you know so that is the power of lists but since I will show you the full power you know what I'm going to say s out system dot out dot println and same numbers now what's going to happen if I just right click and run is tada you see that five thirty to forty point seven to six this is the elements contained in the early list and I'm just making sure if my recording is continuing anyway so this when you do something like this notice you never said how many elements are there in the list okay you never said that all you did was you said numbers not add numbers not add randomly you kept adding and you could repeat this for the rest of your life and it still would probably work yeah right okay so now if I if I run again it's showing me all the elements that is added okay now you should remember one thing when I set integers here basically I am creating a list that can contain just integers if I say float basically I am trying to free you know when I do float it is trying to yeah if I do float it is trying to add all the floating-point numbers to the list if I do strength it is trying to add all the string values to the list so that is the basic introduction to the list now in our context we are trying to add what many teachers write so I'm going to say teachers got it anyway since the explenation is over I'm going to delete this class now let's get back so private list of teacher so what is this list of teacher doing if I just do alt enter import class so we just imported the list ql to our java our Java class here the school glass anyway now list of teacher would ensure that there are many teachers so I'm going to say teachers list off student would ensure that there are many students in the school so I'm going to say students all right now let us proceed further now what are the requirements so far we have created this teacher student and all of that you know what this time I am going to create a new constructor by doing ctrl alt insert I'm sorry yeah ctrl alt insert what function art insert what what is the shortcut I just forgot I just told you guys how could I do this generate so I'm sorry it's alt plus insert yeah it's all without any control I am sorry guys so control if I do if I do generate it's going to give me constructor getter setter what do you want I would say constructor and then I am going to choose what do I want in my fields I mean what do I want as arguments so I am going to say these two initially teachers a list of teacher and list of students okay public school list of teachers now when you pass as an argument you are going to pass another list of teachers when you pass an array list of teachers you pass another list of students so now you are setting it here you know this is created as soon as a new school object is created a new school object is created so parent teachers is the list of teachers in the school okay this is a list of students in the school okay got it now let me ask you this question what is the total money earned by the school as soon as the school is created if you said zero you're right so total money earned zero right likewise what is the total money spent that's also going to be zero right now let us look at this we have created a new school object and the image initialized all the values all I am going to do right now if I am going to do getter and setter for everything okay I'm going to do getter and setter for everything so if I do if I do you know alt and insert getter and setter I am going to choose everything by the way when you create a school can you can you alter teachers yes you can add teachers tonight can you add students yes you can add students to the school can you alter money earned yes can you alter money spent yes so that's why I Ida I just created getter and setter both at the same time okay now when you say public list get teachers what is this function going to do returns the list of teachers in the school right returns the list of teachers in the school likewise what is set teachers going to do set teachers is basically going to you know you know what I'm going to do I would say update teacher because once teachers are set it's over I would say add a teacher add teacher and I am NOT going to pass in a list of teachers I am going to just pass in a teacher object okay a teacher object where is this teacher object coming from the seats object is coming from our teacher class that we created here okay and by the way if you just do control click and take back now so what should this function do as a teacher to the school right as a teacher to the school that's what's happening here okay now Parham I would say teacher the teacher to be added all right now how do we add another teacher to the school how do I do it well guides if you remember it's adding to the ArrayList think about it what is a teacher you know we have lists of teachers right we want to add another teacher how do I do it so I do it by the simplest way this is I'll say teachers dot add who are you going to add another teacher okay so that is the add method that's going to take care of its job now look at this method get students what is the get students method going to do it is going to return the first of students right it's going to return the list of students in the school again I am going to do something different here so it's not such students I would call it update students or add a student add student now it's going to take which object is it going to take the list object no it's just going to take a single student object right student and this dot student equals student oh this does I should say students dot add guys do you remember what's going on it's like it's very similar to the integer thing that we did I took the ArrayList name and I said dot add which would add the element to the ArrayList you know this students element if you look at it if you look at what information it's providing it says private list student students so it's a list of students okay so if you are trying to add to the list it is supposed to be a student object only okay if you are not clear with this right in the description I am trying to help you out in a much elegant manner hopefully this I should do the trick however anyway I'll say public int get total money earned so it's straightforward what is this oh I forgot to add comment here so what is this method going to do it is going to just add a student to the school and the student argument what is it going to say the student to be added okay next let us look at get total money earned so it's straight forward as what it says it's going to return the total money earned by the school now set total money order you know what I will do I don't like to call it set I would rather call it update total money earned right update total money earned and then you say a money you accept money earned and total money earned Plus remember what is happening here I mean like it's similar to the student ah you know fees paid case it keeps adding the fees paid so likewise here also update total money earned is going to you know update the total money earned oh yeah now it's pocket alright basically adds the total money five score okay so this is the money that's supposed to be added next get the total money spent so let's look at this so it basically returns the total money spent right okay by the school obviously now let us look at this sec total money spent now what is the total money spent initially both of them are zero right total money earned or spent is zero now what would be the total money spent it's going to be actually not set total money spent it does update total money spent okay and then money spent so let us say how do i how do i properly make this function work come on guys think about it so this method first of all what is the role of this method it is going to update the money that is spent by the school right so money spent is the money what is that one thing that we are considering when we are talking about spending money by the school I said it is just going to be the teacher's salary remember I am NOT going to take care of any utility bills current bill water bill I mean whatever bill there is it I am NOT going to consider all of that the only way that the school can spend money is by giving money to teachers right so update the money that is spent by the school which is the money that is given out as salary to teachers right which is the money which is the salary given by the school to its teachers correct so that is the the money spent by a score okay so now how do I do this update money spent so basically this is going to be total money earned - - money spent correct I'll be capitalize it I will do this money spent yeah and basically this time I am going to put an equals here which means which means subtract is you know this is equivalent if you know I am presuming that you know all the way that this is equivalent to total money total money earned equals total earned money and - money spent so this entire line is equal to the line that I have written here cut it all right I don't want this line it's pretty big so this is simple so that is our school class so so far we have successfully created all the three classes student class teacher class and school class what we are get to create is the fact that we we are we have be able created any main class to test and run so let's update a new Java class called main okay and then I'll say PS we M all right awesome so - to start with first let us create a new teacher object so I would say teacher and I will call this let's say Lizzie okay so here is our teacher so she is a very good teacher and I would say new teacher now notice as soon as I don't type anything it's asking me for the ID okay so teacher ID is one to start with the name of the teacher is Lizzie LIC dy okay and the salary that Lizzie earns is about 500 okay next let us create another teacher called Melissa okay so she is a new teacher whose ID is - and her name being Melissa you see what's going on here and she is kind of elder to Lizzie and she makes about 700 bucks I know I'm really under estimating teachers I never with no disrespect though you know I am really sorry just for the sake of for the sake of just demonstration alright so we have two teachers if you want let's try with another teacher this time let's try and make a male teacher so our male teacher is wunderhorn wunderhorn okay so you know all these names are just coming off the top of my head it's funny so it's a new teacher right and his ID is three years re a nd er hor n that's what his name is and the salary that he would be making is kind of in between it's let's say 600 bucks so now we have taken care of the teachers now let us try and create a new student student now let us create a new student called tomorrow or tamasha whatever is a new student I don't have to waste much time on student's name and everything so crap so students ID is 1 notice there is a difference in teachers ID and students ID you know when you create a new teacher object the ID is going to just map for the teacher when you create a new student object ID is going to map for the student ok and next so next object is name of the student let's say tamasa yeah that's funny Thomas ah ok um and you have to talk about her grade so she is in fourth grade good student not a bad student yeah so obviously how could I forget mr. Rock right so this guy is a very good student whose ID is 2 and name being rocks it [Music] was Dave right funny and then um so what grade is he doing actually this guy's grade is way beyond bounds but anyway let's put him 12 yeah it's a good good student he and I know that for sure hopefully or at least comment down if you have a mean if you with you if you if you differ for my opinion anyway so student ah let's create another student rabi ok new student whose ID is 3 and mean being Rabi great being fifth grade okay so we've created three students and three teachers which is pretty good right but but you know what to create a school okay so let's first try and create a new school object at the same time school we'll call it high you know GPS Glendora high school whatever or Riverside High School wherever that is is a new school now look at this the school object requires you to pass a list of teachers a list of students right so so so let us first create a list of teachers so I'm going to say list of teachers okay and and you know we'll call teachers list awesome so it'll easy helps me week to do that is a new teacher I'm sorry is a new is a new what realist that's it now let us keep adding to the list so teacher list dot add Lizzy okay teachers list dot add Melissa and teachers list dot add wonderful so now that we have added to the list of teachers at the same time let us create another list of students because that is what is required for a school to start so let's star for students okay we'll call it students list and let's it's it's a new ArrayList is a new ready list okay and then let's keep adding a student list dot add tamasha right and let's let's keep adding student list dot add rock ships okay rhaggy got added student list dot ad russia--the come on yeah so here we have so the list of students and teachers now when we want to create a new school we all we have to do is at this point students list teachers we have to pass the teachers list and students list now that GHS school is created okay just a check just to check if the school is really functioning and if it is created what I'm going to do is I'm going to say GHS dark get total money earned if it returns zero you know what I am going to encapsulate it with s out system dot out dot println why I mean I should have told you that notice it said you are ignoring the result of school dot get total money earned so how to not ignore usually surround it with eyes out so you will be able to print out that value so if it is zero right the total money earned as soon as a new school is created what is the total money earned zero why because we set that value here in our constructor remember total money earned is zero so I'm expecting let me add a little bit of text GHS has earned I'm expecting zero if you guys are expecting the same let us see if they are all right tada GHS has earned zero let's put a dollar sign which would make it more attractive yep so GHS has earned zero which is pretty cool right now it means it means a lot of things it means that the school object is created which in turn means our list is correct which in turn means our student list is correct our teachers list is correct so so far we have created a new school object with teachers list and students list and yeah I mean we have a zero rupees I'm sorry zero dollars I you know I kind of talked about dollars it would be sometimes you know not bad yeah so um yeah that that is the initial starting point and you know will then start you know start making payment fees payments and fees recovery and everything all right now we have created this new ghs object right this school object so let's make first of all tomasa you know let's make tamasha paid the school fees okay so I would say tamasha which is the name of the student from here you know tamasha dot pay fees do we have a pay fees method no right so first of all if that is the case we have to keep a track of you know we have to first of all create a DP is method so let's go back to student and let's create a new function called public wide pay fees which would accept an integer as an argument and fees as a an argument okay an integer are fees as an argument and then so you know base the selected amount as fees to school now what happens inside the pay fees method think about it so what happens is basically fees paid is going to get updated right so fees paid is going to get updated all notice we have Update fees paid method okay so update fees pay method and Pacey's method are going to be the same but you know what I like this pay fees name I think you know I should have kept it pay fees in the first place itself okay ah pay fees let's get rid of this pay fees here that's it all right so see if if there is a pay fees method once if the payee is method is called what is going to happen is it's going to update the fees paid and then remaining is going to be get these paid get okay I create another method called public int get remaining fees okay so get remaining fees is basically going to subtract from total fees right that is piece total - fees paid and I'm going to return so that is getting meaning fees method return the remaining fees okay now let us ah let's make toss of pay fees let's say tamasa dot pay fees now how much this tamasha have to pay to the school let us assume that Thomas ah has paid $5,000 as piece to the school now if I just run this nothing different is going to happen now let us look at this yes guesses as earn zero you know what let me put this line in the next here even if I do that still it wouldn't do anything why because because we haven't done anything to pay fees method so let us go back I mean yeah we said update the fees that's it we didn't update the variable of the school right so we have to update number one we have to update the the the fees that the school has received correct we have to update the total money earned by the school so what I am going to do is I am going to first of all try to okay so if I can I do something like this just to make things clear for you guys I am going to make a method static so which method is going to be static I am going to make update total money earned static you will understand what is static by the way ah so here we say we have non static field money earned cannot be referenced from the static context so let us make ain't static static int and I make this also a as a static int total money earned total money spent they are all static and yeah I mean whenever there is a requirement I will come back and and make it static so we don't run into problems like this okay now what is the purpose of static you see with static we can access the method otherwise we have to have an instance of the method what do I mean by that what do I mean is I can say something like this now school dot update total money earned you see if I want to access a method like this then I have to declare it static if at all I was if I want to access let's say I don't have this method static in that case if I have to access the method then what I could do is I should say DHS dot get total money earned I mean that itself is gone you know so basically you have to update it in Basie's method which does not have access to g g HS variable so how do you update it you have to make it as a static method so now if we do something like this school dot update total money earned okay update total money earned it's going to be fees paid now if you pass this fee is paid and now if we go back and run Terron you see g HS has earned $5,000 now that is a good thing right if we try to make again let's make Roxas pay his fees to the school rock said dot pay fees okay the fees he is supposed to pay is six thousand dollars okay now if I if I if I try to do the same thing again okay this time as you could expect it should show eleven thousand not dollars you see this is pretty good right and just to avoid confusion let me get rid of this line aha you see ths has earned eleven thousand dollars which is pretty awesome now let us make GHS pay the teacher salary so how do we make the GHS pay Peter Stanley well you can you can again again you have to do the same thing for teachers so first of all let us figure out what we should do now I'll write another line making something like this making GHS pay salary okay then now how do you make GHS pay salary to teachers well the first step is let us go back to the teacher class and [Music] let us create another thing another method here called public wide okay public void receive payments or receive to see you or man receive salary okay so so let us try to receive salary then if you want to receive salary you have to pass in some value and you you will you will pass that value and accept that value called receive salary and I will do something like this adds to the salary okay then the next step is removes from the total money earned to G H s okay ah to the school actually I won't say GHS from the school removes from the total money earned by the school yeah sometimes I write some junk grammar which is ridiculous yeah um so now if we do receive salary what happens is yes it is going to update the salary right oh look at this we have just set the salary but we have never we have never told the money earned right so I should create another field called private end salary earned okay now and I and since I've created it I should declare that value initially when when the teacher is created what is the salary it's nothing right so salary earned is going to be zero correct now receive salary so salary earned plus equals salary so now that it has added to the salary adds to the salary right adds to salary earned and then we are not finished yet we have to subtract from the school correct so school dot update total money earned you know what it's not updated to money earned it is supposed to be in the school yeah so update owe to the money spank since this method is not static notice it's not showing me here so if I make this method static public static okay now notice what happens school update total money spent what is the total money spent by the school right now it's just the salary of the staff now let us look at this making G hexes making school pay salary okay now let us pay the salary to the name of some teacher let us find the teacher that is let's see okay so we have Lizzy dot receive salary and what is her salary we don't know right but we can find a way there is a way to receive her salary yes you can go back and check out her salary is five hundred but you don't want to do that you can dynamically receive and no I mean you can dynamically get to know what Lizzy's salary ears so what I will do is Lizzy dot get salary notice where is this coming from you see get salary is this method all right so let us go back and check out again s out ghs has paid or or has spent for salary to you know to to basically the name of the employee right Lindsay dot get name this would basically find him print her name and and has spent for salary to Lizzie and now contains and now has and now has how much money come on guys how much money it is GSS dot get total money earned let us look at this and now has let me give some space and now has dollars actually speaking this is not the right way to use the program you know you don't hard-code it like this you basically create a text user interface which I'm not going to deal with at this point you know my intention was to show you how to create a class how to use methods you know how to make use of everything but my intention was not to show you at this point yeah at this point my intention is definitely not to show you how to create a text user interface or a graphical user interface you know this is absolutely not the right way you know this is just for the sake of making use of the values that we have created and I'm doing this you should actually create a new text user interface that you know if time permits me I talk about it later on but yeah I mean that's the idea behind it this is not the right way to keep adding and you know this is just hard coding everything which is not a good thing to do by the way but anyway for the sake of our understanding this should be the trick this should do the trick yeah so look at this DHS as has earned eleven thousand dollars and then ths has been salary for Lizzie and now has ten thousand five hundred which is pretty cool right so if you want to do the same thing so let us pay salary for you know what is the name of another teacher okay let's make it pay for winder horn dot pay salary or receive salary and then wunderhorn dot get salary okay now if you just print out the same thing again the SS has been salary is spent for salary to wunderhorn dot get name and now has DHS has total this thing so let us look at this look at the DHS has spent for salary to wunderhorn and now has 9900 so that was Lander Hans salary how much was it 600 bucks yeah okay so this one Don Hahn is 600 bucks correct so that's it it's doing the right thing and I want to give you some quick pointers before we conclude this so this actually you should build a text user interface and then your prod you know your entire program would be perfect you can keep adding subtracting probably if time permits I'll build one for you guys maybe I'll create you know I mean yeah I don't want to commit too much but anyway like you know sometimes if I keep doing all of that I won't be able to focus on other things which I thought I should cover for you guys right so I mean you can learn that that's not a big deal you have to put an infinite while loop and and keep asking for the values that's not my focus here but from that I wanted to talk about one more thing called as the two strengths okay let us let us talk about that and rack up this entire tutorial so yeah so you know what I can do control o enter this dialog shows up and if I just say two string and hit OK this thing magically happens what is this well this is a way to to represent a object so let us let us look at this now return we want to return the name of the student okay and then the ID of the student and the total fee is paid by the student okay right now let me before to string let me show you this one thing is out what is the name of the student let's say rock okay and if I just print it out just focus on the last line you see school dot management system dot student at seven for a one for some junk is there right which we don't even give a damn about right so now let us make it more meaningful so it becomes you know for us to easily understand how do I make it more meaningful well you have to what is called as override the two string method so let's overwrite the two string method to match our requirements okay return name okay name plus let me do something like this students name is this okay and then student okay let me do total fees paid so far what is my total fees page so far what is the variable that I've used to keep a track of it T speed right so I will use it again here fee is paid okay then let's put dollar symbols appropriately facebait is this okay in the next line you know what in the next line will say if you want you can use an X line or in my case I don't want it I will do something like this fee is remaining if you want to please I think that should be it you know that let's not worry too much about this thing here I just wanted to show you the power of two string overriding now let us go back and try and run it again tada look at this student's name is rocks it was a wave total fees paid so far is six thousand dollars now that is a much better thing right to be displayed instead of some junk on screen so that is why we need to override to string okay and then let us do the same for teacher and then we'll wrap up this video so if I do ctrl o and to string I would say return what should I return name of the teacher name of the teacher in the name of the teacher is see as long as you don't overwrite to string you are always almost going to end up with you know that junk value which is usually the memory location of the object that we are operating but that you know I am that's not our concern here we want it to be displaying good stuff so if you want it to display good stuff then you have to override the to string method okay name of the teacher name right and then in the next line total salary earned so far what is the total salary earned by this teacher so far it's going to be dollar plus salary earned and that's it now if I just go to me and is out let us print some from teachers named Thomas eyes a teacher right so let's print it out oops how did I type student's name but anyway that's my spell mistake that I did the tomasa total fees paid so far Oh Thomas is a student then oh my bad my bad tamasha is a student my bad so let us see let us see Melissa yeah we haven't used money saipan right so how much money has Melissa earned so far Melissa I would have earned nothing so that's why we have $0 because we need pay Melissa innocent right so we did pay Melissa her you know we'll make Melissa receive her payment if you want I can make that as well just to prove it to you that everything is intact yeah so Melissa dot the sieve salary Melissa dot get salary now that's it if we run this this time you see Melissa has earned a total of seven hundred bucks which is pretty decent right yeah that is the end I think yeah yeah that should be it I'm just trying to fix this gap issue I think you will be able to do it on your own yeah total correct so this time if we run it's going to be perfect awesome so finally at the end of the day we have built a a a school management system that tracks students teachers and oops their funds yeah that's it guys if you like this video give it a thumbs up and I'm pretty positive some of you some of you have certain doubts on why I did that why I did this comment in the comment box and I will try to respond to you guys and by the way let's make use of real quick let's make use of this one method at least add teacher because it's a list right so school DHS has now create you know the school has now found out that there is supposed to be another teacher right now here we say another teacher and we'll call Megan okay so this Megan is a is a new teacher to the school and she is represented by ID six name being Megan and her salary being you know nine hundred bucks which is pretty good next how do I add Mabel to the school's teachers list pretty simple so you say gh s dot add a teacher and then you choose Megan okay and what is it oh I did add student I'm sorry I should have said add teacher okay at the same applies for student as well instead of creating a new teacher you would create a student and then choose ths dot add student that would be it okay that is the basic intro to are getting around with classes we've created a bunch of stuff and don't worry I'll create I mean you'll be able to find this on the github repository that would be linked in the description below that's a guys have a great day thanks watching like this video subscribe and share [Music]
Info
Channel: Rakshith Vasudev
Views: 320,154
Rating: undefined out of 5
Keywords: school management system, java, OOP in Java, Application of OOP in java, setting up app in java, School management system in java, schoo management, java application of Object oriented programming, oop building in java, building school in java, java school, java applications, Application OOPS, core java tutorial, java example programs, object oriented programming tutorial, java step by step programming, building a basic class in java, oop system simplified
Id: e0X00EoFQbE
Channel Id: undefined
Length: 109min 16sec (6556 seconds)
Published: Tue Apr 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.