Laporan Modul 3
Laporan Modul 3
3411191162
TUGAS 3.1
import java.util.Scanner;
public class Addition {
public static void main (String[] args){
- Terdapat dua objek pada program tsb, num1 dan num2 dan bertipe integer
TUGAS 3.2
Buat Program dengan nilai grade bertipe Double, nilai grade didapat dari keyboard
import java.util.Scanner;
public class Double {
public static void main (String[] args){
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
}
}
1. Untuk mendapat masukan dari keyboard, proses harus dituliskan dalam bloc try-catch
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
try{
String name = " ";
System.out.println ("please enter your name: ");
name = dataIn.readLine();
}catch (IOException name) {
System.out.println("hello " + name + "!");
}
}
}
Hasil program ditambah blok try
TUGAS 3.4
import javax.swing.JOptionPane;
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.JOptionPane;
String msg = ("so your hobby is " + hoby + "nice hoby mister." + name) ;
JOptionPane.showMessageDialog(null, msg);
System.out.println (" so your hobby is " + hoby + ". nice hobby mr. " + name);
}
}
TUGAS 3.6
import java.awt.*;
public class Grafik extends Panel{
public Grafik() {
setBackground(Color.black);
}
public void paint (Graphics g) {
g.setColor (new Color (0,255,0)); //green
g.setFont (new Font("Helvetica",Font.PLAIN,16));
g.drawString("hello Gui World!",30, 100);
g.setColor (new Color (1.0f,0,0)); //red
g.fillRect(30, 100, 150, 50);
}
public static void main (String [] args) {
Frame f = new Frame ("Testing Graphics Panel");
Grafik gp = new Grafik();
f.add(gp);
f.setSize(600, 300);
f.setVisible(true);
}
}
Tugas akhir 1
import java.util.Scanner;
public class Menghitung {
public static void main (String[] args){
//operator tambah
System.out.println("OPERATOR TAMBAH");
System.out.print("Nilai1 = ");
num1 = input.nextInt();
System.out.print("Nilai2 = ");
num2 = input.nextInt();
//operator kali
System.out.println("\nOPERATOR PERKALIAN");
System.out.print("Nilai1 = ");
num1 = input.nextInt();
System.out.print("Nilai2 = ");
num2 = input.nextInt();
//OPERATOR PENGURANGAN
System.out.println("\nOPERATOR PENGURANGAN");
System.out.print("Nilai1 = ");
num1 = input.nextInt();
System.out.print("Nilai2 = ");
num2 = input.nextInt();
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.JOptionPane;
String msg = ("so your hobby is " + hoby + "nice hoby mister." + name) ;
JOptionPane.showMessageDialog(null, msg);
System.out.println (" so your hobby is " + hoby + ". nice hobby mr. " + name);
}
}
Tugas akhir 3
JoptionPane 3 kata
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.JOptionPane;
String name = " ", hoby = " ", suka = " ";
name = JOptionPane.showInputDialog("siapa namamu :");
hoby = JOptionPane.showInputDialog("apa hobimu :");
suka = JOptionPane.showInputDialog("apa yang kau suka :");
String msg = ("hobimu adalah " + hoby + " dan kesukaanmu adalah " +suka+ ". mantap,
lanjutkan juragan. " + name) ;
JOptionPane.showMessageDialog(null, msg);
System.out.println ("hobimu adalah " + hoby + " dan kesukaanmu adalah " +suka+ ".
mantap, lanjutkan juragan. " + name);
}
}
TUGAS 4
input.nextInt();
Contoh diatas menggunakan tipedata integer, jika kita mengunakan tipedata lain maka method
berbeda. Contoh input.nextDouble untuk data bertipe double