Penyelesaian Program Penjualan di Kantin xxx

Posted: October 3, 2011 in Pemrograman Berbasis Objek ( PBO )

nah,dari gambaran diatas kita

ada beberapa class yang harus kita buat

1. utama.java

import java.io.IOException;
import java.util.Scanner;

public class utama
{
public static Scanner scn;
public static DataMakanan onyTrans=new DataMakanan();

public static void main(String[] args)
{

aturMenuUtama();
}
public static void cetakMenu(){
String menuutama=”=========APLIKASI PENJUALAN KANTIN OKE JON=========\n\n”;
menuutama = menuutama + “1. Add Makanan\n”;
menuutama = menuutama + “2. Update Makanan\n”;
menuutama = menuutama + “3. Penjualan Makanan\n”;
menuutama = menuutama + “4. View All Makanan\n”;
menuutama = menuutama + “5. View All Transaksi\n”;
menuutama = menuutama + “6. Keluar\n”;
menuutama = menuutama + “SILAHKAN MASUKAN PILIHAN ANDA [1-4]> “;
menuutama = menuutama + “”;
System.out.print(menuutama);
}
public static int getPilihan()
{
int pil=0;
try
{
scn= new Scanner(System.in);
pil=scn.nextInt();

}catch(Exception e){e.printStackTrace();}
return pil;
}
public static void aturMenuUtama(){
boolean selesai=false;
do{
cetakMenu();
int pil=getPilihan();
switch(pil){
case 1:AddMakanan();break;
//    case 2:onyTrans.UpdateMakanan();break;
//case 3:onyTrans.PenjualanMakanan();break;
case 4:onyTrans.LihatMakanan();break;
//case 5:onyTrans.LihatTransData();break;
case 6: selesai=true;break;
default: System.out.println(“WARNING!\n\nPilihan 1-9!”);
}
}while(!selesai);
System.out.println(“Terima Kasih Telah Menggunakan Program ini!”);
}
public static String inputanString()
{
String data=””;
try
{
data=scn.next();
}catch(Exception e){e.printStackTrace();}
return data;
}
public static int inputanAngka()
{

int data=0; /* Inisialisasi */
try
{
data= scn.nextInt();
}
catch(Exception e)
{e.printStackTrace();}
return data;
}

public static void AddMakanan()
{

System.out.println(“Tambah Makanan\n”);
System.out.println(“Paket: “);
String paket=inputanString();

System.out.println(“Harga: “);
int harga=inputanAngka();

Makanan mk=new Makanan(paket,harga);
onyTrans.add(mk);
}
}

2. Makanan.java

public class Makanan {
private String paket;
private int harga;

public String getPaket() {
return paket;
}

public void setPaket(String Paket) {
this.paket = paket;
}

public int getHarga() {
return harga;
}

public void setHarga(int harga) {
this.harga = harga;
}

public Makanan(String paket, int harga) {
super();
this.paket = paket;
this.harga = harga;
}

public String tampilData(){
return paket+”\t”+harga;
}
}

3. DataMakanan.java

import java.util.Vector;

public class DataMakanan {
private Vector <Makanan> tabelMakanan=new Vector<Makanan>();

public void add(Makanan mk)
{
tabelMakanan.addElement(mk);
}
public void LihatMakanan()
{
System.out.println(“========Daftar Menu Makanan========”);
System.out.println(“”);
System.out.println(“Paket ” + “Harga\t”);
for(Makanan tr:tabelMakanan)
System.out.println(tr.tampilData());
}
}

 

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