Java

Банкомат v1

package bankomat;

public class Term {

private int count5000=0;
private int count1000=0;
private int count500=0;
private int count100=0;
private final int MAX_MONEY=200000;

public void setMoney(int money5000,int money1000,int money500,int money100)
{
count5000=money5000;
count1000=money1000;
count500=money500;
count100=money100;
}

Term(int money5000,int money1000,int money500,int money100)
{
count5000=money5000;
count1000=money1000;
count500=money500;
count100=money100;
}

private long allMoney()
{
    return 5000*count5000+1000*count1000+500*count500+100*count100;
}

private boolean haveMoney(int userWantMoney)
{
boolean res=true;

if (userWantMoney>MAX_MONEY) 
{
res=false;    
System.out.print("Выдача ограничена суммой "+MAX_MONEY);
}
    
if (userWantMoney>allMoney()) 
{
res=false;    
System.out.print("Закончились деньги в терминале");
}
return res;
}

public void getMoney(int userSum)
{
    
int tempSum=userSum;

if (userSum%100!=0)
{
    System.out.println("Могу выдать сумму только кратную 100");
}

if (haveMoney(userSum) && (userSum%100==0))
{
    
while (tempSum>=5000)        
    
{
tempSum-=5000;
System.out.println("5000");
}

while (tempSum>=1000)        
    
{
tempSum-=1000;
System.out.println("1000");
}

while (tempSum>=500)        
    
{
tempSum-=500;
System.out.println("500");
}

while (tempSum>=100)        
    
{
tempSum-=100;
System.out.println("100");
}}}}    


Вызов

Term t1=new Term(34,23,1,2);
t1.getMoney(12700);