Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.  
  12.  
  13.         static barang[] brg = new barang[0];
  14.         struct barang
  15.         {
  16.             public string Tipe;
  17.             public int Harga;
  18.             public int merek;
  19.             public int Jenis;
  20.             public int Jumlah;
  21.             public int Qty;
  22.             public int subtotal()
  23.             {
  24.                 return Harga * Qty;
  25.             }
  26.  
  27.             public enum elektronik
  28.             {
  29.  
  30.                 Kulkas = 1,
  31.                 Tv = 2,
  32.                 AC = 3,
  33.                 Microwave = 4,
  34.                 Smartphone = 5,
  35.             }
  36.  
  37.             public enum mereks
  38.             {
  39.                 Samsung = 1,
  40.                 sharp = 2,
  41.                 lg = 3,
  42.                 panasonic = 4,
  43.  
  44.             }
  45.          
  46.             static void input()
  47.             {
  48.                 Array.Resize(ref brg, brg.Length + 1);
  49.                 Console.Clear();
  50.                 Console.WriteLine("===========================================");
  51.                 Console.WriteLine("                 INPUT DATA                ");
  52.                 Console.WriteLine("===========================================");
  53.                 Console.Write("Masukkan Jumlah elektronik : ");
  54.                 brg[brg.GetUpperBound(0)].Jumlah = int.Parse(Console.ReadLine());
  55.                 Console.WriteLine();
  56.                 Console.WriteLine("Jenis Elektronik : ");
  57.                 Console.WriteLine("1. Kulkas ");
  58.                 Console.WriteLine("2. TV ");
  59.                 Console.WriteLine("3. AC ");
  60.                 Console.WriteLine("4. Microwave ");
  61.                 Console.WriteLine("5. Smartphone ");
  62.                 Console.Write("Masukkan Jenis [1-5] : ");
  63.                 brg[brg.GetUpperBound(0)].Jenis = int.Parse(Console.ReadLine());
  64.                 Console.WriteLine("Merek : ");
  65.                 Console.WriteLine("1. Samsung ");
  66.                 Console.WriteLine("2. Sharp ");
  67.                 Console.WriteLine("3. LG ");
  68.                 Console.WriteLine("4. Panasonic ");
  69.                 Console.Write("Masukkan Merek [1-4] : ");
  70.                 brg[brg.GetUpperBound(0)].merek = int.Parse(Console.ReadLine());
  71.                 Console.Write("Masukkan Tipe : ");
  72.                 brg[brg.GetUpperBound(0)].Tipe = Console.ReadLine();
  73.                 Console.Write("Masukkan Harga : ");
  74.                 brg[brg.GetUpperBound(0)].Harga = int.Parse(Console.ReadLine());
  75.                 Console.Write("Masukkan Qty : ");
  76.                 brg[brg.GetUpperBound(0)].Qty = int.Parse(Console.ReadLine());
  77.  
  78.             }
  79.  
  80.             static void tampil()
  81.             {
  82.                 Console.Clear();
  83.                 Console.Title = "Tampil";
  84.                 DateTime tgl = DateTime.Now;
  85.  
  86.                 Console.WriteLine("============================================================================================");
  87.                 Console.WriteLine("         Jenis           Merek              Tipe         Harga           Qty        Subtotal");
  88.                 Console.WriteLine("============================================================================================");
  89.  
  90.                 foreach (barang data in brg)
  91.                 {
  92.                    
  93.                     Console.WriteLine( " "+ data.Jenis       + data.merek + data.Tipe.PadRight(7) + data.Harga.ToString("0.000").PadRight(5) + data.Qty + data.subtotal().ToString("0.00"));
  94.                 }
  95.  
  96.             }
  97.                 static void Main(string[] args)
  98.             {
  99.                 Console.Title = "Elektronik";
  100.                 int kode;
  101.             ulang:
  102.                 Console.Clear();
  103.                 Console.WriteLine("                        MENU                      ");
  104.                 Console.WriteLine("==================================================");
  105.                 Console.WriteLine("1. Input Data ");
  106.                 Console.WriteLine("2. Tampil Data ");
  107.                 Console.WriteLine("3. Input Keluar ");
  108.                 Console.WriteLine("==================================================");
  109.                 kode = int.Parse(Console.ReadLine());
  110.                 if (kode == 1)
  111.                 {
  112.                     input();
  113.                 }
  114.                 else
  115.                 if (kode == 2)
  116.                 {
  117.                     tampil();
  118.                 }
  119.                 else if (kode == 3)
  120.                 {
  121.                     Environment.Exit(0);
  122.                 }
  123.                 else
  124.                 {
  125.                     Console.WriteLine("Kode tidak valid.");
  126.                 }
  127.                 Console.ReadKey();
  128.                 goto ulang;
  129.  
  130.             }
  131.  
  132.          
  133.  
  134.             }
  135.  
  136.         }
  137.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement