RECORD
B. Praktek
Membuat Rekaman Objek
?html>
?head>
?title> Membuat Rekaman Objek ?/title>
?/head>
?body>
?script language="JavaScript">
?!--
var Record = new Array();
function Mahasiswa (npm, nama, prodi, jenjang) {
// Properti
this.npm = npm;
this.nama = nama;
this.prodi = prodi;
this.jenjang = jenjang;
// Metode
this.LihatRecordMahasiswa = LihatRecordMahasiswa;
}
function LihatRecordMahasiswa() {
document.write("?td>" + this.npm + "?/td>");
document.write("?td>" + this.nama + "?/td>");
document.write("?td>" + this.prodi + "?/td>");
document.write("?td>" + this.jenjang + "?/td>");
}
//mengisi data
Record[0] = new Mahasiswa ("43E001", "Dani", "TI", "SI");
Record[1] = new Mahasiswa ("43E001", "Doni", "TI", "SI");
Record[2] = new Mahasiswa ("43E001", "Dina", "TI", "SI");
Record[3] = new Mahasiswa ("43E001", "Dini", "TI", "SI");
//menampilkan data
document.write("?table border = '1'>");
document.write("?th>NPM?/th> ?th>Nama?/th>");
document.write("?th>Prodi?/th> ?th>Jenjang?/th> ?br>");
for (i=0; i ? Record.length; i++)
{
document.write("?tr>");
Record[i].LihatRecordMahasiswa();
document.write("?/tr>");
}
document.write("?/table> ?br>");
document.write("?table border = '1'>");
document.write("?th>NPM?/th> ?th>Nama?/th>");
document.write("?th>Prodi?/th> ?th>Jenjang?/th> ?br>");
for (i=0; i ? Record.length; i++)
{
document.write("?tr>");
Record[i].npm;
document.write("?/tr>");
}
document.write("?/table>");
//-->
?/script>
?/body>
?/html>
Program Entri Data Pegawai
?html>
?head>?title>Memanipulasi data pegawai?/title>
?script language = "javascript" type="text/javascript">
?!--
var DBPegawai = new Array();
function pegawai(Fields_NIP,
Fields_Nama,
Fields_Gaji_Per_Jam,
Fields_Jam_Kerja,
Fields_Gaji_Total)
{
this.NIP = Fields_NIP;
this.Nama = Fields_Nama;
this.Gaji_Jam = Fields_Gaji_Per_Jam;
this.Jam_Kerja= Fields_Gaji_Total;
}
function input pegawai()
{
var Nama,Gaji_Per_Jam,Jam_Kerja,Gaji;
while ( NIP = window.prompt("Ketikan NIP (Nomor Induk Karyawan)
\n\n Click 'cancel' untuk Berhenti !!."))
{
Nama = window.prompt("Nama Pegawai :");
Gaji_Per_Jam = parseInt(window.prompt("Gaji Per Jam:"));
Jam_Kerja = parseInt(window.prompt("Jumlah Jam Kerja:"));
Gaji = Gaji_Per_Jam * Jam_Kerja;
DBPegawai[DBPegawai.length] = new Pegawai(NIP,Nama,Gaji_Per_Jam,Jam_Kerja,Gaji);
}
ShowPegawai();
}
function ShowPegawai(){
document.write("?table border='1'>" +
"?tr>" +
"?th>NIP?/th>?th>Nama?/th>?th>Gaji Per Jam?/th>?th>Jam Kerja?/th>"+
"?th>Gaji Total?/th>" +
"?/tr>");
for (i=0; i ? DBPegawai.length; i++) {
document.write ("?tr>" +
" ?td>" + DBPegawai[i].NIP + "?/td>
" ?td>" + DBPegawai[i].Nama+ "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Gaji_Jam + "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Jam_Kerja + "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Gaji_Total + "?/td>" +
" ?/tr>");
}
document.write("?/table>");
}
//-->
?/script>
?/head>
?/body onload ="input Pegawai();">
?/body>
?/html>
Memanipulasi data pegawai
A. Landasan Teori
Record merupakan struktural data yang mengandung sekumpulan data atau fields yang berbeda jenis atau tipenya dan deklarasi Type record dapat dilakukan oleh user sendiri.
B. Praktek
Membuat Rekaman Objek
?html>
?head>
?title> Membuat Rekaman Objek ?/title>
?/head>
?body>
?script language="JavaScript">
?!--
var Record = new Array();
function Mahasiswa (npm, nama, prodi, jenjang) {
// Properti
this.npm = npm;
this.nama = nama;
this.prodi = prodi;
this.jenjang = jenjang;
// Metode
this.LihatRecordMahasiswa = LihatRecordMahasiswa;
}
function LihatRecordMahasiswa() {
document.write("?td>" + this.npm + "?/td>");
document.write("?td>" + this.nama + "?/td>");
document.write("?td>" + this.prodi + "?/td>");
document.write("?td>" + this.jenjang + "?/td>");
}
//mengisi data
Record[0] = new Mahasiswa ("43E001", "Dani", "TI", "SI");
Record[1] = new Mahasiswa ("43E001", "Doni", "TI", "SI");
Record[2] = new Mahasiswa ("43E001", "Dina", "TI", "SI");
Record[3] = new Mahasiswa ("43E001", "Dini", "TI", "SI");
//menampilkan data
document.write("?table border = '1'>");
document.write("?th>NPM?/th> ?th>Nama?/th>");
document.write("?th>Prodi?/th> ?th>Jenjang?/th> ?br>");
for (i=0; i ? Record.length; i++)
{
document.write("?tr>");
Record[i].LihatRecordMahasiswa();
document.write("?/tr>");
}
document.write("?/table> ?br>");
document.write("?table border = '1'>");
document.write("?th>NPM?/th> ?th>Nama?/th>");
document.write("?th>Prodi?/th> ?th>Jenjang?/th> ?br>");
for (i=0; i ? Record.length; i++)
{
document.write("?tr>");
Record[i].npm;
document.write("?/tr>");
}
document.write("?/table>");
//-->
?/script>
?/body>
?/html>
Program Entri Data Pegawai
?html>
?head>?title>Memanipulasi data pegawai?/title>
?script language = "javascript" type="text/javascript">
?!--
var DBPegawai = new Array();
function pegawai(Fields_NIP,
Fields_Nama,
Fields_Gaji_Per_Jam,
Fields_Jam_Kerja,
Fields_Gaji_Total)
{
this.NIP = Fields_NIP;
this.Nama = Fields_Nama;
this.Gaji_Jam = Fields_Gaji_Per_Jam;
this.Jam_Kerja= Fields_Gaji_Total;
}
function input pegawai()
{
var Nama,Gaji_Per_Jam,Jam_Kerja,Gaji;
while ( NIP = window.prompt("Ketikan NIP (Nomor Induk Karyawan)
\n\n Click 'cancel' untuk Berhenti !!."))
{
Nama = window.prompt("Nama Pegawai :");
Gaji_Per_Jam = parseInt(window.prompt("Gaji Per Jam:"));
Jam_Kerja = parseInt(window.prompt("Jumlah Jam Kerja:"));
Gaji = Gaji_Per_Jam * Jam_Kerja;
DBPegawai[DBPegawai.length] = new Pegawai(NIP,Nama,Gaji_Per_Jam,Jam_Kerja,Gaji);
}
ShowPegawai();
}
function ShowPegawai(){
document.write("?table border='1'>" +
"?tr>" +
"?th>NIP?/th>?th>Nama?/th>?th>Gaji Per Jam?/th>?th>Jam Kerja?/th>"+
"?th>Gaji Total?/th>" +
"?/tr>");
for (i=0; i ? DBPegawai.length; i++) {
document.write ("?tr>" +
" ?td>" + DBPegawai[i].NIP + "?/td>
" ?td>" + DBPegawai[i].Nama+ "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Gaji_Jam + "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Jam_Kerja + "?/td>" +
" ?td align='right'>"+ DBPegawai[i].Gaji_Total + "?/td>" +
" ?/tr>");
}
document.write("?/table>");
}
//-->
?/script>
?/head>
?/body onload ="input Pegawai();">
?/body>
?/html>
Tidak ada komentar:
Posting Komentar