PRAKTIKUM JAVA
PROGRAM SESUDAH UTS
Tugas 1
Bintang Turun.Java
public class BintangTurun
{
public static void main(String [] args)
{
int x=6;
int a,b;
for(a=1;a<=x-1;a++){
for(b=1;b<=a;b++){
System.out.print(“*”);
}
System.out.println(“\n”);
}
}
}
Tugas2
BintangKolom.Java
public class BintangKolom
{
public static void main(String [] args)
{
int kol=4;
int bar=5;
for(int k=1;k<=kol;k++){
for(int b=1;b<=bar;b++){
System.out.print(“*”);
}
System.out.println(“\n”);
}
}
}
PROGRAM SEBELUM UTS
TEMU 2
Program 1
public class TipeData1 {
public static void main(String[] args)
{
byte a = 1;
short b = 2;
int c = 3,d;
d = a+b+c;
System.out.println("hasilnya = "+d);
}
}
Program 2
public class TipeData2
{
public static void main(String[] args)
{
double pi = 3.14;
double r = 2.12;
double luas;
luas = pi*r*r;
System.out.println("Luas Lingkaran = " + luas);
}
}
program 3
public class TipeData3
{
public static void main(String[] args)
{
char ch1 = 65;//karena sudah ada kodenya sendiri dari ASCII
char ch2 = 'B';
System.out.println("ch1 = "+ch1);
System.out.println("ch2 = "+ch2);
}
}
TEMU 3
Program 1
public class Operator1
{
public static void main(String[]args)
{
System.out.println("Operator aritmetika"+"pada tipe integer");
int a = 7+4;
int b = a-4;
int c = a*b;
int d = c/3;
int e = -a;
System.out.println("Nilai a:"+a);
System.out.println("Nilai b:"+b);
System.out.println("Nilai c:"+c);
System.out.println("Nilai d:"+d);
System.out.println("Nilai e:"+e);
System.out.println();
System.out.println("Operasi aritmetika"+"pada tipe floating-point");
double fa = 7+4;
double fb = fa- 4;
double fc = fa*fb;
double fd = fc/3;
double fe = -a;
System.out.println("NIlai fa:"+fa);
System.out.println("Nilai fb:"+fb);
System.out.println("Nilai fc:"+fc);
System.out.println("Nilai fd:"+fd);
System.out.println("Nilai fe:"+fe);
}
}
Program 2
class Operator2
{
public static void main(String[] args)
{
int a=25, b=6;
int c = a /b;
double d = 17.75;
double e = d /b;
System.out.println("Sisa bagi " + a + "/" + b + " adalah " + c);
System.out.println("Sisa bagi " + d + "/" + b + " adalah " + e);
}
}
Program 3
public class Operato3
{
public static void main(String[] args)
{
int a=17;
System.out.println("Pre-increment");
System.out.println("a\t: " + a);
System.out.println("++a\t: " + ++a);
System.out.println("a\t: " + a);
int b=17;
System.out.println("\nPost-increment");
System.out.println("b\t: " + b);
System.out.println("b++\t: " + b++);
System.out.println("b\t: " + b);
}
}
Program 4
public class Operator4
{
public static void main(String[] args)
{
int a=5, b=10;
System.out.println("a == b bernilai " + (a == b));
System.out.println("a != b bernilai " + (a != b));
System.out.println("a > b bernilai " + (a > b));
System.out.println("a < b bernilai " + (a < b));
System.out.println("a >= b bernilai " + (a >= b));
System.out.println("a <= b bernilai " + (a <= b));
}
}
TEMU 4
Program 1
public class Latihan_4_1
{
public static void main(String[] args)
{
int a=1,b=10;
if(a<5)
{
System.out.println("nilai a lebih kecil dari 5");
}
else
{
System.out.println("");
}
}
}
Program 2
public class Latihan_4_2 {
public static void main( String[] args)
{
double gaji=2500000;
double pajak=0,terima=0;
if(gaji>1000000)
{
pajak=0.1*gaji;
}
else
{
pajak=0;
}
terima=gaji-pajak;
System.out.println("gaji="+terima);
}
}
Program 3
public class Latihan_4_3 {
public static void main(String[] args)
{
char kode= 'E';
if(kode=='E')
{
System.out.println(kode+"adalah kode yang benar");
}
else
{
System.out.println(kode+"adalah kode yang salah");
}
}
}
Program 4
public class Latihan_4_4 {
public static void main(String[] args)
{
String kode= "A1";
if(kode=="A1")
{
System.out.println(kode+ " adalah kode yang benar");
}
else
{
System.out.println(kode+ " adalah kode yang salah");
}
}
}
Program 5
public class Latihan_4_5 {
public static void main(String[] args)
{
char ch='B';
if(ch=='A'||ch=='I'||ch=='O')
{
System.out.println(ch +" adalah huruf vokal");
}
else
{
System.out.println(ch +" adalah huruf mati(konsonan).");
}
}
}
Program 6
public class Latihan_4_6 {
public static void main(String [] args)
{
int UTS=65,UAS=72;
double Nilai Akhir=0;
Nilai Akhir= (0.4*UTS)+(0.6*UAS);
if(Nilai akhir<=70)
{
System.out.println ("Gagal");
}
else if(Nilai Akhir>70)
{
System.out.println ("Lulus");
}
System.out.println(Nilai Anda= +Nilai Akhir);
System.out.println("Selamt Anda.....");
}
}
TEMU 5
Program 1
public class Latihan_4_7
{
public static void main(String[] args)
{
char nilaiIndeks;
double nilaiUTS,nilaiUAS, nilaiAkhir;
//contoh data yang di masukan
nilaiUTS = 75.0;
nilaiUAS = 60.0;
//menghitung nilai akhir menggunakan rumus di atas
nilaiAkhir = (0.4 * nilaiUTS) + (0.6 * nilaiUAS);
if(nilaiAkhir>=80)
{
nilaiIndeks='A';
}
else if(nilaiAkhir>=70)
{
nilaiIndeks='B';
}
else if(nilaiAkhir>=50)
{
nilaiIndeks='C';
}
else if(nilaiAkhir>=30)
{
nilaiIndeks='D';
}
else
{
//(nilai Akhir < 30)
nilaiIndeks ='E';
}
System.out.println("Nilai Akhir\t:" + nilaiAkhir);
System.out.println("Nilai Indeks\t:" + nilaiIndeks);
}
}
Program 2
public class Latihan_4_8
{
public static void main(String[] args)
{
char kode = 'C';
String NamaBarang;
int HargaBarang;
if(kode=='A')
{
NamaBarang = "Flashdisk";
HargaBarang= 75000;
}
else if(kode=='B')
{
NamaBarang="Speaker";
HargaBarang=35000;
}
else if(kode=='C')
{
NamaBarang="Card Reader";
HargaBarang=15000;
}
else
{
NamaBarang="Mouse";
HargaBarang=40000;
}
System.out.println("Kode\t\t:"+ kode);
System.out.println("NamaBarang \t:" +NamaBarang);
System.out.println("HargaBarang \t:" +HargaBarang);
}
}
Program 3
public class Latihan_Mandiri
{
public static void main(String[] args)
{
//input
String NamaPenerima="Iin";
String AlamatPengirim="aaaaa";
String NamaPenerima="aajakl";
String AlamatPenerima="ajbudh";
char KodeKota='J';
int BeratKiriman=50;
int TrifPerKg=3500;
if(kode=='J')
{
KotaTujuan = "Jakarta";
TarifPerKg = 3500;
}
else if(kode=='B')
{
KotaTujuan = "Bandung";
TarifPerKg = 4500;
}
else if(kode=='C')
{
KotaTujuan = "Cirebon";
TarifPerKg = 3000;
}
else if(kode=='T')
{
KotaTujuan = "Tanggerang";
TarifPerKg = 4000;
}
BiayaKiriman = (BeratKiriman * Biaya Packing);
if(BiayaKiriman>30)
{
Biaya Packing=10000;
}
Pembayaran = (BiayaKiriman + Biaya Packing);
System.out.println("Nama Pengirim \t\t:" + NamaPengirim);
System.out.println("Alamat Pengirim \t:" +AlamatPengirim);
System.out.println("Nama Penerima \t:" + NamaPenerima);
System.out.println("Alamat Penerima \t:" + NamaPenerima);
System.out.println("Kode \t\t\t\t:" + Kode);
System.out.println("Kota Tujuan \t\t:" +KotaTujuan);
System.out.println("Tarif Per Kg \t\t:" +TarifPerKg);
System.out.println("Berat Kiriman \t\t:" + BiayaKiriman);
System.out.println("Pembayaran\t\t\t\t:" + Pembayaran);
}
}
TEMU 6
Program 1
java.io.*;
public class temu6
{
public static void main(String[]arg) throws IOException
{
String namapasien = "joni";
String namakamar = "a";
char kodekamar = 'D';
int lamaperawatan = 7;
int biayaobat = 750000;
int biayadokter = 250000;
int biayakamar = 0;
int biayatotal = 0;
switch (kodekamar)
{
case 'A':
namakamar = "anggrek";
biayakamar = 350000;
break;
case 'B':
namakamar = "ak";
biayakamar = 150000;
break;
case 'C':
namakamar = "agrek";
biayakamar = 300000;
break;
case 'D':
namakamar = "anek";
biayakamar = 400000;
break;
default:
System.out.println("tidak ada kode kamar" + kodekamar);
}
biayatotal = (lamaperawatan * biayakamar) + biayaobat + biayadokter;
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("daftar pembayaran");
System.out.println("rs mugas");
System.out.println("=====================================");
System.out.println("nama pasien :"+namapasien);
System.out.println("kode kamar :"+kodekamar);
System.out.println("nama kamar :"+namakamar);
System.out.println("lama perawatan :"+lamaperawatan);
System.out.println("biaya kamar per hari :"+biayakamar);
System.out.println("biaya obat :"+biayaobat);
System.out.println("biaya dokter :"+biayadokter);
System.out.println("biaya total :"+biayatotal);
System.out.println("=====================================");
}
}