Contoh Program BufferedReader & Contoh Program JOptionPane

Contoh Program BufferedReader
package contoh2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main
{
public static void main ( String[] args ) throws IOException {
BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
String nama;
int nilai;
try{
System.out.print (“Ketikkan nama = “);
nama = (dataIn.readLine());
System.out.print (“Masukkan nilai = “);
nilai = Integer.parseInt(dataIn.readLine());
if (nilai >= 80){
System.out.println(“Ketikkan Nama Anda : ” +nama+ “Nilai Anda : ” +nilai+ “predikat A”);}
else
if (nilai >= 70){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat B”);}
else
if (nilai >= 60){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat C”);}
else
if (nilai >= 50){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat D”);}
else {
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat E”);}
}
catch( NumberFormatException e ){
System.out.println(“Error!”);
System.exit(1);
}
}
}

Contoh Program JOptionPane
package contoh1;
import javax.swing.JOptionPane;
public class Main {
public static void main( String[] args ){
String nama;
int nilai;
nama = JOptionPane.showInputDialog (“Masukkan Nama Anda”);
String teks = JOptionPane.showInputDialog(“Masukkan Nilai”);
nilai = Integer.parseInt(teks);
if (nilai >= 80){
JOptionPane.showMessageDialog(null, nama+ ” Selamat Anda Lulus… Dengan Nilai : ” +nilai);}
else
if (nilai >= 70){
JOptionPane.showMessageDialog(null, nama+ ” Selamat Anda Lulus… Dengan Nilai : ” +nilai);}
else
if (nilai >= 60){
JOptionPane.showMessageDialog(null, nama+ ” Anda Lulus(bersyarat)… Nilai Anda : ” +nilai);}
else
if (nilai >= 50){
JOptionPane.showMessageDialog(null, nama+ ” Maaf Anda Tidak Lulus…” +nilai+ “Nilai Anda Kurang”);}
else {
JOptionPane.showMessageDialog(null, nama+ ” dinyatakan tidak lulus, nilai Anda ” +nilai);}

}
}

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: