File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Simulating Power Supply Unit. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simulating Power Supply Unit." Watch "Simulating Power Supply Unit." New topic

Simulating Power Supply Unit.

Ted Scofield

Joined: Apr 04, 2009
Posts: 26
Hi all,

I'm trying to create a power supply unit simulation. In order to do so, I must use the following interface:

Ramping should be implemented concurrently, so that other interface methods (except loadRamp) are available at all times.

This is my solution:

I'm a bit worried with the following:

1) Is the design OK? Could it be more elegant?
2) Is there an elegant way of enabling methods only when the unit is turned on (and not using ifs)?
3) Is the startRamp method designed OK, or could this be done better?
4) Are exceptions in set method necessary or should I just ignore the method if the device is ramping or off or value < 0? What would you do?

If you have any other comments or tips/advices, I'd be very thankful.

Thank you,
David Newton

Joined: Sep 29, 2008
Posts: 12617

I'd ramp to the new value if the unit is currently ramping.

You might want look into various ways of implementing state machines.

I'd name the interface something other than Methods, since methods are the only things that should be in an interface--name it something more descriptive.

I'm a little wary of the "isDoneRamping" variable; from a cursory inspection of the code it's not clear to me what its purpose is--what differentiates it from !isRamping?

I'd also be wary of non-synchronized access to shared variables--if there are multiple threads accessing the same value there's always the possibility of someone walking over someone else's value. Depends on usage, obviously; just something to be aware of.
I agree. Here's the link:
subject: Simulating Power Supply Unit.
It's not a secret anymore!