File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes programming challenge - 3.5/4 DONE- calculator display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "programming challenge - 3.5/4 DONE- calculator display " Watch "programming challenge - 3.5/4 DONE- calculator display " New topic

programming challenge - 3.5/4 DONE- calculator display

Arvin tirboman

Joined: Sep 16, 2011
Posts: 1

Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

This is not really object oriented. You should try to figure out how you could create a class hierarchy that represents digits in a Seven-segment display way. (

This image gives you quite a lot of help. I would implement this as a base class, (AbstractSevenSegmentDigit) containing booleans if the segment should be printed or not. By default, everything is off.

Then I would create subclasses where I in the constructor sets the segments that are to be lit. The class OneSevenSegmentDigit would look something like this:

What I would like the digits to do is to return to me a two dimensional boolean array that is a multiple of the integer I send into it. Then you can iterate over that array to print "light the board".
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4226

Making a separate class for each digit is *very* heavy handed. Instead I would use a single class that can assert or clear the segments individually, and return a collection of asserted segments.

My example stores the state of the display internally as an int value, and has a hard-coded list of values for each digit.

Note that I only added a toString() method to the SegmentDisplay class to illustrate the correctness of the class. I normally wouldn't add a toString() method that contains line separators. The hard-coded Strings in the Segment enum can then also be removed.

The original poster could add a String[] toLines(int size) method, that returns a String for each line of digit, depending on the length of each segment. These lines can then simply be merged together when there are multiple digits to be printed. For this, methods isHorizontal()/isVertical() could be added to the Segment enum.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Darryl Burke

Joined: May 03, 2008
Posts: 5093

Arvin, we don't have too many rules here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites.

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: programming challenge - 3.5/4 DONE- calculator display
It's not a secret anymore!