ini adalah salah satu contoh dari java class library:
import java.io.*;
public class pertemuan10_4{
public static void main(String[] args){
int a=0, b=0, pilih=0;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
pertemuan10_4 obj104 = new pertemuan10_4();
boolean ulang = true;
try{
System.out.println("Masukan 2 Buah Bilangan");
System.out.println("-----------------------");
System.out.print("A : "); a = Integer.parseInt(input.readLine());
System.out.print("B : "); b = Integer.parseInt(input.readLine());
while(ulang){
System.out.println("--------------------------");
System.out.println(">> Aritmatik 2 Bilangan <<");
System.out.println("--------------------------");
System.out.println("1. Tambah");
System.out.println("2. Kurang");
System.out.println("3. Kali");
System.out.println("4. Bagi");
System.out.println("5. Selesai");
System.out.println("--------------------------");
System.out.print("Masukan Pilihan : "); pilih = Integer.parseInt(input.readLine());
Senin, 23 Mei 2011
Java dengan menggunakan input dan lainnya dalam pembuatan sistem akademik
dibawah ini adalah contoh sebuah sistem akademik dengan menggunakan inputan, perulangan, dan lainya secara lengkap...
import java.io.*;
public class dataMhs
{
public static void main( String[] args )
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int grade;
String DataMahasiswa[][]=new String[5][4];
String DataMataKuliah[][]=new String[5][4];
String DataKRS[][]=new String[5][3];
try
{
boolean ada = true;
while(ada)
{
System.out.println("\n\n\t\tDAFTAR MENU");
System.out.println("-----------------------------------------------");
System.out.println("1. Entri MataKuliah");
System.out.println("2. Entri Mahasiswa");
System.out.println("3. Entri KRS");
System.out.println("4. Tampil Matakuliah");
System.out.println("5. Tampil Mahasiswa");
System.out.println("6. Tampil KRS");
System.out.println("7. Keluar");
System.out.println("-----------------------------------------------\n");
System.out.print("Masukan Pilihan[1/2/3/4/5/6/7] = ");
grade=Integer.parseInt(input.readLine());
switch(grade)
{
case 1:
{int i = 0;
while(true){
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Matakuliah :");
System.out.println("-----------------------------------------------");
System.out.print("\tKode Matakuliah\t: "); DataMataKuliah[i][0]= input.readLine();
System.out.print("\tNama\t\t: "); DataMataKuliah[i][1]= input.readLine();
System.out.print("\tJenis\t\t: "); DataMataKuliah[i][2]= input.readLine();
System.out.print("\tSKS\t\t: "); DataMataKuliah[i][3]= input.readLine();
i++;
System.out.print("\tTambah Matakuliah [y/n] : "); String jumlah = input.readLine();
if (jumlah.equals("n")){
break;}
System.out.println("-----------------------------------------------");
}
}
break;
case 2:
{int i = 0;
while(true)
{
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Mahasiswa :");
System.out.println("-----------------------------------------------");
System.out.print("\tNIM\t\t : "); DataMahasiswa[i][0]= input.readLine();
System.out.print("\tNama\t\t : "); DataMahasiswa[i][1]= input.readLine();
System.out.print("\tAlamat\t\t : "); DataMahasiswa[i][2]= input.readLine();
System.out.print("\tNo.Telepon\t : "); DataMahasiswa[i][3]= input.readLine();
i++;
System.out.print("\tTambah Mahasiswa [y/n] : "); String tambah= input.readLine();
if (tambah.equals("n")){
break;}
}
System.out.println("-----------------------------------------------");
}
break;
case 3:
{int i = 0;
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Data KRS :");
System.out.println("-----------------------------------------------");
System.out.print("\tNo. KRS : "); DataKRS[i][0]= input.readLine();
System.out.print("\tNIM\t\t : "); DataKRS[i][1]= input.readLine();
for (int x=0; x<DataMahasiswa.length;x++){
if (DataMahasiswa[x][0].equals(DataKRS[i][1])){
System.out.println("\tNama\t\t : "+DataMahasiswa[x][1]);
break;
}
}
while(true)
{
System.out.print("\tKode Matakuliah\t : "); DataKRS[i][2]= input.readLine();
for (int y=0; y<DataMataKuliah.length;y++){
if (DataMataKuliah[y][0].equals(DataKRS[i][2])){
System.out.println("\tNama\t\t : "+DataMataKuliah[y][1]);
System.out.println("\tJenis\t\t : "+DataMataKuliah[y][2]);
System.out.println("\tSKS\t\t : "+DataMataKuliah[y][3]);
break;
}
}
i++;
System.out.print("\tTambah Matakuliah lagi [y/n] : "); String tambah= input.readLine();
if (tambah.equals("n")){
break;
}
}
}
break;
import java.io.*;
public class dataMhs
{
public static void main( String[] args )
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int grade;
String DataMahasiswa[][]=new String[5][4];
String DataMataKuliah[][]=new String[5][4];
String DataKRS[][]=new String[5][3];
try
{
boolean ada = true;
while(ada)
{
System.out.println("\n\n\t\tDAFTAR MENU");
System.out.println("-----------------------------------------------");
System.out.println("1. Entri MataKuliah");
System.out.println("2. Entri Mahasiswa");
System.out.println("3. Entri KRS");
System.out.println("4. Tampil Matakuliah");
System.out.println("5. Tampil Mahasiswa");
System.out.println("6. Tampil KRS");
System.out.println("7. Keluar");
System.out.println("-----------------------------------------------\n");
System.out.print("Masukan Pilihan[1/2/3/4/5/6/7] = ");
grade=Integer.parseInt(input.readLine());
switch(grade)
{
case 1:
{int i = 0;
while(true){
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Matakuliah :");
System.out.println("-----------------------------------------------");
System.out.print("\tKode Matakuliah\t: "); DataMataKuliah[i][0]= input.readLine();
System.out.print("\tNama\t\t: "); DataMataKuliah[i][1]= input.readLine();
System.out.print("\tJenis\t\t: "); DataMataKuliah[i][2]= input.readLine();
System.out.print("\tSKS\t\t: "); DataMataKuliah[i][3]= input.readLine();
i++;
System.out.print("\tTambah Matakuliah [y/n] : "); String jumlah = input.readLine();
if (jumlah.equals("n")){
break;}
System.out.println("-----------------------------------------------");
}
}
break;
case 2:
{int i = 0;
while(true)
{
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Mahasiswa :");
System.out.println("-----------------------------------------------");
System.out.print("\tNIM\t\t : "); DataMahasiswa[i][0]= input.readLine();
System.out.print("\tNama\t\t : "); DataMahasiswa[i][1]= input.readLine();
System.out.print("\tAlamat\t\t : "); DataMahasiswa[i][2]= input.readLine();
System.out.print("\tNo.Telepon\t : "); DataMahasiswa[i][3]= input.readLine();
i++;
System.out.print("\tTambah Mahasiswa [y/n] : "); String tambah= input.readLine();
if (tambah.equals("n")){
break;}
}
System.out.println("-----------------------------------------------");
}
break;
case 3:
{int i = 0;
System.out.println("-----------------------------------------------");
System.out.println("\t\tEntri Data KRS :");
System.out.println("-----------------------------------------------");
System.out.print("\tNo. KRS : "); DataKRS[i][0]= input.readLine();
System.out.print("\tNIM\t\t : "); DataKRS[i][1]= input.readLine();
for (int x=0; x<DataMahasiswa.length;x++){
if (DataMahasiswa[x][0].equals(DataKRS[i][1])){
System.out.println("\tNama\t\t : "+DataMahasiswa[x][1]);
break;
}
}
while(true)
{
System.out.print("\tKode Matakuliah\t : "); DataKRS[i][2]= input.readLine();
for (int y=0; y<DataMataKuliah.length;y++){
if (DataMataKuliah[y][0].equals(DataKRS[i][2])){
System.out.println("\tNama\t\t : "+DataMataKuliah[y][1]);
System.out.println("\tJenis\t\t : "+DataMataKuliah[y][2]);
System.out.println("\tSKS\t\t : "+DataMataKuliah[y][3]);
break;
}
}
i++;
System.out.print("\tTambah Matakuliah lagi [y/n] : "); String tambah= input.readLine();
if (tambah.equals("n")){
break;
}
}
}
break;
Langganan:
Postingan (Atom)