Jumat, 24 Juli 2009

nama hari

import javax.swing.JOptionPane;
class namahari2
{
public static void main(String[] args) throws Exception
{
String bil;
int nourut;
//DataInputStream dis = new DataInputStream (System.in);
bil=JOptionPane.showInputDialog("Masukkan Nomor Urut (0 s/d 6) :");
nourut=Integer.parseInt(bil);

switch (nourut)
{
case 0 :JOptionPane.showMessageDialog(null,"Hari Senin"); break;
case 1 :JOptionPane.showMessageDialog(null,"Hari Selasa"); break;
case 2 :JOptionPane.showMessageDialog(null,"Hari Rabu"); break;
case 3 :JOptionPane.showMessageDialog(null,"Hari Kamis"); break;
case 4 :JOptionPane.showMessageDialog(null,"Hari Jumat"); break;
case 5 :JOptionPane.showMessageDialog(null,"Hari Sabtu"); break;
case 6 :JOptionPane.showMessageDialog(null,"Hari Minggu"); break;
default : JOptionPane.showMessageDialog(null,"Salah Memasukan Nomor Urut !!!");
}
System.exit(0);
}
}

menghitung sisi miring

import javax.swing.JOptionPane;
class menghitung_sisimiring
{
public static void main(String[] args)throws Exception
{
String alas,tinggi;
int a,t;
double akar,kuadratA,kuadratT,jmlAT,sm;
alas=JOptionPane.showInputDialog("Alas :");
a=Integer.parseInt(alas);
tinggi=JOptionPane.showInputDialog("Tinggi :");
t=Integer.parseInt(tinggi);
kuadratA=Math.pow(a,2);
kuadratT=Math.pow(t,2);
jmlAT=kuadratA+kuadratT;
sm=Math.sqrt(jmlAT);
JOptionPane.showMessageDialog(null,"Sisi Miring ="+sm);
System.exit(0);
}
}

menentukan umur

import java.io.*;
class menentukan_umur_anak
{
public static void main(String[] args) throws Exception
{
DataInputStream dis = new DataInputStream (System.in);
int u;
String umur;
System.out.print("MASUKKAN UMUR ANDA:");
umur=dis.readLine();
u=Integer.parseInt(umur);
if ((u>=1)&&(u<=4))
{
System.out.println("Balita");
}
else
if ((u>=5)&&(u<=14))
{
System.out.println("Anak - Anak");
}
else
if ((u>=15)&&(u<=20))
{
System.out.println("Remaja");
}
else
if ((u>=21)&&(u<=39))
{
System.out.println("Dewasa");
}
else
if ((u>=40)&&(u<=60))
{
System.out.println("Tua");
}
else
if (u>=61)
{
System.out.println("Lansia");
}
}
}

menentukan umur( GUI)

import javax.swing.JOptionPane;
class menentukan_umur_anak2
{
public static void main(String[] args) throws Exception
{
int u;
String umur;
umur=JOptionPane.showInputDialog("Umur :");
u=Integer.parseInt(umur);
if ((u>=0)&&(u<=4))
{
JOptionPane.showMessageDialog(null,"Balita");
}
else
if ((u>=5)&&(u<=13))
{
JOptionPane.showMessageDialog(null,"Anak - Anak");
}
else
if ((u>=14)&&(u<=19))
{
JOptionPane.showMessageDialog(null,"Remaja");
}
else
if ((u>=20)&&(u<=35))
{
JOptionPane.showMessageDialog(null,"Dewasa");
}
else
if ((u>=36)&&(u<=60))
{
JOptionPane.showMessageDialog(null,"Tua");
}
else
if (u>=61)
{
JOptionPane.showMessageDialog(null,"Lansia");
}
System.exit(0);
}
}

menentukan golongan

import javax.swing.JOptionPane;
class menentukan_golongan
{
public static void main(String[] args) throws Exception
{
int a,b;
double c,d,e,f,g,h,i,j;
a=1000000;
b=1500000;
c=2000000;
d=1.67*a;
e=1.67*b;
f=1.67*c;
g=a*2;
h=b*2;
i=c*2;
j=0.1*c;
JOptionPane.showMessageDialog(null,"GOLONGAN ANDA"+"\n Gaji Golongan IA :"+a+
"\n Gaji Golongan IIA :"+b+"\n Gaji Golongan IIIA :"+c+"\n Gaji Golongan IB :"+d+
"\n Gaji Golongan IIB :"+e+"\n gaji Golongan IIIB :"+f+"\n Gaji Golongan IC :"+g+
"\n Gaji Golongan IIC :"+h+"\n Gaji Golongan IIIC :"+i+"\n Gaji Golongan IIIA mendapat tunjangan 10% :"+j);


}
}

