daily pastebin goal
46%
SHARE
TWEET

я банкир

a guest Mar 13th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         MTBankATM mtbankATM = new MTBankATM(3, 2, 3, 460);
  4.         mtbankATM.receiveMoney(50);
  5.         mtbankATM.giveMoney(40);
  6.         mtbankATM.output();
  7.         mtbankATM.countBanknotes();
  8.         mtbankATM.infoBank();
  9.         mtbankATM.atmProducer();
  10.     }
  11. }
  12.  
  13. public class MTBankATM extends ATM implements InfoBank, ATMProducer {
  14.  
  15.     MTBankATM(int twenty, int fifty, int hundred, int balance) {
  16.         super(twenty, fifty, hundred, balance);
  17.     }
  18.  
  19.     @Override
  20.     public void atmProducer() {
  21.         System.out.println("The producer is your mom.");
  22.     }
  23.  
  24.     @Override
  25.     public void infoBank() {
  26.         System.out.println("You are at ATM #228 na ulice Pushkina dom Kalatushkina.");
  27.     }
  28. }
  29.  
  30. public interface OutputMoney {
  31.     void output();
  32. }
  33.  
  34. public interface GiveMoney {
  35.     void giveMoney(int money);
  36. }
  37.  
  38. public interface ReceiveMoney {
  39.     void receiveMoney(int receivedMoney);
  40. }
  41.  
  42. public interface InfoBank {
  43.     void infoBank();
  44. }
  45.  
  46. public interface ATMProducer {
  47.     void atmProducer();
  48. }
  49.  
  50. public abstract class ATM implements GiveMoney, ReceiveMoney, OutputMoney, CountBanknotes {
  51.     private int twenty; //купюра двадцатки
  52.     private int fifty;
  53.     private int hundred;
  54.     private int balance; // купюры, имеющиеся в обороте банкомата
  55.  
  56.     ATM (int twenty, int fifty, int hundred, int balance) {
  57.         this.twenty = twenty;
  58.         this.fifty = fifty;
  59.         this.hundred = hundred;
  60.         this.balance = balance;
  61.     }
  62.  
  63.     @Override
  64.     public void giveMoney(int money) { //банкомат прощается с деньгами
  65.         if (money > balance) System.out.println("Sorry, this amount is not available.");
  66.         if (money % 100 % 50 % 20 == 0) {
  67.             balance -= money;
  68.             hundred -= money / 100;
  69.             money %= 100;
  70.             fifty -= money / 50;
  71.             money %= 50;
  72.             twenty -= money / 20;
  73.             System.out.println("Money withdrawn successfully.");
  74.         }
  75.         else System.out.println("Please, choose another amount.");
  76.     }
  77.  
  78.     @Override
  79.     public void receiveMoney(int receivedMoney) { //банкомат получает деньги
  80.         if (receivedMoney == 100) {
  81.             balance += 100;
  82.             hundred++;
  83.             System.out.println("Money deposited into your account.");
  84.         }
  85.         else if (receivedMoney == 50) {
  86.             balance += 50;
  87.             fifty++;
  88.             System.out.println("Money deposited into your account.");
  89.         }
  90.         else if (receivedMoney == 20) {
  91.             balance += 20;
  92.             twenty++;
  93.             System.out.println("Money deposited into your account.");
  94.         }
  95.         else System.out.println("Please insert another amount.");
  96.     }
  97.  
  98.     @Override
  99.     public void output() {
  100.         System.out.printf("The ATM's balance is %d.\n", balance);
  101.     }
  102.  
  103.     @Override
  104.     public void countBanknotes() {
  105.         System.out.printf("The following banknotes are available: %d hundreds, %d fifties, %d twenties.\n", hundred, fifty, twenty);
  106.     }
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top