Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:io';
- void main(){
- var ordervoucher = orderVoucher();
- ordervoucher.topUp();
- }
- class GameVoucher{
- String gameName;
- double price;
- GameVoucher(this.gameName, this.price);
- @override
- String toString(){
- return "Game Name : $gameName\t Price : Rp. $price.00";
- }
- }
- class orderVoucher{
- List <GameVoucher> gameVoucher =[];
- orderVoucher(){
- gameVoucher.add(GameVoucher('PUBG', 350000));
- gameVoucher.add(GameVoucher('Fortnite', 450000));
- gameVoucher.add(GameVoucher('Freefire', 55000));
- gameVoucher.add(GameVoucher('CODM', 660000));
- }
- void displayMenu(){
- print("====-----=======------");
- for (var i = 0; i < gameVoucher.length; i++) {
- print("${i + 1}. ${gameVoucher[i]}");
- }
- print("====-----=======------");
- }
- GameVoucher gameSelection(){
- displayMenu();
- stdout.write("Masukkan pilihan Game Anda [1/2/3/4] : ");
- int choice = int.parse(stdin.readLineSync()!);
- if(choice > 5 && choice < 1){
- throw Exception("Pilihan Game Tidak valid!");
- }
- return gameVoucher[choice - 1];
- }
- int voucherNumber(){
- stdout.write("Jumlah voucher yang akan dibeli : ");
- int jlh = int.parse(stdin.readLineSync()!);
- return jlh;
- }
- String paymentSelection(){
- stdout.writeln("1. Transfer Bank");
- stdout.writeln("2. QRIS");
- stdout.write("Masukkan Jenis Pembayaran : ");
- var payMethod = stdin.readLineSync()!;
- return payMethod;
- }
- void topUp(){
- try {
- var selectedGame = gameSelection();
- var voucherNumz = voucherNumber();
- var methodPayment = paymentSelection();
- print("You order ${voucherNumz} ${selectedGame.gameName} vouchers for Rp. ${selectedGame.price * voucherNumz} by ${methodPayment}");
- } catch (e) {
- print(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement