Showing posts with label kuliahan. Show all posts
Showing posts with label kuliahan. Show all posts

Thursday, 12 November 2009

Tugas Java Tentang If-else if-else

Soal:
Menggunakan if - else if - else
1. Nyatakan himpunan nilai numerik berikut ini 88, 26, 67, 92, 55, 49 sebagai grade A, B, C, D, E dengan ketentuan sebagi beriku:

Min Max Grade
0 39 E
40 55 D
56 79 C
80 89 B
90 100 A

2. Cetak grade yang sesuai untuk setiap nilai.
3. Tentukan Total nilai dan hitung rata-rata nilai.

Jawabanya:

public class grade{
public static void main(String[] arg){

int nilai[] = {88, 26, 67, 92,55,46};
float total = 0;
char grade='E';
for(int a=0; a < nilai.length; a++) {

if ( nilai[a] >= 0 && nilai[a] <= 39) {
grade = 'E';
}else if ( nilai[a] >= 40 && nilai[a] <= 55) {
grade = 'D';
}else if( nilai[a] >= 56 && nilai[a] <= 79){
grade = 'C';
}else if( nilai[a] >= 80 && nilai[a] <= 89){
grade = 'B';
}else if( nilai[a] >= 90 && nilai[a] <= 100){
grade = 'A';
}else {
System.out.print("!mposible...");
grade = '?';
}
System.out.println("Grade dari nilai " + nilai[a] + " adlh " + grade);
total = total + nilai[a];
}
System.out.println("Total Nilai " + total);
float rata2 = total / nilai.length;
System.out.println("Rata-rata Nilai " + rata2);
}
}

Sunday, 1 November 2009

Tugas Java dihari pertama!!!

Setelah cari-cari di google... akhirnya gw menemukan jawaban dari sebuah pertanyaan ini neEh..:
"Cari 3 jenis Aplikasi yang ditulis menggunakan bahasa Java (Desktop, Mobile, JEE, Webbase or Server), berserta Deskripsi, URL, dan Lisensinya"


gw nyarinya susah banget,,, maklum baru ngenal apa itu yang namanya java, waktu pun kepepet (karna udah lewat dari quota yang dikasih eNeF. tp gw ma edo tetep aja bandel ampe jam 20:00 masih aja ngonlinE.)... mudah mudahan sih jawabanya gak melenceng dari pertanyaan yang di inginkan ama dosen.

oke ini jawabanya:

---------------------------- Desktop
Nama: XNap - A P2P framework and client.
Deskripsi:
XNap is a Java plugin-based peer-to-peer (P2P) framework and client including an OpenNap plugin with multiple server support, as well as Gnutella, giFT (OpenFT), IRC, ICQ and an OverNet plugin. XNap provides resuming, chat, hotlist and a media library.
Link : http://xnap.sourceforge.net/
Lisensi: OpenSource

---------------------------- Mobile
Nama: SMS Me and You.
Deskripsi:
Protect your secret SMS with a password. SMS Me and You will protect
your SMS with a four digit numeric password. Everytime you will receive
a SMS the password screen will be prompted. No message will be saved,
and if you will refuse the SMS it will be immediately destroyed.
link: http://getjar.com/mobile/11641/sms-me-and-you/
lisensi: OpenSource.

---------------------------- Server
Nama: Java Chat Software.
Deskripsi:
AddonChat is full featured, real-time Java Chat Software that embeds seamlessly into your web site. Adding a chat room sets your site apart, giving visitors the opportunity to interact with you and each other — turning your site into a true online community. Because addonChat is hosted by us, you won't pay extra bandwidth or hosting fees. With version 8.0, addonChat continues to lead the industry in providing full featured, easy to use Java Chat Software.
link: http://www.addonchat.com/
lisensi: free (minimalis) and proprietary (with feature)

Wednesday, 28 October 2009

Menginstall postgreSQL di linux

Instalasi PostgreSQL

Tahap-tahapan Installasi PostgreSQL ini dalam bentuk Source.
Pertama-tama Download PostgreSQL Disini.
Karena dalam menginstal ini menggunakan user biasa maka dari itu kita harus membuatnya terlebih dahulu, berikut perintah untuk membuat user baru:


[root@localhost ~]# useradd pebriana
[root@localhost ~]# passwd pebriana
Changing password for user pebriana.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#


Tentukan lokasi instalasi PostgreSQL, misal di direktori /home/pebriana/ kemudian masuk sebagai user biasa,


[root@localhost ~]# su - pebriana
[pebriana@localhost ~]$


Ekstrak paket tarball (postgresql-8.0.0.tar.gz) hasil download dan diletakan di home direktori, dengan menjalankan perintah berikut ini:


[pebriana@localhost ~] tar -xzvf postgresql-8.4.1.tar.gz


pindah ke direktori hasil extrak tadi:


[pebriana@localhost ~]$ cd postgresql-8.4.1
[pebriana@localhost postgresql-8.4.1]$ ls
aclocal.m4 configure contrib doc HISTORY Makefile src
config configure.in COPYRIGHT GNUmakefile.in INSTALL README


Jalankan perintah berikut untuk configure PostgreSQL yang akan di install pada direktori /home/pebriana/pgsql:


