package euler; public class Change { private int one; private int two; private int five; private int ten; private int twenty; private int fifty; private int pound; private int twopound; public Change( int x) { twopound = x; } public boolean makeChange() { if(two>0) { two -= 1; one += 2; }else if(five>0) { five -= 1; two += 2; one += 1; }else if(ten>0) { ten -= 1; five += 2; }else if(twenty>0) { twenty -= 1; ten += 2; }else if(fifty>0) { fifty -= 1; twenty += 2; ten += 1; }else if(pound>0) { pound -= 1; fifty += 2; }else if(twopound>0) { twopound -= 1; pound += 2; } else return false; return true; } public int sum() { return one+2*two+5*five+10*ten+20*twenty+50*fifty+100*pound+200*twopound; } public String toString() { return one+"x1p + "+two + "x2p + "+five + "x5p + "+ten+"x10p + "+twenty+"x20p + "+fifty+"x50p + "+pound+"x100p + "+twopound+"x200p"; } }