aspose file tools*
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 Spring in Action 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
Author

programming challenge - 3.5/4 DONE- calculator display

Arvin tirboman
Greenhorn

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. (http://en.wikipedia.org/wiki/Seven-segment_display).



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
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

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.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

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

http://www.java-forums.org/advanced-java/48597-programming-challenge-calculator-display.html


luck, db
There are no new questions, but there may be new answers.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: programming challenge - 3.5/4 DONE- calculator display