Membuat Program Maintenance Data Barang

Berikut ini adalah kerangka program maintenance data barang,

Program Utama

public class MaintainBarang{
	private FileBarang dataBarang;
	private boolean selesai=false;

	public MaintainBarang(){
		dataBarang=new FileBarang();
	}
	public void cetakMenu(){
		String menu="Program Maintenance Barang\n"+
					"1. Add Barang Baru\n"+
					"2. Cari Data Barang\n"+
					"3. Cek Harga Barang\n"+
					"4. Hapus Data Barang\n"+
					"5. View All Data Barang\n"
					"6. Selesai\n"+
					"Pilih [1-6] > ";
		while(!selesai){
			System.out.println(menu);
		    int pilihan=bacaInt();
			switch(pilihan){
				case 1:doAdd();break;
				case 2:cari();break;
				case 3:
				case 6:selesai=true;break;
				default:
			}
		}

	}
	public void doAdd(){
		System.out.println("Add Data Barang\n");
		System.out.println("ID \t:");

		System.out.println("Nama \t");

		System.out.println("Harga \t");

	}
	private int bacaInt(){
		int i=0;

		return i;
	}
	private String bacaString(){
		String s="";

		return s;
	}
	public static void main(String argv[]){
		MaintainBarang mb=new MaintainBarang();
		mb.cetakMenu();
	}
}

Class Barang

public class Barang{
	private String id;
	private String nama;
	private int harga;
	public Barang(){
	}
	public Barang(String id, String nama, int harga){
		this.id=id;
		this.nama=nama;
		this.harga=harga;
	}
	public String getInfo(){
		return id+";"+nama+";"+harga+"#";
	}
	public String toString(){
		return id+"\t"+nama+"\t"+harga;
	}
	public String getNama(){
		return nama;
	}
	public void setNama(String nama){
		this.nama=nama;
	}
	public String getID(){
		return id;
	}
	public int getHarga(){
		return harga;
	}
	public void setHarga(int harga){
		this.harga=harga;
	}
}

Class FileBarang

import java.util.Vector;
public class FileBarang{
	private Vector dataBarang=new Vector();
	private BacaIO bio;

	public FileBarang(){
		bio=new BacaIO();
	}
	public void addData(Barang b){
		dataBarang.add(b);
		tulisKeFile("databarang.txt");
	}
	public void tulisKeFile(String namaFile){
		String data="";
		for(Barang brg:dataBarang){
			data=data+brg.getInfo();
		}
		bio.tulisKeFile(namaFile,data);
	}
	public void bacaData(String namaFile){
		String data = bio.bacaFile(namaFile);
		String []arrStr=data.split("#");
		for(String str:arrStr){
			if(str.length()>1)
			dataBarang.add(createBarang(str));	
		}
	}
	private Barang createBarang(String str){
		Barang b=null;
		String arrStr[]=str.split(";");
		b=new Barang(arrStr[0],arrStr[1],Integer.parseInt(arrStr[2]));
		return b;
	}
	public Barang cariData(String nama){
		Barang b=null;
		for(Barang brg:dataBarang)
			if(brg.getNama().equals(nama))
			b=brg;
		return b;
	}
	public int cekHarga(String nama){
		Barang b=cariData(nama);
		if (b==null)
		return 0;
		else
		return b.getHarga();
	}
	public void cetakDataBarang(){
		System.out.println("=================================");
		System.out.println(" ID\t  Nama\t  Harga ");
		System.out.println("=================================");
		for(Barang brg:dataBarang)
			System.out.println(brg);
		System.out.println("=================================");
	}

	public static void main(String []argv){
		FileBarang fb=new FileBarang();
		fb.bacaData("databarang.txt");
		fb.cetakDataBarang();
		fb.addData(new Barang("BR03","Penghapus",500));
		System.out.println("Check Harga Buku Gambar:" + fb.cekHarga("Buku Gambar A4"));
	}
}
This entry was posted in PBO. Bookmark the permalink.

33 Responses to Membuat Program Maintenance Data Barang

  1. Super-Duper blog! I am loving it!! Will come back again. I am bookmarking your feeds also.

  2. chanel store says:

    All the time My husband and i bring about my very own Glimmer chanel store, We acquire harmonize with. Everyone wishes to recognize what more or less chanel store I am only including! They in reality be noticeable, fluctuate plus incorporate a very little a gift a powerful dress-up costume. Really good acquisition!

  3. gucci outlet says:

    Have A Peek HERE

  4. Navigate To THIS WebSite

  5. gucci sale says:

    Visit This Web-site

  6. cheap chanel says:

    a large number of ease cheap chanel previously!

  7. insanity dvd says:

    Visit THESE Guys

  8. Pingback: LPZwMCfT

  9. continued says:

    Greetings! I’ve been reading your web site for a while now and finally got the courage to go ahead and give you a shout out from Kingwood Texas! Just wanted to tell you keep up the fantastic job!

  10. simply put i obtained this process buy swtor credits and the situation fights with just when it comes to all things. i favor consumers!

  11. I want the structure!a are incredibly trend. My spouse and i convey guild wars 2 gold day-to-day!

  12. michael kors says:

    You Can Try THIS Out

  13. Hop Over To THIS Site

  14. chanel bags says:

    I’m seeking out Renewable chanel bags with The japanese. Nonetheless couldn’t identify great site. At last I recently found the chanel bags on the websites.

  15. michael kors says:

    Navigate To These Guys

  16. Hi, its pleasant paragraph concerning media print, we all know media is a impressive source of data.

  17. ffxiv gil says:

    Everyone loves THEESE ffxiv gil! they are really comfertable and trendy.that they used this your feet style even when walking with hail that will insured the top ffxiv gil. Furthermore, they are really all too easy to really clean. round for getting my own so next binocular(time honored big bober on ebony:)) <Three

  18. Irrrm a sucker for driving our buy neverwinter astral diamonds about the actual bus pause to running errands as well as the shopping center. They are nice. I are delighted To begin to buy individuals.

  19. Ned Pulk says:

    Appreciate it for helping out, good info. “Considering how dangerous everything is, nothing is really very frightening.” by Gertrude Stein.

Leave a Reply

Your email address will not be published. Required fields are marked *