• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

programming challenge - 3.5/4 DONE- calculator display

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic