Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How to implement with Collection  RSS feed

 
Greenhorn
Posts: 3
Android Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

nice to make my first post.

I like to implement this class using some collection what do you think what type of collection can I use? and why?


led-matrix2.jpg
[Thumbnail for led-matrix2.jpg]
 
Bartender
Posts: 9545
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? Is the array not working out for you?

I'm all for using collections over arrays, but if the collection doesn't grow have to grow dynamically, and the choice of using an array or a collection doesn't leak into your public API, you might as well use an array. More immediate issues:

  • You're using magic values everywhere. Why do you iterate starting at 7? What's special about x and y positions 2, 3, 5 and 6?
  • You're not using appropriate types for your abstractions. A color should not be represented by an integer.
  • Your constructor does more than just initializing your class. Why is it sending anything to a TCP client?
  • On that note, why is TCPClient.sentToBoard() a static method? It's got a typo by the way.
  • Why does DisplayBoard know anything about using TCP anyway?
  • Avoid the public keyword. Classes should have default access unless you intend to use them outside of your package. Fields must be private in pretty much all cases.
  • Make classes final unless you have a really good reason to extend them.
  •  
    Fadel Cazor
    Greenhorn
    Posts: 3
    Android Java Python
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why? Is the array not working out for you?
    R: It's ok, but I did it for an excercise in a course, but now I think to use it idea to solve another problems and applications

    I'm all for using collections over arrays, but if the collection doesn't grow have to grow dynamically, and the choice of using an array or a collection doesn't leak into your public API, you might as well use an array.
    R. I think to use another structure for example to draw non regular shape (maybe a face) and for a mor big led matrix

    More immediate issues:

    You're using magic values everywhere. Why do you iterate starting at 7?
    R: Nothing magic I wrote the excercise as is because I started thinking to draw from the middle of the matrix to the edges, then I forgot to modify it.

    What's special about x and y positions 2, 3, 5 and 6?
    R: As you can see the led's have a regular shape defined in the exercise enunciate, thes vaues define the dots range by each color.

    You're not using appropriate types for your abstractions. A color should not be represented by an integer.
    R: You are right, It's is only an exrcise please excuse me  I will do that you say for some real progam.

    Your constructor does more than just initializing your class. Why is it sending anything to a TCP client?
    R: This method fill the array with values 1,2 or 3, then it's sending to the gadget (I think) by some TCP interface to led display as the image show.

    On that note, why is TCPClient.sentToBoard() a static method? It's got a typo by the way.
    Why does DisplayBoard know anything about using TCP anyway?
    R: You can suppose that the TCPClient.sentToBoard() works well because it's part of the enunciate to the execise and as yu can see the image show the led display is ok.

    Avoid the public keyword. Classes should have default access unless you intend to use them outside of your package. Fields must be private in pretty much all cases.
    R: ok you are rigth, I will do this in the future, excuse me please

    Make classes final unless you have a really good reason to extend them.
    R: ok you are rigth, I will do this in the future, excuse me please
     
    Stephan van Hulst
    Bartender
    Posts: 9545
    188
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Fadel Cazor wrote:I think to use another structure for example to draw non regular shape (maybe a face) and for a mor big led matrix


    Okay, for that I would suggest you create a class that represents a position in the LED matrix, an enum that represents the colors you can use (unless the colors can be created through modulation, in which case you might want to create a class that encapsulates RGB values) and then you can keep track of the state of the LEDs using a Map<Position, Color>.

    As you can see the led's have a regular shape defined in the exercise enunciate, thes vaues define the dots range by each color.


    Yes, but that's only an example, right? I assume that any LED in the matrix can be controlled to have a different color, and also that you can use the application with matrix boards that have different sizes. So hard coding those values is not a good idea. Pass the board size as constructor parameters, and set the colors of the LEDs using a separate method after you've constructed the board.

    This method fill the array with values 1,2 or 3, then it's sending to the gadget (I think) by some TCP interface to led display as the image show.


    I assume that method was written by your teacher then. In a real application, the representation should not know about TCP, and it's not your board class that controls the device, but the class that uses your board class.
     
    Master Rancher
    Posts: 3036
    106
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Must you use an array or a collection?

    I was thinking of a BufferedImage instead, and write any character (or another image) to it. It would make the class very flexible with ease.

    If your BufferedImage is say nxn pixels, and you want each pixel to be a block of mxm pixels, then you can simply enlarge your bi.

    And for tcp: all you need is to send n, m, and the character (or the nxn pixel information), plus perhaps some color information.
     
    He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
    Programmatically Create PDF Using Free Spire.PDF with Java
    https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!