[pebriana@localhost postgresql-8.4.1]$ ./configure –prefix=/home/pebriana/pgsql


Jalankan perintah make


[pebriana@localhost postgresql-8.4.1]$ make


tunggu beberapa saat Pada bagian akhir proses ini, jika tidak terjadi hal-hal yang tak diinginkan, seperti kurang beberapa library pendukung untuk install PostgreSQL atau proses make berjalan lancar akan muncul baris berikut ini:


make[1]: Leaving directory `/home/pebriana/postgresql-8.4.1/config'
All of PostgreSQL successfully made. Ready to install.


Berarti anda siap untuk instal PostgreSQL

Login sebagai root, kemudian jalankan proses installasi PostgreSQL


[pebriana@localhost ~]$ su
password:
[root@localhost ~]# make install


jika muncul seperti tampilan berikut ini. berarti PostgreSQL telah berhasil terinstal di Linux anda.

make[1]: Leaving directory `/home/pebriana/postgresql-8.4.1/config'
PostgreSQL installation complete.



Direktori data
Pada direktori data ini nantinya akan di simpan file-file konfigurasi PostgreSQL dan binary dari data anda.
untuk membuat direktori data berikut ini langkah-langkahnya:

[root@localhost ~]# su pebriana
password:
[pebriana@localhost ~]$ mkdir /home/pebriana/pgsqldata


ubah izin akses kepemilikan direktori data menjadi user yang anda inginkan.


[pebriana@localhost ~]$ chown pebriana.pebriana /home/pebriana/pgsqldata


Inisialisasi direktori data,

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/initdb -D /home/pebriana/pgsqldata/

The files belonging to this database system will be owned by user "pebriana".
This user must also own the server process.

fixing permissions on existing directory /home/pebriana/pgsqldata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /home/pebriana/pgsqldata/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/home/pebriana/pgsql/bin/postgres -D /home/pebriana/pgsqldata
or
/home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start


Jalankan service PostgreSQL:

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start
server starting


Mematikan Service PostgreSQL:

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start
waiting for server to shut down.... done
server stopped



Password Security dan konfigurasi file PostgreSQL

login sebagai user pebriana (user system) dan login ke databases pebriana (template1)

[pebriana@localhost ~]$ psql template1

Welcome to psql 8.1.11 (server 8.4.1), the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

WARNING: You are connected to a server with major version 8.4,
but your psql client is major version 8.1. Some backslash commands,
such as \d, might not work properly.
template1=#


Dari konsole database template1, jalankan perintah SQL untuk mengubah password user postgres. Kemudian keluar dari user terminal interactive PostgreSQL


template1=# alter user pebriana with password '12345';
ALTER ROLE
template1=# \q


konfigurasi file pg_hba.conf dan postgresql.conf yang berada di direktori data.
Edit file /home/pebriana/pgsqldata/pg_hba.conf pada 10 baris terakhir file ini, menjadi :


[pebriana@localhost ~]$ cd pgsqldata
[pebriana@localhost pgsqldata]$ vim pg_hba.conf


Installasi PostgreSQL

simpan dengan perintah wq

Edit file /home/pebriana/pgsqldata/postgresql.conf untuk TCP/IP connection, dengan cukup mengubah bagian berikut atau tepatnya mengaktifkan property berikut:


[pebriana@localhost pgsqldata]$ vim postgresql.conf


PostgreSQL
ganti localhost dengan * kemudian simpan dengan perintah wq
Setelah Selesai restart service PostgreSQL anda


[pebriana@localhost pgsqldata]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile restart


Buat User database PostgreSQL
Untuk membuat user baru pada database PostgreSQL haruslah yang membuat user postgres

Jalankan perintah berikut untuk buat user database PostgreSQL ( anda tidak harus sebagai root ) Misalkan user baru = apri.

[pebriana@localhost pgsqldata]$ createuser apri -P -U pebriana


option -p pada command diatas untuk sekaligus membuat password user baru,
sedangkan option -U postgres berarti hanya user postgres yang berhak membuat user baru
Selanjutnya anda diminta untuk memasukan password user_baru kemudian
apakah user_baru boleh membuat database ? ya
apakah user_baru boleh create user baru ? tentu saja tidak
Setelah itu masukan password dari user postgres pada database PostgreSQL


Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE


Membuat database
Berikut perintah user database untuk create database baru

[pebriana@localhost pgsqldata]$ createdb tes -U apri
password:
CREATE DATABASE

Perintah diatas berarti membuat database tes dimana pemilik database tersebut adalah user database apri.
Login ke database dengan PostgreSQL
Untuk login ke database PostgreSQL jalankan perintah berikut ini:

[pebriana@localhost pgsqldata]$ psql tes -U apri
Welcome to psql 8.1.11 (server 8.4.1), the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

WARNING: You are connected to a server with major version 8.4,
but your psql client is major version 8.1. Some backslash commands,
such as \d, might not work properly.

tes=>


Menghapus Database
Berikut perintah user database untuk menghapus/drop database

[pebriana@localhost pgsqldata]$ dropdb tes -U apri

Perintah diatas berarti menghapus database tes.