memasukan data array

import java.io.*;
class memasukan_data_array
{
public static void main(String[] args)
{
DataInputStream dis=new DataInputStream(System.in);
try
{
int [ ] angka = new int[5];
System.out.println("Ketikan 5 buah angka : ");
System.out.println("==================== ");
for (int i=0;i {
System.out.println("Data ke-"+(i+1)+":");
angka [i] =Integer.parseInt (dis.readLine());
}
System.out.println();
System.out.println("Data yang di cari :");
System.out.println("=================");
int cari =Integer.parseInt(dis.readLine());
int ada = 0;
for (int i=0;(i {
if (angka[1]==cari)
{
ada++;
}
if (ada==0)
{
System.out.println("\nData yang dicari ada ");
ada++;
}
else
if (ada!=0)
{
System.out.println("\nData yang dicari tidak ada ");
ada++;
}
}
}
catch (Exception e)
{
System.out.println("Salah Input Data ! ! ! ! ");
}
}
}

matrik

import java.io.*;
class matrik
{
public static void main(String[] args) throws Exception
{
DataInputStream dis = new DataInputStream (System.in);
System.out.println( );

System.out.println( "Masukan Jumlah Baris : " );
int baris = Integer.parseInt (dis.readLine());
System.out.println( "Masukan Jumlah Baris : " );
int kolom = Integer.parseInt (dis.readLine());

int [ ] [ ] matrikA = new int [ baris ] [ kolom ] ;
int [ ] [ ] matrikB = new int [ baris ] [ kolom ] ;
int [ ] [ ] matrikC = new int [ baris ] [ kolom ] ;

System.out.println( );
System.out.println( "Masukan Data Matrik A : " );
System.out.println( "--------------------------------------" );
for (int i=0;i {
for (int j=0;j {
System.out.print( "Data Ke ["+(i+1)+"]"+"["+(j+1)+"]"+""+":"+"" );
matrikA [ i ] [ j ] =Integer.parseInt (dis.readLine());
}
}
System.out.println( );
System.out.println( "Masukan Data Matrik B : " );
System.out.println( "--------------------------------------" );
for (int i=0;i {
for (int j=0;j {
System.out.print( "Data Ke ["+(i+1)+"]"+"["+(j+1)+"]"+""+":"+"" );
matrikB [ i ] [ j ] =Integer.parseInt (dis.readLine());
}
}
System.out.println( );
System.out.println( "Masukan Data Matrik A : " );
System.out.println( "--------------------------------------" );
for (int i=0;i {
for (int j=0;j {
System.out.print (matrikA[ i ] [ j ] + " ");
}
System.out.println();
}
System.out.println( );
System.out.println( "Masukan Data Matrik B : " );
System.out.println( "--------------------------------------" );
for (int i=0;i {
for (int j=0;j {
System.out.print (matrikB[ i ] [ j ] + " ");
}
System.out.println();
}
for (int i=0;i {
for (int j=0;j {
matrikC[ i ] [ j ] =matrikA [ i ] [ j ] +matrikB [ i ] [ j ] ;
}

}
System.out.println();
System.out.println("Hasil Penjumlahan Matrik A + Matrik B : ");
System.out.println("-------------------------------------------------------------");
for (int i=0;i {
for (int j=0;j {
System.out.println(matrikC[ i ] [ j ] + " ");
}
System.out.println();
}
}
}

rumus mencari permukaan tabung

import javax.swing.JOptionPane;
class luas_tabung
{
public static void main(String[] args) throws Exception
{
String jari,tinggi;
int r,t;
double ;
jari=JOptionPane.showInputDialog("Jari-jari :");
r=Integer.parseInt(alas);
tinggi=JOptionPane.showInputDialog("Tinggi :");
t=Integer.parseInt(tinggi);
Ltabung=2*r*t

System.out.println("Luas Permukaan Tabung (pecahan): ");
System.out.println("Luas Permukaan Tabung (bulat): ");
}
}

biodata

import javax.swing.JOptionPane;
class latihan
{
public static void main(String[]args) throws Exception
{
String bil,bal;
bil=JOptionPane.showInputDialog("Masukkan Nama :");
bal=JOptionPane.showInputDialog("Masukkan Alamat :");
JOptionPane.showMessageDialog(null,"Nama Anda :"+bil+"Alamat Anda :"+bal);
System.exit(0);
}
}

Senin, 20 Juli 2009

kalkulator

import javax.swing.*;
import java.awt.event.*;
class kalkulator extends JFrame
{
JLabel angka1=new JLabel("Angka 1 :");
JLabel angka2=new JLabel("Angka 2 :");
JLabel hasilangka =new JLabel("Hasil :");
JLabel aritmatika =new JLabel("Operasi :");
JTextField nilai1=new JTextField(10);
JTextField nilai2=new JTextField(10);
JTextField hasil=new JTextField(10);

JButton operasi1=new JButton("+");
JButton operasi2=new JButton("-");
JButton operasi3=new JButton("*");
JButton operasi4=new JButton(":");
JButton exit=new JButton("Hitung Baru");

Kalkulator()
{
setTitle("ADI PUTRA");
setLocation(200,200);
setSize(180,210);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
void KomponenVisual()
{
getContentPane().add(angka1);
angka1.setBounds(10,10,60,20);
getContentPane().add(angka2);
angka2.setBounds(10,40,60,20);
getContentPane().add(hasilangka);
hasilangka.setBounds(10,120,60,20;
getContentPane().add(aritmatika);
aritmatika.setBounds(10,70,60,20);

getContentPane().add(nilai1);
nilai1.setBounds(70,10,90,20);
getContentPane().add(nilai2);
nilai2.setBounds(70,40,90,20);
getContentPane().add(hasil);
hasil.setBounds(70,120,90,20);

getContentPane().add(operasi1);
operasi1.setBounds(70,70,45,20);
getContentPane().add(operasi2);
operasi2.setBounds(115,70,45,20);
getContentPane().add(operasi3);
operasi3.setBounds(70,90,45,20);
getContentPane().add(operasi4);
operasi4.setBounds(115,90,45,20);

getContentPane().add(exit);
exit.setBounds(10,150,151,20);
setVisible(true);

}

void AksiReaksi()
{
operasi.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int
x=Integer.parseInt(nilai1.getText());
int
y=Integer.parseInt(nilai2.getText());
String tambah=String.valueOf(x+y);
hasil.setText(tambah);
}
});

operasi2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int
x=Integer.parseInt(nilai1.getText());
int
y=Integer.parseInt(nilai2.getText());
String tambah=String.valueOf(x-y);
hasil.setText(kurang);
}
});

operasi3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int
x=Integer.parseInt(nilai1.getText());
int
y=Integer.parseInt(nilai2.getText());
String tambah=String.valueOf(x*y);
hasil.setText(kali);
}
});

operasi4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int
x=Integer.parseInt(nilai1.getText());
int
y=Integer.parseInt(nilai2.getText());
String tambah=String.valueOf(x/y);
hasil.setText(bagi);
}
});

exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Kalkulator m1 = new Kalkulator();
m1.KomponenVisual();
m1.AksiReaksi();
}
});
}

public static void main(String args[])
{
Kalkulator e1 = new Kalkulator();
e1.KomponenVisual();
e1.AksiReaksi();

}
}

ganjil genap

import java.io.*;
class genap_ganjil
{
public static void main(String[] args) throws Exception
{
int x;
String bil;
DataInputStream dis = new DataInputStream (System.in);
System.out.println("Masukkan Angka :");
bil=dis.readLine();
x=Integer.parseInt(bil);
if ((x%2==0)&&(x%5==0))
{
System.out.println("Angka Tersebut Adalah Angka Genap Yang Habis Dibagi 5");
}
else
if ((x%2==0)&&(x%5==0))
{
System.out.println("Angka Tersebut Adalah Angka Ganjil Yang Habis Dibagi 5");
}
else
if ((x%2==0)&&(x%5!=1))
{
System.out.println("Angka Tersebut Adalah Angka Genap Yang Tidak Habis Dibagi 5");
}
else
if((x%2!=0)&&(x%5!=1))
{
System.out.println("Angka Tersebut Adalah Angka Ganjil Yang Tidak Habis Dibagi 5");
}
}
}

gaji

import javax.swing.JOptionPane;
class gaji
{
public static void main(String[] args) throws Exception
{

String gol,nama;
int tigaa,empatb,1a,1b,1c,4a,3a,4b;

nama=JOptionPane.showInputDialog("Masukkan Nama Anda : ");
//nama=Character.parseChar(nama);

gol=JOptionPane.showInputDialog("Masukkan Golongan Anda : ");
//IA,IB,IC,IVA,IIIA,IVB=Integer.parseInt(gol);

tigaa=(5000000/5)*2;
empatb=10000000+1250000;



if (gol=1a)
{
JOptionPane.showMessageDialog(null,"Gaji Anda Adalah 500.000");
}
else
if (gol=1b)
{
JOptionPane.showMessageDialog(null,"Gaji Anda Sebesar 1.000.000");
}
else
if (gol=1c)
{
JOptionPane.showMessageDialog(null,"Gaji Anda Sebesar 1.500.000");
}
else
if (gol=4a)
{
JOptionPane.showMessageDialog(null,"Gaji Anda Sebesar 5.000.000");
}
else
if (gol=3a)
JOptionPane.showMessageDialog(null,"Gaji Anda Sebesar : "+tigaa);
{
else
if (gol=4b)
{
JOptionPane.showMessageDialog(null,"Gaji Anda Sebesar : "+empatb);
}
else
JOptionPane.showMessageDiaolog(null,"Maaf Anda Tidak Terdaftar Kerja Kenapa Mau Gaji");
}



}
}

continous1

import javax.swing.JOptionPane;
class continou
{
public static void main(String[] args) throws Exception
{
String bil=" ";
for ( int cacah=10;cacah>=1 ;cacah--)
{
if (cacah%2==0)
{
continue;
}
bil=bil+cacah+" ";
}
JOptionPane.showMessageDialog(null,bil);
System.exit(0);
}
}

continous

import javax.swing.JOptionPane;
class continou2
{
public static void main(String[] args) throws Exception
{
String bil=" ";
for ( int cacah=10;cacah>=1 ;cacah--)
{
if (cacah%2==0)
{
continue;
}
bil=bil+cacah+" ";
}
JOptionPane.showMessageDialog(null,bil);
System.exit(0);
}
}

Menghitung luas permukaan dan volume balok

import java.io.*;
class cara_menghitung_luas_permukaan_dan_volume_balok
{
public static void main(String[] args) throws Exception
{
System.out.println("Nama : Made Adi Putra");
System.out.println("NIM : 080020015");

DataInputStream dis = new DataInputStream (System.in);
int x,y,z;
int lp,vol;
String pjg,lbr,tgi;
System.out.print("Masukkan Nilai X :");
pjg=dis.readLine();
x=Integer.parseInt(pjg);
System.out.print("Masukkan Nilai Y :");
lbr=dis.readLine();
y=Integer.parseInt(lbr);
System.out.print("Masukkan Nilai Z :");
tgi=dis.readLine();
z=Integer.parseInt(tgi);
lp=x*y*z;
vol=2*(x*y*z);
System.out.print("Luas Permukaan Balok :"+lp);
System.out.print("Volume Balok :"+vol);
System.exit(0);
}
}

Biodata dalam bentuk GUI

import javax.swing.JOptionPane;
class biodata
{
public static void main(String[] args) throws Exception
{
String nim, nama, alamat,telepon;
nim=JOptionPane.showInputDialog("NIM :");
nama=JOptionPane.showInputDialog("Nama :");
alamat=JOptionPane.showInputDialog("Alamat:");
telepon=JOptionPane.showInputDialog("Telepon :");
System.out.println("NIM :"+nim);
System.out.println("Nama :"+nama);
System.out.println("Alamat :"+alamat);
System.out.println("Telepon :"+telepon);
System.exit(0);
}
}

bilangan prima

import java.io.*;
class bilangan_prima
{
public static void main(String[] args) throws Exception
{
System.out.println("PROGRAM MENCARI BILANGAN PRIMA");
System.out.println("=================================");
System.out.println("Nama : MADE ADI PUTRA");
System.out.println("NIM : 080020015");
System.out.println("Jurusan : T. INFORMATIKA");
System.out.println("=================================");
String batas;
int i, x, y,b;
DataInputStream dis = new DataInputStream (System.in);
System.out.print("Masukkan batas angka : ");
batas=dis.readLine();
b=Integer.parseInt(batas);
System.out.println("Deret Bilangan Prima : ");
for (i=1; i < b; i++ )
{
for (x=2; x
{
y = i%x;
if (y==0)
{
break;
}
}
if(i == x)
{
System.out.print(" "+i);
}
}
}
}

bilangan GUI

import javax.swing.JOptionPane;
class bilangan
{
public static void main(String[] args) throws Exception
{
int x;
String bil;
bil=JOptionPane.showInputDialog("Masukkan Bilangan :");
x=Integer.parseInt(bil);
if (x%2==0)
{
System.out.println("Bilangan Yang Anda Masukan Adalah : Genap");
}
else
if (x%2!=0)
{
System.out.println("Bilangan Yang Anda Masukan Adalah : Ganjil ");
}
System.exit(0);
}
}

bilangan

import java.io.*;
class bilangan
{
public static void main(String[] args) throws Exception
{
System.out.println("PROGRAM MENCARI BILANGAN PRIMA");
System.out.println("=================================");
System.out.println("Nama : MADE ADI PUTRA");
System.out.println("NIM : 080020015");
System.out.println("Jurusan : T. IMFORMATIKA");
System.out.println("=================================");
String batas;
int i, x, y,b;
DataInputStream dis = new DataInputStream (System.in);
System.out.print("Masukkan batas angka : ");
batas=dis.readLine();
b=Integer.parseInt(batas);
System.out.println("Deret Bilangan Prima : ");
for (i=1; i <= b; i++ )
{
for (x=i; x
{
System.out.print(" "+i);
}
}
}
}

aritmatika

class aritmatikademo
{
public static void main(String[] args) throws Exception
{
//sedikit angka
int i = 37;
int j = 42;
double x = 27.475;
double y = 7.22;

System.out.println("Variable values...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" x = " + x);
System.out.println(" y = " + y);

//penjumlahan angka
System.out.println("Adding...");
System.out.println(" i + j = "+(i + j));
System.out.println(" x + y = "+(x+y));

//pengurangan angka
System.out.println("Subtracting...");
System.out.println(" i - j = "+(i - j));
System.out.println(" x - y = "+(x - y));

//perkalian angka
System.out.println("Multipying...");
System.out.println(" i *j = "+ (i * j));
System.out.println(" x * y = "+(x * y));

//pembagian angka
System.out.println("Dividing...");
System.out.println(" i / j = "+(i / j));
System.out.println(" x / y = "+(x / y));

//menghitung hasil modulus dari pembagian
System.out.println("Computing the remainder...");
System.out.println(" i % j = "+(i % j));
System.out.println(" x % y = "+(x % y));

//tipe penggabungan
System.out.println("Mixing tipes...");
System.out.println(" j + y = "+(j + y));
System.out.println(" i * x = "+(i * x));






}
}

akar dan kuadrat GUI 2

import javax.swing.JOptionPane;
class akar_dan_kuadratGUI
{
public static void main(String[] args) throws Exception
{
String alas,tinggi;
int a,t;
double akar,kuadratA,kuadratT,jmlAT,sisimiring;
//DataInputStream dis = new DataInputStream (System.in);
alas=JOptionPane.showInputDialog("Masukan Alas :");
a=Integer.parseInt(alas);
tinggi=JOptionPane.showInputDialog("Masukan Tinggi :");
t=Integer.parseInt(tinggi);
kuadratA=Math.pow(a,2);
kuadratT=Math.pow(t,2);
jmlAT=kuadratA+kuadratT;
sisimiring=Math.sqrt(jmlAT);
JOptionPane.showMessageDialog(null,"Jadi Sisi Miringnya ="+sisimiring);
System.exit(0);
}
}

akar dan kuadrat

import java.io.*;
class akar_dan_kuadrat
{
public static void main(String[] args) throws Exception
{
String angka;
int a,b,c;
double akar,kuadrat;
DataInputStream dis = new DataInputStream (System.in);
System.out.println("Masukan Angka :");
angka=dis.readLine();
a=Integer.parseInt(angka);
kuadrat=Math.pow(a,2);
akar=Math.sqrt(a);
System.out.println("Kuadrat :"+kuadrat);
System.out.println("Akar : " +akar);
}
}

akar dan kuadrat GUI

import javax.swing.JOptionPane;
class akar_dan_kuadrat2
{
public static void main(String[] args) throws Exception
{
String alas,tinggi;
int a,t;
double akar,kuadratA,kuadratT,jmlAT,sisimiring;
//DataInputStream dis = new DataInputStream (System.in);
alas=JOptionPane.showInputDialog("Masukan Alas :");
a=Integer.parseInt(alas);
tinggi=JOptionPane.showInputDialog("Masukan Tinggi :");
t=Integer.parseInt(tinggi);
kuadratA=Math.pow(a,2);
kuadratT=Math.pow(t,2);
jmlAT=kuadratA+kuadratT;
sisimiring=Math.sqrt(jmlAT);
JOptionPane.showMessageDialog(null,"Jadi Sisi Miringnya ="+sisimiring);
System.exit(0);
}
}

toturial java