Introduction to Object Oriented Programming Implementation

Hello folks, this is Vulphere. Today I will show you how to create a simple implementation of Object Oriented Programming.

Special thanks to my lecturer who teaches and introduces me to this lecture.

Here included the complete codes for this implementation:
/*
* Copyright (c) 2018, praktek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

package firstjava;

/**
*
* @author praktek
*/
public class Mhs {
private String nim;
public String nama;
public String alamat;

public void setNim(String pNim) {
this.nim = pNim;
}

public String getNim() {
return this.nim;
}
}

Form:

/*
* Copyright (c) 2018, praktek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

package firstjava;

/**
*
* @author praktek
*/
public class frmMhs {
public static void main(String[] arg){
ctrMhs oMhs = new ctrMhs();

System.out.print("\nData Awal Mahasiswa\n");
System.out.println("Nim: "+oMhs.getNim());
System.out.println("Nama: "+oMhs.getDataMhs() [1]);
System.out.println("Alamat: "+oMhs.getDataMhs() [2]);

String[] aData = new String[3];
aData[0] = "1712501202";
aData[1] = "Vulp Rainer";
aData[2] = "Blok M";
oMhs.setDataMhs(aData);

System.out.print("\nData Baru Mahasiswa\n");
System.out.println("Nim: "+oMhs.getNim());
System.out.println("Nama: "+oMhs.getDataMhs() [1]);
System.out.println("Alamat: "+oMhs.getDataMhs() [2]);
}
}

and ctr

/*
* Copyright (c) 2018, praktek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

package firstjava;

/**
*
* @author praktek
*/
public class ctrMhs {
private final Mhs oMhs;
ctrMhs(){
oMhs = new Mhs();
oMhs.setNim("1712501202");
oMhs.nama = "Vulp Rainer";
oMhs.alamat = "Ciledug";
}
public void setNim(String pNim) {
oMhs.setNim(pNim);
}
public String getNim(){
return oMhs.getNim();
}
public String[] getDataMhs(){
String[] vData = new String[3];
vData[0] = oMhs.getNim();
vData[1] = oMhs.nama;
vData[2] = oMhs.alamat;
return vData;
}
public void setDataMhs(String[] pData){
oMhs.setNim(pData[0]);
oMhs.nama = pData[1];
oMhs.alamat = pData[2];
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *