Senin, 03 Oktober 2011

Program Kantin Java - OOP (Object Oriented Programming)



/*
* author : mochamad Rifai Idris
* Nim : 10.41010.0153
* Program : KantinJava
*/
import java.io.*;
class KantinJava
{
public static void main (String []args)
throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
Menu menu = new Menu();
String AdminUser;
System.out.print("Admin/User : ");
AdminUser = br.readLine();
menu.setAdmin(AdminUser);
menu.Cetak();

}
}

-------------------------------------------end program------------------------------

import java.io.*;
import java.util.Vector;
class Menu
{
//Menu menu = new Menu();
private String AdminUser;
private int pil=0;

public void setAdmin(String AdminUser)
{
this.AdminUser = AdminUser;
}

public String getAdmin()
{
return AdminUser;
}

void Cetak()
throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
//do
//{
Transaksi transaksi = new Transaksi();
if (getAdmin().equalsIgnoreCase("admin"))
{
do
{
System.out.println("++++++++++++++++++++++++++++++++++");
System.out.println("Menu Transaksi");
System.out.println("++++++++++++++++++++++++++++++++++");
System.out.println("1. Add Makanan");
System.out.println("2. Update Makanan");
System.out.println("3. Penjualan Makanan");
System.out.println("4. View All Makanan");
System.out.println("5. View All Transaksi");
System.out.println("6. Keluar");
System.out.print("Masukan Pilihan Anda : " );
pil = Integer.parseInt(br.readLine());
System.out.println();

if (pil==1)
{
transaksi.InputMakanan();
}
else if (pil==2)
{
transaksi.UpdateMakanan();
}
else if (pil==3)
{
transaksi.PesananMakanan();
}
else if (pil==4)
{
transaksi.LaporanMakanan();
}
else if (pil==5)
{
transaksi.LaporanTransaksi();
}
else if(pil==6)
{
System.exit(0);
}

}
while (pil!=6);


}
else if (getAdmin().equalsIgnoreCase("user"))
{
transaksi.PesananMakanan();
}
else if (getAdmin().equalsIgnoreCase("exit"))
{
System.exit(0);
}
else
{
System.out.println("user tidak dikenali");
}
//}
//while (!(getAdmin().equals("admin")));
}
}

--------------------------------------------end program--------------------------

import java.io.*;
class Transaksi
{
private int [] IdMakanan = new int [1000];
private String [] NamaMakanan = new String [1000];
private int [] HargaMakanan = new int [1000];

private int [] IdTransaksi = new int [1000];
private int [] IdPesanan = new int [1000];
private int [] JumlahPesanan = new int [1000];
private int [] TotalPesanan = new int [1000];

private int id=0;
private int id2=0;
private int cari=0;
private String InputMakanan;

void cari()
{

}

void InputMakanan()
throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
while (true)
{
System.out.print("Input Data Makanan (y/n) : ");
InputMakanan = br.readLine();
if (InputMakanan.equals("n"))
{
break;
}
else
{
id = id + 1;
System.out.println("No Makanan : " + id);
IdMakanan [id] = id;
System.out.print("Nama Makanan : ");
NamaMakanan [id] = br.readLine();
System.out.print("Harga Makanan : ");
HargaMakanan[id] = Integer.parseInt(br.readLine());
}
System.out.println();
}
}

void UpdateMakanan()
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
{
System.out.println("Data Sebelum Diupdate");
LaporanMakanan();
System.out.println();
System.out.print("Masukan No. Id dari Makanan yang Ingin Dirubah : ");
int RubahId = Integer.parseInt(br.readLine());

for (int i=1; i<=id; i++)
{
if (IdMakanan[i] == RubahId)
{
System.out.print("Nama Makanan : ");
NamaMakanan [RubahId] = br.readLine();
System.out.print("Harga Makanan : ");
HargaMakanan [RubahId] = Integer.parseInt(br.readLine());
System.out.println("Data Sesudah Diupdate");
LaporanMakanan();
}
else if (IdMakanan[i]!=RubahId)
{
if (i==id)
{
System.out.println("data tidak ada");
}
}

}
}
}

void LaporanMakanan()
{
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(" Data Makanan Warung Serba Murah ");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("No Nama Makanan Harga ");
System.out.println("------------------------------------------------------");
for (int a=1;a<=id;a++ )
{
System.out.println(IdMakanan[a]+" " + NamaMakanan[a]+" "+HargaMakanan[a]);
}
System.out.println("------------------------------------------------------");
}

void LaporanTransaksi()
{
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(" Data Semua Transaksi ");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("NoTransaksi No NamaMakanan Jumlah Harga Total");
System.out.println("------------------------------------------------------");
for (int a=1;a<=id2;a++ )
{
System.out.println(IdTransaksi[a]+" " + IdPesanan[a]+" "+
NamaMakanan[a]+" "+JumlahPesanan[a]+" "+HargaMakanan[a]+" "+TotalPesanan[a]);
}
System.out.println("------------------------------------------------------");
}

void PesananMakanan()
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
{
LaporanMakanan();
System.out.println();
System.out.println("----Form Pemesanan Makanan----");
while (true)
{
System.out.print("Apakah anda ingin memesan makan ? (y/n) :");
String pesanan = br.readLine();
if (pesanan.equals("n"))
{
//System.exit(0);
break;
}
else
{

id2 = id2 + 1;
System.out.println("No Transaksi : " + id2);
IdTransaksi [id2] = id2;
System.out.print("No. Makanan : ");
IdPesanan [id2] = Integer.parseInt(br.readLine());
System.out.println("Nama Makanan : " + NamaMakanan[IdPesanan[id2]]);
System.out.println("Harga Makanan : " + HargaMakanan[IdPesanan[id2]]);
System.out.print("Jumlah Pesan : ");
JumlahPesanan [id2] = Integer.parseInt(br.readLine());
System.out.println("Total Harga : " +
(JumlahPesanan[id2]*HargaMakanan[IdPesanan[id2]]));
TotalPesanan [id2] = (HargaMakanan[id2]*HargaMakanan[IdPesanan[id2]]) ;
}
System.out.println();
}
}
}
}

2 komentar:

 
Copyright 2011 @ learning for sharing!