Advertisement
qee20

Game Voucher

Mar 22nd, 2024
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.83 KB | Source Code | 0 0
  1. import 'dart:io';
  2.  
  3. void main(){
  4.   var ordervoucher = orderVoucher();
  5.  
  6.   ordervoucher.topUp();
  7. }
  8.  
  9.  
  10. class GameVoucher{
  11.   String gameName;
  12.   double price;
  13.  
  14.   GameVoucher(this.gameName, this.price);
  15.  
  16.   @override
  17.   String toString(){
  18.     return "Game Name : $gameName\t Price : Rp. $price.00";
  19.   }
  20. }
  21.  
  22. class orderVoucher{
  23.   List <GameVoucher> gameVoucher =[];
  24.  
  25.   orderVoucher(){
  26.     gameVoucher.add(GameVoucher('PUBG', 350000));
  27.     gameVoucher.add(GameVoucher('Fortnite', 450000));
  28.     gameVoucher.add(GameVoucher('Freefire', 55000));
  29.     gameVoucher.add(GameVoucher('CODM', 660000));
  30.   }
  31.  
  32.   void displayMenu(){
  33.     print("====-----=======------");
  34.     for (var i = 0; i < gameVoucher.length; i++) {
  35.       print("${i + 1}. ${gameVoucher[i]}");
  36.     }
  37.     print("====-----=======------");
  38.   }
  39.  
  40.   GameVoucher gameSelection(){
  41.     displayMenu();
  42.     stdout.write("Masukkan pilihan Game Anda [1/2/3/4] : ");
  43.     int choice = int.parse(stdin.readLineSync()!);
  44.     if(choice > 5 && choice < 1){
  45.       throw Exception("Pilihan Game Tidak valid!");
  46.     }
  47.     return gameVoucher[choice - 1];
  48.   }
  49.  
  50.   int voucherNumber(){
  51.     stdout.write("Jumlah voucher yang akan dibeli : ");
  52.     int jlh = int.parse(stdin.readLineSync()!);
  53.     return jlh;
  54.   }
  55.  
  56.  
  57.  
  58.   String paymentSelection(){
  59.     stdout.writeln("1. Transfer Bank");
  60.     stdout.writeln("2. QRIS");
  61.     stdout.write("Masukkan Jenis Pembayaran : ");
  62.     var payMethod = stdin.readLineSync()!;
  63.     return payMethod;
  64.   }
  65.  
  66.   void topUp(){
  67.     try {
  68.       var selectedGame = gameSelection();
  69.       var voucherNumz = voucherNumber();
  70.       var methodPayment = paymentSelection();
  71.  
  72.       print("You order ${voucherNumz} ${selectedGame.gameName} vouchers for Rp. ${selectedGame.price * voucherNumz} by ${methodPayment}");
  73.     } catch (e) {
  74.       print(e);
  75.     }
  76.   }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement