• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to get a String representation of the attributes of an Object located in an Array

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,
I have the following empty method inherited from an Interface:



The purpose is to query an array at position row, column and get the attributes of the Object that sits in that position.
The objects are Logic Operation cells that contain the following attributes:
char type; (A Letter sign that each cell has ('A' for an and-gate, 'R' for an or-gate, 'W' for a pass through gate, etc....))
char signal; (either a "0", "1", or "-" for a cell that has no state yet.)
int orientation; (Each cell can be pictured as a square with four sides that can be rotated. The original state sign is >, 90° left is ^, 180° left from original state is <, 270° from original state is v, and back to >)

all these attributes are contained within each cell and the resulting String should be of the following format: "W1 ^" for a cell of Type 'W' with state 1 and rotated 90° so it looks up (Original state always looks right).

How could I implement this in this Method? I know that I have to query the array with the row and column parameters, but im not sure of the syntax or commands to extract the needed information from the cell contained in the array.

Name of the Array is "simGrid"
THanks!!!

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual approach would be to write a custom toString() method for the class of the objects being stored in the array.

Bill
 
Rancher
Posts: 1049
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dennis,
You have to look at the cell and see what there are for getters or public access to the cell properties. How you do the representation is up to you, but how it's accessed is up to the original writer of the class. As a rule of thumb, I try to make a representation that I could read and reverse the process, so I could read the string representation and initialize an object back to that state.
Les

Dennis Von Valkenburgh wrote:Hello Ranchers,
I have the following empty method inherited from an Interface:



The purpose is to query an array at position row, column and get the attributes of the Object that sits in that position.
The objects are Logic Operation cells that contain the following attributes:
char type; (A Letter sign that each cell has ('A' for an and-gate, 'R' for an or-gate, 'W' for a pass through gate, etc....))
char signal; (either a "0", "1", or "-" for a cell that has no state yet.)
int orientation; (Each cell can be pictured as a square with four sides that can be rotated. The original state sign is >, 90° left is ^, 180° left from original state is <, 270° from original state is v, and back to >)

all these attributes are contained within each cell and the resulting String should be of the following format: "W1 ^" for a cell of Type 'W' with state 1 and rotated 90° so it looks up (Original state always looks right).

How could I implement this in this Method? I know that I have to query the array with the row and column parameters, but im not sure of the syntax or commands to extract the needed information from the cell contained in the array.

Name of the Array is "simGrid"
THanks!!!

 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic