import java.util.concurrent.atomic.AtomicInteger; /* * Goal: maintain a fixed ratio between length and width. * This implementation is NOT thread safe. */ public class AspectRatio { private final AtomicInteger length = new AtomicInteger(0); private final AtomicInteger width = new AtomicInteger(0); public AspectRatio(int l,int w) { length.set(l); width.set(w); } public void setLength(int newLength) { double ratio = ((double) length.get()) / width.get(); this.length.set(newLength); this.width.set((int) (newLength / ratio)); } public int getWidth() { return width.get(); } public int getLength() { return length.get(); } }