Rabu, 17 Oktober 2012
Main
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulator;
/**
*
* @author Praktikum
*/
public class Main {
private int a;
private int b;
private int hasil;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
/**
* @return the a
*/
public int getA() {
return a;
}
/**
* @param a the a to set
*/
public void setA(int a) {
this.a = a;
}
/**
* @return the b
*/
public int getB() {
return b;
}
/**
* @param b the b to set
*/
public void setB(int b) {
this.b = b;
}
int tambah(){
return a+b;
}
int kurang(){
return a-b;
}
int kali(){
return a*b;
}
int bagi(){
return a/b;
}
void display(){
}
/**
* @return the hasil
*/
public int getHasil() {
return hasil;
}
/**
* @param hasil the hasil to set
*/
public void setHasil(int hasil) {
this.hasil = hasil;
}
}
Driver
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulator;
import java.util.Scanner;
/**
*
* @author Praktikum
*/
public class driver {
public static void main(String args[]){
int pil;
Scanner key = new Scanner(System.in);
Main Kal= new Main();
do{
System.out.println("Kalkulator");
System.out.println("1. Tambah");
System.out.println("2. Kurang");
System.out.println("3. Kali");
System.out.println("4. Bagi");
System.out.println("0. OUT");
System.out.print("Pilihan : ");
pil = key.nextInt();
switch(pil){
case 1:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.tambah());
System.out.println();
break;
case 2:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.kurang());
System.out.println();
break;
case 3:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.kali());
System.out.println();
break;
case 4:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.bagi());
System.out.println();
break;
case 0: System.out.print("Keluar");
default: System.out.println("Perintah Tidak ada");
//switch(int ){
}}while(pil!=0);
}}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulator;
/**
*
* @author Praktikum
*/
public class Main {
private int a;
private int b;
private int hasil;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
/**
* @return the a
*/
public int getA() {
return a;
}
/**
* @param a the a to set
*/
public void setA(int a) {
this.a = a;
}
/**
* @return the b
*/
public int getB() {
return b;
}
/**
* @param b the b to set
*/
public void setB(int b) {
this.b = b;
}
int tambah(){
return a+b;
}
int kurang(){
return a-b;
}
int kali(){
return a*b;
}
int bagi(){
return a/b;
}
void display(){
}
/**
* @return the hasil
*/
public int getHasil() {
return hasil;
}
/**
* @param hasil the hasil to set
*/
public void setHasil(int hasil) {
this.hasil = hasil;
}
}
Driver
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulator;
import java.util.Scanner;
/**
*
* @author Praktikum
*/
public class driver {
public static void main(String args[]){
int pil;
Scanner key = new Scanner(System.in);
Main Kal= new Main();
do{
System.out.println("Kalkulator");
System.out.println("1. Tambah");
System.out.println("2. Kurang");
System.out.println("3. Kali");
System.out.println("4. Bagi");
System.out.println("0. OUT");
System.out.print("Pilihan : ");
pil = key.nextInt();
switch(pil){
case 1:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.tambah());
System.out.println();
break;
case 2:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.kurang());
System.out.println();
break;
case 3:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.kali());
System.out.println();
break;
case 4:
System.out.print("Masukan Bilangan Ke-1 : ");
Kal.setA(key.nextInt());
System.out.print("Masukan Bilangan Ke-2 : ");
Kal.setB(key.nextInt());
System.out.println("Hasil = "+ Kal.bagi());
System.out.println();
break;
case 0: System.out.print("Keluar");
default: System.out.println("Perintah Tidak ada");
//switch(int ){
}}while(pil!=0);
}}
Senin, 15 Oktober 2012
Relasi Antar Objek
Assosiati : adalah sebuah nama formal dari sebuah structural relasi yang ada di antara banyak kelas misal :
- Seorang Mahasiswa terdaftar pada sebuah mata kuliah.
- Seorang Dosen Mengajar sebuah mata kuliah.
- Sebuah Program pendidikan Terdiri dari mata kuliah
Link : adalah sebuah relasi struktural antar 2 objek, misal :
- Karimata terdaftar pada OOP
Multiplicity : mirip dengan metode Kardinalisasi pada Mata Kuliah Pengolahan Data Base
Agregasi : Adalah bentuk khusus dari sebuah asosiasi, namun secara konsep dapat dibedakan, bisa menggunakan "consist of","is composed of" atau "memiliki" . Contoh:
- Mobil memiliki mesin
Komposisi : Sebuah bentuk agregasi yang lebih kuat, dimana bagian kecil tidak akan ada tanpa ada objek keseluruhan. Misal :
- Ruangan tidak akan ada bila Gedung tidak ada
Ruangan = parts; dan Gedung = whole / object.
Jumat, 12 Oktober 2012
Prima :
public static void main(String [] args){
int i,temp;
int iawal,iakhir;
Scanner input = new Scanner(System.in);
iawal = 1;
iakhir = 20;
System.out.println("Masukan Inputan Awal Anda = "+ iawal);
System.out.println("Masukan inputan Akhir Anda = "+ iakhir);
i = iawal;
for (i=iawal;i
// for(temp=i;(temp%temp==1) && (temp%2==1);i--)
if((j%2==1)){
System.out.print(j+ " ");}}
}
}
package javalatian;
import java.io.*;
import java.util.Scanner;
/**
*
* @author 7
*/
public class Javalatian {
private int noSeri;
private String warna;
private String nama;
private String status;
private int maxspeed;
private int speed= 0;
public void mobil (int noSeri, String warna, String nama, int maxspeed){
this.setNoSeri(noSeri);
this.setWarna(warna);
this.setNama(nama);
this.setMaxspeed(maxspeed);
}
public void setnoSeri(int noSeri){
this.setNoSeri(noSeri);
}
public int getnoSeri(){
return getNoSeri();
}
public void Start(){
status = "hidup";
// if(Status.equal("Hidup"));
}
public void percepat(int x){
if(status.equals("hidup")){
if (getSpeed()+x>getMaxspeed()){
System.out.println("Kecepatan maksimum");
}
else {
setSpeed(getSpeed()+x);
}
System.out.println("Hidupkan mesin");
}
}
public void perlambat(int x){
if(status.equals("hidup")){
if(getSpeed()-x<=0){
System.out.println("Kecepatan maksimum");
}else{
setSpeed(getSpeed()-x);
}
}
System.out.println("Idupin Mobil");
}
public static void berhenti(int speed,String status){
System.out.println("Berhenti");
speed = 0;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
/**
* @return the noSeri
*/
public int getNoSeri() {
return noSeri;
}
/**
* @param noSeri the noSeri to set
*/
public void setNoSeri(int noSeri) {
this.noSeri = noSeri;
}
/**
* @return the warna
*/
public String getWarna() {
return warna;
}
/**
* @param warna the warna to set
*/
public void setWarna(String warna) {
this.warna = warna;
}
/**
* @return the nama
*/
public String getNama() {
return nama;
}
/**
* @param nama the nama to set
*/
public void setNama(String nama) {
this.nama = nama;
}
/**
* @return the maxspeed
*/
public int getMaxspeed() {
return maxspeed;
}
/**
* @param maxspeed the maxspeed to set
*/
public void setMaxspeed(int maxspeed) {
this.maxspeed = maxspeed;
}
/**
* @return the speed
*/
public int getSpeed() {
return speed;
}
/**
* @param speed the speed to set
*/
public void setSpeed(int speed) {
this.speed = speed;
}
}
Rabu, 10 Oktober 2012
Kelipatan :
public static void main(String[] args) {
// TODO code application logic here
int angka ;
Scanner input = new Scanner (System.in);
System.out.println("Angka : ");
angka = input.nextInt();
if (angka%3==0){
System.out.println("Kelipatan 3");
}else{
System.out.println("Bukan Kelipatan 3");
}}
public static void main(String[] args) {
// TODO code application logic here
int angka ;
Scanner input = new Scanner (System.in);
System.out.println("Angka : ");
angka = input.nextInt();
if (angka%3==0){
System.out.println("Kelipatan 3");
}else{
System.out.println("Bukan Kelipatan 3");
}}
Langganan:
Postingan (Atom)