Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- MTBankATM mtbankATM = new MTBankATM(3, 2, 3, 460);
- mtbankATM.receiveMoney(50);
- mtbankATM.giveMoney(40);
- mtbankATM.output();
- mtbankATM.countBanknotes();
- mtbankATM.infoBank();
- mtbankATM.atmProducer();
- }
- }
- public class MTBankATM extends ATM implements InfoBank, ATMProducer {
- MTBankATM(int twenty, int fifty, int hundred, int balance) {
- super(twenty, fifty, hundred, balance);
- }
- @Override
- public void atmProducer() {
- System.out.println("The producer is your mom.");
- }
- @Override
- public void infoBank() {
- System.out.println("You are at ATM #228 na ulice Pushkina dom Kalatushkina.");
- }
- }
- public interface OutputMoney {
- void output();
- }
- public interface GiveMoney {
- void giveMoney(int money);
- }
- public interface ReceiveMoney {
- void receiveMoney(int receivedMoney);
- }
- public interface InfoBank {
- void infoBank();
- }
- public interface ATMProducer {
- void atmProducer();
- }
- public abstract class ATM implements GiveMoney, ReceiveMoney, OutputMoney, CountBanknotes {
- private int twenty; //купюра двадцатки
- private int fifty;
- private int hundred;
- private int balance; // купюры, имеющиеся в обороте банкомата
- ATM (int twenty, int fifty, int hundred, int balance) {
- this.twenty = twenty;
- this.fifty = fifty;
- this.hundred = hundred;
- this.balance = balance;
- }
- @Override
- public void giveMoney(int money) { //банкомат прощается с деньгами
- if (money > balance) System.out.println("Sorry, this amount is not available.");
- if (money % 100 % 50 % 20 == 0) {
- balance -= money;
- hundred -= money / 100;
- money %= 100;
- fifty -= money / 50;
- money %= 50;
- twenty -= money / 20;
- System.out.println("Money withdrawn successfully.");
- }
- else System.out.println("Please, choose another amount.");
- }
- @Override
- public void receiveMoney(int receivedMoney) { //банкомат получает деньги
- if (receivedMoney == 100) {
- balance += 100;
- hundred++;
- System.out.println("Money deposited into your account.");
- }
- else if (receivedMoney == 50) {
- balance += 50;
- fifty++;
- System.out.println("Money deposited into your account.");
- }
- else if (receivedMoney == 20) {
- balance += 20;
- twenty++;
- System.out.println("Money deposited into your account.");
- }
- else System.out.println("Please insert another amount.");
- }
- @Override
- public void output() {
- System.out.printf("The ATM's balance is %d.\n", balance);
- }
- @Override
- public void countBanknotes() {
- System.out.printf("The following banknotes are available: %d hundreds, %d fifties, %d twenties.\n", hundred, fifty, twenty);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement