Aplikasi Minimarket Sederhana Dengan C# Posted by Unknown on January 16, 2015 Get link Facebook X Pinterest Email Other Apps using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tugas1_teori { class Program { struct barang { public int harga, jumlah; public string kode, nama; } static void Main(string[] args) { int i = 0,pil2; barang [] b = new barang [0]; do { Console.Clear(); Console.WriteLine("================================="); Console.WriteLine("# 1.Input Barang\t\t#"); Console.WriteLine("# 2.Cetak Barang\t\t#"); Console.WriteLine("# 3.Edit Barang\t\t\t#"); Console.WriteLine("# 4.Hapus Barang\t\t#"); Console.WriteLine("# 5.Exit\t\t\t#"); Console.WriteLine("================================="); Console.Write("Masukkan pilihan anda = "); pil2 =Convert.ToInt32(Console.ReadLine()); Console.WriteLine("================================="); switch(pil2){ case 1: //do{ Array.Resize(ref b, b.Length + 1); string kodesama; int jumlah; Console.Write("\nKode Barang ="); kodesama = Console.ReadLine(); b[b.GetUpperBound(0)].kode = kodesama; Console.Write("Nama Barang ="); b[b.GetUpperBound(0)].nama = Console.ReadLine(); Console.Write("Harga Barang ="); b[b.GetUpperBound(0)].harga = Convert.ToInt32(Console.ReadLine()); Console.Write("Jumlah Barang ="); jumlah=Convert.ToInt32(Console.ReadLine()); b[b.GetUpperBound(0)].jumlah = jumlah; for (int j = 0; j < b.GetUpperBound(0); j++) { if (b[j].kode == kodesama) { b[j].jumlah += jumlah; Array.Resize(ref b, b.Length - 1); } } // Console.Write("Apakah anda ingin menginput data penduduk ? "); //pil = Console.ReadLine(); //} //while (pil == "Y" || pil == "y"); break; case 2: Console.WriteLine("\n==============================================================="); Console.WriteLine("Kode Barang\tNama Barang\t harga barang\t Jumlah barang"); Console.WriteLine("==============================================================="); for (int j = 0; j < b.Length;j++ ) { Console.WriteLine("{0,-15:D} {1,-15:D} {2,15:D} {3,15:D}", b[j].kode, b[j].nama, b[j].harga, b[j].jumlah); Console.WriteLine("---------------------------------------------------------------"); }; //foreach(barang data in b){ // Console.Write("{0} {1} {2} {3}", data.kode, data.nama, data.harga, data.jumlah); //} //} Console.ReadLine(); break; case 3: String cari; Console.Write("\nMasukkan kode yang mau di-Edit ="); cari = Console.ReadLine(); for (int j = 0; j <= b.GetUpperBound(0); j++) { if (cari == b[j].kode) { Console.Write("Kode Barang ="); b[j].kode = Console.ReadLine(); Console.Write("Nama Barang ="); b[j].nama = Console.ReadLine(); Console.Write("Harga Barang ="); b[j].harga = Convert.ToInt32(Console.ReadLine()); Console.Write("Jumlah Barang ="); b[j].jumlah = Convert.ToInt32(Console.ReadLine()); break; } } break; case 4: string hapus; Console.Write("\nMasukkan kode yang mau di-Hapus ="); hapus = Console.ReadLine(); for (int j = 0; j <= b.GetUpperBound(0); j++) { if (b[j].kode == hapus) { for (int k = j; k < b.GetUpperBound(0); k++) { b[k].kode = b[k + 1].kode; b[k].nama = b[k + 1].nama; b[k].harga = b[k + 1].harga; b[k].jumlah = b[k + 1].jumlah; } Array.Resize(ref b, b.Length - 1); break; } } break; } } while (pil2 != 5); Console.ReadKey(); } } } Comments Unknown21 May 2018 at 06:30Tiap konversi ke integer harusnya dibungkus try.. catch supaya pas ada input selain angka exceptionnya ditangkapReplyDeleteRepliesAdmin Uzi27 October 2018 at 06:06Bro, unutk catchnya gimana ya?DeleteRepliesReplyReplyAdd commentLoad more... Post a Comment
Tiap konversi ke integer harusnya dibungkus try.. catch supaya pas ada input selain angka exceptionnya ditangkap
ReplyDeleteBro, unutk catchnya gimana ya?
Delete