Help with encapsulation and a specific case of design

Hello all. I have been playing with Java (my first real language and first OOP language) for a couple months now. Right now I am trying to write my first real application, but I want to design it right and I am smashing my head against the wall with my data structure, specifically with encapsulation.
I go into detail about my app below, but it gets long so for those who don't want to read that far, let me just put these two questions up front:
1) How do principles of encapsulation change when members are complex objects rather than primitives? If the member objects themselves have only primitive members and show good encapsulation, does it make sense to pass a reference to them? Or does good encapsulation demand that I deep-clone all the way to the bottom of my data structure and pass only cloned objects through my top level accessors? Does the analysis change when the structure gets three or four levels deep? Don't DOM structures built of walkable nodes violate basic principles of encapsulation?
2) "Encapsulation" is sometimes used to mean no public members, othertimes to mean no public members AND no setter methods. The reasons for the first are obvious, but why go to the extreme of the latter? More importantly HOW do you go to the extreme of the latter? Would an "updatePrices" method that updates encapsulated member prices based on calculations, taking a single argument of say the time of year be considered a "setter" method that violates the stricter vision of encapsulation?
Even help with just those two questions would be great. For the masochistic, on to my app... The present code is at
http://www.immortalcoil.org/drake/Code.zip
The most basic form of the application is statistics driven flash card software for Japanese Kanji (Chinese characters). For those who do not know, these are ideographic characters that represent concepts rather than sounds. There are a few thousand. In abstract terms, my data structure needs to represent the following.
-  There are a bunch of kanji.
   Each kanji is defined by:
   -  a single character (the kanji itself); and
   -  multiple readings which fall into two categories of "on" and "kun".
      Each reading is defined by:
      -  A string of hiragana or katakana (Japanese phoenetic characters); and
      -  Statistics that I keep to represent knowledge of that reading/kanji pair.Ideally the structure should be extensible. Later I might want to add statistics associated with the character itself rather than individual readings, for example. Right now I am thinking of building a data structure like so:
-  A Vector that holds:
   -  custom KanjiEntry objects that each hold
      -  a kanji in a primitive char value; and
      -  two (on, kun) arrays or Vectors of custom Reading objects that hold
         -  the reading in a String; and
         -  statistics of some sort, probably in primitive valuesFirst of all, is this approach sensible in the rough outlines?
Now, I need to be able to do the obvious things... save to and load from file, generate tables and views, and edit values. The quesiton of editting values raises the questions I identified above as (1) and (2). Say I want to pull up a reading, quiz the user on it, and update its statistics based on whether the user got it right or wrong. I could do all this through the KanjiEntry object with a setter method that takes a zillion arguments like:
theKanjiEntry.setStatistic(
"on",   // which set of readings
2,      // which element in that array or Vector
"score", // which statistic
98);      // the valueOr I could pass a clone of the Reading object out, work with that, then tell the KanjiEntry to replace the original with my modified clone.
My instincts balk at the first approach, and a little at the second. Doesn't it make more sense to work with a reference to the Reading object? Or is that bad encapsulation?
A second point. When running flash cards, I do not care about the subtlties of the structure, like whether a reading is an on or a kun (although this is important when browsing a table representing the entire structure). All I really care about is kanij/reading pairings. And I should be able to quickly poll the Reading objects to see which ones need quizzing the most, based on their statistics. I was thinking of making a nice neat Hashtable with the keys being the kanji characters in Strings (not the KanjiEntry objects) and the values being the Reading objects. The result would be two indeces to the Reading objects... the basic structure and my ad hoc hashtable for runninq quizzes. Then I would just make sure that they stay in sync in terms of the higher level structure (like if a whole new KanjiEntry got added). Is this bad form, or even downright dangerous?
Apart from good form, the other consideration bouncing around in my head is that if I get all crazy with deep cloning and filling the bottom level guys with instance methods then this puppy is going to get bloated or lag when there are several thousand kanji in memory at once.
Any help would be appreciated.
Drake

Usually by better design. Move methods that use the
getters inside the class that actually has the data....
As a basic rule of thumb:
The one who has the data is the one using it. If
another class needs that data, wonder what for and
consider moving that operation away from that class.
Or move from pull to push: instead of A getting
something from B, have B give it to A as a method
call argument.Thanks for the response. I think I see what you are saying.. in my case it is something like this.
Solution 1 (disfavored):
public class kanjiDrill{ // a chunk of Swing GUI or something
     public void runDrill(Vector kanjiEntries){
          KanjiEntry currentKanjiEntry = kanjiEntries.elementAt(0); // except really I will pick one randomly
          char theKanji = currentKanjiEntry.getKanji();
          String theReading = currentKanjiEntry.getReading();
          // build and show a flashcard based on theKanji and theReading
          // use a setter to change currentKanji's data based on whether the user answers correctly;
}Solution 2 (favored):
public class kanjiDrill{ // a chunk of Swing GUI or something
     public void runDrill(Vector kanjiEntries){
          KanjiEntry currentKanjiEntry = kanjiEntries.elementAt(0); // except really I will pick one randomly
          currentKanji.buildAndShowFlashcard(); // method includes updating stats
}I can definitely see the advantages to this, but two potential reasons to think hard about it occur to me right away. First, if this process is carried out to a sufficient extreme the objects that hold my data end up sucking in all the functionality of my program and my objects stop resembling natural concepts.
In your shopping example, say you want to generate price tags for the items. The price tags can be generated with ONLY the raw price, because we do not want the VAT on them. They are simple GIF graphics that have the price printed on a an irregular polygon. Should all that graphics generating code really go into the item objects, or should we just get the price out of the object with a simple getter method and then make the tags?
My second concern is that the more instance methods I put into my bottom level data objects the bigger they get, and I intend to have thousands of these things in memory. Is there a balance to strike at some point?
It's not really a setter. Outsiders are not setting
the items price - it's rather updating its own price
given an argument. This is exactly how it should be,
see my above point. A breach of encapsulation would
be: another object gets the item price, re-calculates
it using a date it knows, and sets the price again.
You can see yourself that pushing the date into the
item's method is much beter than breaching
encapsulation and getting and setting the price.So the point is not "don't allow access to the members" (which after all you are still doing, albeit less directly) so much as "make sure that any functionality implicated in working with the members is handled within the object," right? Take your shopping example. Say we live in a country where there is no VAT and the app will never be used internationally. Then we would resort to a simple setter/getter scheme, right? Or is the answer that if the object really is pure data are almost so, then it should be turned into a standard java.util collection instead of a custom class?
Thanks for the help.
Drake

Similar Messages

  • Help with count and sum query

    Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
    SELECT 'ST' LEDGER,
    CASE
    WHEN c.Category = 'E' THEN 'Headcount Exempt'
    ELSE 'Headcount Non-Exempt'
    END
    ACCOUNTS,
    CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
    'MARCH_12' AS PERIOD,
    COUNT (a.empl_id) head_count
    FROM essbase.employee_pubinfo a
    LEFT OUTER JOIN MMS_DIST_COPY b
    ON a.cost_ctr = TRIM (b.bu)
    INNER JOIN MMS_GL_PAY_GROUPS c
    ON a.pay_group = c.group_code
    WHERE a.employee_status IN ('A', 'L', 'P', 'S')
    AND FISCAL_YEAR = '2012'
    AND FISCAL_MONTH = 'MARCH'
    GROUP BY a.company,
    b.district,
    a.cost_ctr,
    c.category,
    a.fiscal_month,
    a.fiscal_year;
    which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    user610131 wrote:
    ... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
    I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
    You may want both a sub-query and a different GROUP BY clause. For example:
    WITH    got_group_by_columns     AS
         SELECT  a.empl_id
         ,     CASE
                        WHEN  c.category = 'E'
                  THEN  'Headcount Exempt'
                        ELSE  'Headcount Non-Exempt'
                END          AS accounts
         ,       CASE
                        WHEN a.company = 'ZEE'
                        THEN 'OH'
                        ELSE 'NA'
                END          AS market
         FROM              essbase.employee_pubinfo a
         LEFT OUTER JOIN  mms_dist_copy             b  ON   a.cost_ctr     = TRIM (b.bu)
         INNER JOIN       mms_gl_pay_groups        c  ON   a.pay_group      = c.group_code
         WHERE     a.employee_status     IN ('A', 'L', 'P', 'S')
         AND        fiscal_year           = '2012'
         AND        fiscal_month          = 'MARCH'
    SELECT    'ST'               AS ledger
    ,       accounts
    ,       market
    ,       'MARCH_12'          AS period
    ,       COUNT (empl_id)       AS head_count
    FROM       got_group_by_columns
    GROUP BY  accounts
    ,            market
    ;But that's just a wild guess.
    You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
    Edited by: Frank Kulash on Apr 4, 2012 5:31 PM

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • MOVED: [Athlon64] Need Help with X64 and Promise 20378

    This topic has been moved to Operating Systems.
    [Athlon64] Need Help with X64 and Promise 20378

    I'm moving this the the Administration Forum.  It seems more apporpiate there.

  • Help with partitions and file systems [SOLVED]

    Hi, i have been using Ubuntu for a while, and now i want to move to Arch. I've probed it in a PC and i like so i want to make que change.
    But, before installing Arch, I have 2 doubts. I red the beginners guide and also the instalation guide. There it says that if better to have diferents partitions for  /, /boot/, /home, /usr, /var, y /tmp
    Usually, i alwayes used something like this:
        * /boot (32megas)
        * /swap (512 megas)
        * /root (6 a 8 gigas)
        * /home (80 gigas aprox)
    It's really better to also have partitions for /var, /usr y /tmp? o some of them? and, in that case, wich size should i give them? because i don't want to make them too small, but i don't want to waste disk space neither.
    Adn that takes me to my second question, wich filesystem is better for each partitionn? in many places, i read taht JFS its good for /var or that XFS if better for /home and big files
    I thinked to use something like this:
        * /boot (ext2)
        * / (JFS)
        * swap
        * /home (XFS)
    Is a good design? or should i use other filesystem like reiserfs, etc... and for /var, /usr and /tmp partition, wich one should i use?
    Thank you
    Ps: This Pc is gonna be a desktop pc
    Ps2: sorry for my bad english. it is not my real lenguage
    Reason of edit: added the swap partition. I forgot it
    Last edited by Thalskarth (2008-12-21 20:11:00)

    thanks everybody for the help,
    kaola_linux wrote:@Thalskarth - it's better to have /var especially if you're using ext3 or other filesystems which was designed for larger files as your partition for /home and /.  Having a seperate partition for /var would be nice (backup purposes and reinstalling without downloading the entire package whole over again). 5gb would be sufficient for your /var, anyway you can always resize it to your needs.
    so, a 5gb partition in reiserfs would be OK for a /var
    Inxsible wrote:
    Lot of people also use XFS which is known to have better performance with huge files. I think EXT3 offers a good balance...because I am never sure whether my home partition will have all huge files or not..same with my external drive...so i just use EXT3
    If you have a specific partition for movies or some video/audio editing that you do..you may wanna consider XFS too. I don't do all that...so I have never used XFS. I wouldn't know the exact performance difference between ext3 and XFS.
    Yes, in many places i red that XFS is better for big files. But i couldn't fine wich is the meaning of "big file". Does it mean a 200 mg file? or a 4.4gb one??
    the same applies to reiserFs, what is a small file? a 1mg one or a 4kb one?
    I have alwayes used ext3, i thinked in XFS and JFS just to give them a try.
    amranu wrote:I have no idea about better filesystems, all my partitions are ext3 (soon to be ext4)
    Inxsible wrote:One thing that makes me wanna keep EXT3 is that EXT4 is coming out (soon?) and you can upgrade from 3 to 4 without having to reformat and having to make backups of your current data.
    really is cominf soon? i didn't think in ext4 beacuse many places said that was in development for many years... meybe they were a bit out-of-date
    Edit: i search in the wiki and it says that since 11 october 2008, ext4 is "stable" and is been included since kernel 2.6.28 as stable realase, is to early to prove it? or it better to wait a while??
    thanks.
    and, does anyone try the JFS one?
    Last edited by Thalskarth (2008-12-03 00:14:56)

  • Help with TYPE and LIKE statements

    HI guys,
    I know this is really novice stuff, but I am a little confused.
    Can anyone please explain the exact difference between TYPE and like with the help of a program, to understand it.
    What situation would demand the use of each of the LIKE statement, since I can do all these things using the TYPE ?

    Hi Akhil,
    I summarized the info in SDN posts and SAP Help, to make it easier for you to understand. I also included some code snippets. Hope these prove to be helpful to you.
    The following is from SAP Help:
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    A known data type can be any of the following:
    ·        A predefined ABAP type to which you refer using the TYPE addition
    ·        An existing local data type in the program to which you refer using the TYPE addition
    ·        The data type of a local data object in the program to which you refer using the LIKE addition
    ·        A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.
    The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context.  The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.
    ·        In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.
    ·        You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:
    DATA dref TYPE REF TO cl_global.
    DATA:  f1 LIKE cl_global=>attr,
           f2 LIKE dref->attr.
    You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.
    Example
    TYPES: BEGIN OF struct,
             number_1 TYPE i,
             number_2 TYPE p DECIMALS 2,
           END OF struct.
    DATA:  wa_struct TYPE struct,
           number    LIKE wa_struct-number_2,
           date      LIKE sy-datum,
           time      TYPE t,
           text      TYPE string,
           company   TYPE s_carr_id.
    This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.
    The following info is from various posts:
    --> Type: It is used when userdefined object link with SAP system data type.
    Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.
    --> Like: It is when data object link with the other data object.
    --> TYPE, you assign datatype directly to the data object while declaring.
    --> LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.
    you can refer to all visible data objects at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in
    memory during the LIKE reference. Local data objects mask global data objects that have the same name.
    --> Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.
    Types: var1(20) type c.
    data: var2 type var1. ( type is used bcoz var1 is defined with TYPES and it
    does not occupy any memory spce.
    data: var3 like var2. ( like is used here bcoz var2 is defined with DATA
    so it does occupy space in memory ).
    data: material like mara-matnr. ( like is used here bcoz mara-matnr is stored in memory)
    --> Type refers the existing data type
    --> Like refers the existing data object
    Please Reward Points if any of the above points are helpful to you.
    Regards,
    Kalyan Chakravarthy

  • Help with Importing and Editing an Image

    Hello All,
    I am working on a project where I need to import an image into LabView and edit it. The gist of my program is that I want to create a VI that generates an interactive floorplan.
    I want to be able to import the bitmap or png into my file so I can edit the file by assigning flashing colors to each room, etc.
    I tried to import the .png by wiring "Read png" --> "Draw Flattened Pixmap" --> "new picture".
    When I run the program I get a "general I/O" error in the "Read PNG" block even though it lets me select which png I can import.
    Does LabVIEW 8.5 not allow for importing PNG files? Does anyone have any idea why I am getting this error?
    On another note, I was reading about some of the IMAQ VI's and they seem like they may work for importing an image and creating graphics, etc. Should I try to delve a little deeper into the IMAQ stuff?
    Thanks much for the help!

    Great call on checking whether it was just a bad file.
    I tried to convert it from a .bmp to a .png by simply renaming it which LabVIEW did not like...
    So I just opened it up and re-saved it with photo editing software and it worked!
    Now I just have to play around with my editing options to get the graphics I want. 
    I'll post some sample code just for suggestions that anyone may have. This is just my preliminary structure without most of my condition statements. All the code inside the case structures will be added when I figure all this stuff out.
    My goal is to have each strobe and interlock correspond to a different graphic on the floorplan. For example, when strobe 1 reads red, I want the corresponding room to flash red and vice versa with green and yellow. Also, when interlock 1 reads false, I want a flashing light to pop up next to the corresponding door.  
    Anyone have any ideas for how to make these kinds of graphics? I figured I may be able to use a color box for the solid colors and LEDs for the flashing lights but I would rather edit the pixels to make it look more professional.
    Thanks for all the help!
    Attachments:
    LabStatusProgram.vi ‏9 KB

  • Please Please help with JavaScript and Actions

    Hello!
    Is there a way to perform a saved Action from the Action Pallette using a JavaScript script? I know there is a way to do it with Visual Basic.
    Is there a way to run a Visual Basic script from a JavaScript script?(which could be a potential workaround if JavaScript CANNOT call on an Action)
    Is there a way to call on a JavaScript from an Action?
    Here's specific information on my problem:
    I am using Illustrator CS2 on a PC
    I have written all of the JavaScript scripts that I need to perform various layer selection procedures and they all work perfectly. I have placed them in the Presets > Scripts folder so that they appear in my file menu.
    I wrote a very long action that called on these scripts (using Insert Menu Item > then selecting the script by going File > Scripts) sequentially and did some selecting and copy-pasting and applying graphic styles in between scripts. The Action worked PERFECTLY and ran all the scripts I needed to an automated a process that usually takes me an hour in less than five minutes!
    I saved the actions and saved the file.
    After closing Illustrator all of the lines of the action that called on scripts disappeared! It seems this is a known bug...I currently know of no workaround.
    Can anyone help with any of the following things:
    1. Getting actions to SAVE the commands to run javascripts
    2. Writing a JavaScript that runs an Illustrator Action
    3. Writing a JavaScript that runs a Visual Basic script that runs an Illustrator Action.
    I spent three days learning the basics of JavaScript (mostly by trial and error) and successfully wrote all the scripts I needed...I was overjoyed! But now that I've closed illustrator my actions to run said scripts do not work. PLEASE ADVISE!!!
    Thanks in advance,
    Matthew

    try next
    1)if possible split JS-code into 2 parts (before/after action)
    2)make vbs script with contents
    Set appRef = CreateObject("Illustrator.Application.3")
    appRef.DoJavaScriptFile("C:\my1.js")
    appRef.DoScript(Action As String, From As String)
    'add wait while ActionIsRunning
    appRef.DoJavaScriptFile("C:\my2.js")
    3) run vbs (File > Scripts or double-click).

  • Help with treemap and other stuff

    hi guys..
    i m new to this forum..
    and this is my first post....so if i act a little naive .....please bare with me.
    and if this is not the correct place to post ..i m sorry for that.
    i have an assignment to submit....i m getting the whole picture ....but not sure how to go about implementing it.
    here it is...
    Write an Object Oriented solution to the problem in Java. The solution is to consist of:
    A TableIndex class
    A TableNavigator Interface
    A data row class ....class that i have to create.
    An application class to use and test your TableIndex class
    The following UML class diagrams show the public methods of the classes. Other methods may be specified. Specify data members, inner classes and interfaces as appropriate.
    TableIndex Class
    The TableIndex class is an index to a collection of objects. The class is to approximate an index to a data table in memory that consists of a number of rows. To control access to the index a current row is defined that specifies the row that can be accessed. To retrieve a row from the index it must be the current row. The get() method is the only method in TableIndex class that retrieves a row from the index. The current row can be changed explicitly using the methods: previous(), next(), first(), last(), gotoBookmark and find(K); and implicitly using insert(K, V), modify(K, V) and remove().
    The TableIndex class is to be implemented using the java API's TreeMap class and must use Generics. The data types K and V below are generic types for the Key and Value (row) respectively. An important aspect of the assignment is using the Java API documentation to understand the TreeMap class.
    guys ....can u plz help with the starting bit ..
    what should be the opening statement of the class...
    public class TableIndex<K , V> .....????
    and what should be the treemap declaration..??
    TreeMap<K , V> indexTable = new TreeMap<K , V>();...???
    i m confused....
    can u plz explain to me..

    hi mate.....didnt quite get you..
    can u plz be a bit more simple in explanation..!!!
    i will post the whole question ..so that anyone reading will understand better....
    Problem Description
    You are to develop an index class and associated classes.
    Requirements
    Write an Object Oriented solution to the problem in Java. The solution is to consist of:
    A TableIndex class
    A TableNavigator Interface
    A data row class
    An application class to use and test your TableIndex class
    The following UML class diagrams show the public methods of the classes. Other methods may be specified. Specify data members, inner classes and interfaces as appropriate.
    TableIndex Class
    The TableIndex class is an index to a collection of objects. The class is to approximate an index to a data table in memory that consists of a number of rows. To control access to the index a current row is defined that specifies the row that can be accessed. To retrieve a row from the index it must be the current row. The get() method is the only method in TableIndex class that retrieves a row from the index. The current row can be changed explicitly using the methods: previous(), next(), first(), last(), gotoBookmark and find(K); and implicitly using insert(K, V), modify(K, V) and remove().
    The TableIndex class is to be implemented using the java API's TreeMap class and must use Generics. The data types K and V below are generic types for the Key and Value (row) respectively. An important aspect of the assignment is using the Java API documentation to understand the TreeMap class.
    TableIndex
    +TableIndex()
    +TableIndex(name: String, comp: Comparator)
    +getName(): String
    +isEmpty(): Boolean
    +size(): Integer
    +hasPrevious(): Boolean
    +hasNext(): Boolean
    +previous()
    +next()
    +first()
    +last()
    +setBookmark(): Boolean
    +clearBookmark()
    +gotoBookmark(): Boolean
    +contains(key: K): Boolean
    +find(key: K): Boolean
    +get(): V
    +insert(key:K, value: V): Boolean
    +modify(value: V): Boolean
    +modify(key: K, value: V): Boolean
    +remove(): V
    +iterator(): Iterator
    +equals(obj2: Object): Boolean
    +toString(): String
    Additional Notes:
    The table index has an order defined by the compareTo method of the key's class or by the compare method specified in the class that implements the Comparator interface.
    getName(): the name of the index, blank by default.
    isEmpty(): returns true if there aren't any rows in the table index
    size(): returns the number of rows in the table index
    hasPrevious(): returns true if there is a row before the current row.
    hasNext(): returns true if there is a row after the current row in sequence.
    previous(): if there is a row before the current row, move to the row and make it the new current row.
    next() if there is a row after the current row, move to the row and make it the new current row.
    first(): if the table isn't empty, move to the first row and make it the new current row.
    last(): if the table isn't empty, move to the last row and make it the new current row.
    setBookmark(): sets a bookmark at the current row. If the bookmark is successfully set the method returns true. The bookmark is cleared if the TableIndex is empty or the row the bookmark was set on is deleted..
    clearBookmark(): sets the bookmark to null, indicating there isn't a bookmark.
    gotoBookmark(): if a bookmark has been set, go to the bookmarked row. If successful the book marked row becomes the current row and the method returns true.
    contains(K): return true if a row with the key specified exists.
    find(K): if a row is found with the specified key, the current row is set to the row found.
    get(): returns the current row. Null is returned if there isn't a current row.
    insert(K, V): inserts a row (value) with the key specified. The key must not be null and must be unique (not already in the TableIndex). The row (value) must not be null. If the row is successfully inserted true is returned, and the row becomes the current row..
    modify(V): change the current row's data to the row (value) specified. The key and the current row key are to remain the same. If successful true is returned.
    modify(K, V): change the current row's key and data to the key and row (value) specified. If successful the changed row becomes the new current row. If successful true is returned. Note: this is more difficult than modify(V).
    remove(): remove the current row. When a row is deleted the next row (if available) becomes the current row, otherwise if there isn't a next row the previous row becomes the current row, otherwise the table is empty therefore the current row is null.
    iterator(): returns an iterator to the rows (values) in the index. The rows are to be retrieved in order. The remove method does not need to be implemented (its method body can be empty)..
    the equals method uses the name, and the rows (values) in order when testing for equality.
    the toString method should return appropriately formatted data members and the rows (values/data) in the index.
    TableNavigator Interface
    «interface»
    TableNavigator
    +isEmpty(): Boolean
    +hasPrevious(): Boolean
    +hasNext(): Boolean
    +previous()
    +next()
    +first()
    +last()
    +contains(key: K): Boolean
    +find(key: K): Boolean
    Additional Notes:
    The TableIndex class implements the TableNavigator Interface.
    The purpose of the above methods is outlined in the TableIndex class.
    Your Data Row Class
    You are to include a class of your own to represent a row of data in the TableIndex. This is not to be a class that was covered in other programming subjects. It does not need to be complex but must include a range of data types. This class will be used to test your TableIndex class. The class should have an appropriate name and deal with something of interest to you.
    Your Application Class
    The application class is to make use of the TableIndex class and your data row class. It is to clearly show how the TableIndex class is used, and in doing so, test it. The class should have an appropriate name. The application class should create two indexes of different key data types. One of the indexes must make use of the Comparator interface to have a key that is in descending order.
    Output
    Output in the test classes/programs is to go to standard out or a text file. There should be no output from the TableIndex class or your data row class. A GUI interface is NOT required. There is no need to input data from the keyboard or file. Use the Unix script command or write output to a text file (etc) to provide example runs of your test programs.

  • Need some help with WRT54G2 and Home Network

    Ok, I've had the WRT54G for a long time and recently updated to the WRT54G2 but now can't access file and print sharing that's running Windows Vista from Windows XP using wireless.
    Here's my set up,
    Desktop running Windows Vista connected to router (This is the computer with Folders and Printers)
    2-Windows XP Laptops connected wirelessly 
    All 3 are set on same workgroup can be seen on Windows XP machine when going to, My Network Places, also all can get on the internet.
    Any ideas what the problem could be? I'm guessing a setting somewhere but I haven't been able to find it.
    Solved!
    Go to Solution.

    Hey Gary...
    I just upgraded my set up to a WRT54GS from an older linksys router that only had A/B. I have two wired desktops and a wireless desktop in my network..all running xp and all sharing files. I had no issues with the file sharing prior to the upgrade but once I changed over the computers could see eachother, access the net but not share files...Chances are it is likely a firewall issues...
    Try turning off windows firewall...that might help..
    Also depending upon your antivirus there might be settings in there that you would have to change to allow for file sharing.
    In my case I did some research and read that if you are running Norton 2009 on the computer that you want to share files from to try uninstalling and reinstalling the program..Had something to do with firewall settings in the program.....I did that and ouila...now all my computers are sharing again...
    Message Edited by redlands on 06-07-2009 06:41 AM

  • Desperately seeking help with recording and playback error messages...

    When I attempt to record a single track of audio (either with my internal mic or my Samson USB mic), I get the following message 15 to 30 sec into it:
    CoreAudio:
    Disk is too slow. (Record)
    (-10004)
    And when I attempt to playback that single track of a little bit of audio I recorded, I get the following message:
    This song has too many instrument tracks to be played in real-time.
    I have tried all the steps to solve the problem under "Optimizing Garageband" in the Help menu and nothing has worked.
    I would greatly appreciate any suggestions that anyone has as to how I could get rid of these messages and actually enable myself to record a full song at some point in the conceivable future...

    I'm guessing that your computer is too slow to record
    real-time audio.
    Of itself it should be fine - I still use a G3 desktop to record stereo with no problems at all - though GB may add an overhead. Still, this shouldn't be happening.
    If you have other tracks playing
    while you are recording this could be an issue,
    especially if there are a lot playing.
    Yes...
    If this is the
    case then you can lock the tracks playing by pressing
    the lock icon.
    This won't make any difference to audio tracks, only to MIDI tracks, and in that case it reduces demands on the processor but increases demands on the disk - which appears to be the trouble in the first place.
    I agree that you should consider
    getting an external hard drive. You can set the
    record path to the external hard drive
    Since laptop disks are usually slower than external ones this might help - particularly if your internal drive is very full.
    which will
    free up working memory to your computer.
    No it won't, but it will take the strain off the internal disk, if that's what you mean. The memory might be an issue, which would be resolved by installing more RAM if possible.

  • Help with Coding and Warning/Error Messages

    Can someone help me with Java Language to get SAP to enter through soft warnings and errors?
    I am working to record/write a script to change orders but am hitting a road block when error messages pop up. I need to get it to enter through if the message pops up or move to the next step if not... there can be 1 error or multiples depending on the number line items.
    THANKS!

    I'm guessing that your computer is too slow to record
    real-time audio.
    Of itself it should be fine - I still use a G3 desktop to record stereo with no problems at all - though GB may add an overhead. Still, this shouldn't be happening.
    If you have other tracks playing
    while you are recording this could be an issue,
    especially if there are a lot playing.
    Yes...
    If this is the
    case then you can lock the tracks playing by pressing
    the lock icon.
    This won't make any difference to audio tracks, only to MIDI tracks, and in that case it reduces demands on the processor but increases demands on the disk - which appears to be the trouble in the first place.
    I agree that you should consider
    getting an external hard drive. You can set the
    record path to the external hard drive
    Since laptop disks are usually slower than external ones this might help - particularly if your internal drive is very full.
    which will
    free up working memory to your computer.
    No it won't, but it will take the strain off the internal disk, if that's what you mean. The memory might be an issue, which would be resolved by installing more RAM if possible.

  • (newbie and technophobe here) Help with speakers and web camera ...

    Hello, everyone!
    I've had my G-5 since I ordered new in November of 2005, and only now am I geting around to purchasing speakers and musing about a web camera.
    On speakers, the kid at Best Buy yesterday told me that speakers aren't really operating system specific. That is, that they plug and play into any computer and don't require any software; like speakers do to a stereo. However, I just noticed the speakers I bought (Logitech Z-10) for $120.00 do not have "Macintosh" listed on the box as it does for a PC on the Requirements listing. Before I open this box and find out they don't work properly, do I really need Mac specific speakers?
    I also went to the Mac store here in Fashion Valley and they no longer carried any web cameras. After visiting three other computer retailers such as Best Buy, and Frys, I came up dry on cameras for a Mac. I do however have an Ebay merchant selling a MacAlly iceCam Web Camera Mac right here in town who I can drive over and purchase one if I want to. However, after going on Ebay, I noticed that the $300.00 Mac iSight camera is there for sale, so I was wondering what the difference was. The MacAlly one is around $27.00, whereas the iSight is close to $300.00. Is the iSight worth the price in other words? What can it do that the MacAlly can't? Would the MacAlly suffice just to talk to another across the country?
    Thank you.
    G-5 Imac Mac OS X (10.3.9)

    Martin, Rod:
    Thank you for your responses. I think I have Panther(10.3.9), so will iChatAV be in that system, or will I have to upgrade to Tiger in order to make full use of an iSight camera ? Can I web camera with AOL subscribers, or am I pretty much limited as to who I can conference with?
    Thank you for clearing up the speaker thing. It looks like I'll be returning them to Best Buy tomorrow, and then start a search for Apple specific speakers. Thanks again.
    iSight question: It looks like I'm going to have to purchase an iSight web camera at an overinflated price at a site such as Ebay since Apple no longer produces them, so my question is, Does anyone know whether the camera came with software or manuals (In case the seller doesn't have any) ... or does one actually need any?
    Keychain Question: What's this annoying keychain box that pops up everytime I use Safari? How do I get rid of it? What's it for? What am I supposedly unlocking? I don't think I have a keychain password.
    Thank you all for your assistance,
    Frank
    G-5 Imac   Mac OS X (10.3.9)  
    G-5 Imac   Mac OS X (10.3.9)  
    G-5 Imac   Mac OS X (10.3.9)  

  • Help with Mathscipt and for loop

    I have a code in Mathscript/matlab and I need to output the array out. One option is my first code,the other option is using a for loop, but I am only getting the last ouput out. I need to get the whole output out.
    Any help.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Help with Mathscript_for loop.vi ‏115 KB
    Help with Mathscript_for loop2.vi ‏84 KB

    Here's how it should look like.
    Message Edited by altenbach on 10-30-2008 05:12 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    MathscriptInFOR.png ‏15 KB

  • Need help with JTextArea and Scrolling

    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import javax.swing.*;
    public class MORT_RETRY extends JFrame implements ActionListener
    private JPanel keypad;
    private JPanel buttons;
    private JTextField lcdLoanAmt;
    private JTextField lcdInterestRate;
    private JTextField lcdTerm;
    private JTextField lcdMonthlyPmt;
    private JTextArea displayArea;
    private JButton CalculateBtn;
    private JButton ClrBtn;
    private JButton CloseBtn;
    private JButton Amortize;
    private JScrollPane scroll;
    private DecimalFormat calcPattern = new DecimalFormat("$###,###.00");
    private String[] rateTerm = {"", "7years @ 5.35%", "15years @ 5.5%", "30years @ 5.75%"};
    private JComboBox rateTermList;
    double interest[] = {5.35, 5.5, 5.75};
    int term[] = {7, 15, 30};
    double balance, interestAmt, monthlyInterest, monthlyPayment, monPmtInt, monPmtPrin;
    int termInMonths, month, termLoop, monthLoop;
    public MORT_RETRY()
    Container pane = getContentPane();
    lcdLoanAmt = new JTextField();
    lcdMonthlyPmt = new JTextField();
    displayArea = new JTextArea();//DEFINE COMBOBOX AND SCROLL
    rateTermList = new JComboBox(rateTerm);
    scroll = new JScrollPane(displayArea);
    scroll.setSize(600,170);
    scroll.setLocation(150,270);//DEFINE BUTTONS
    CalculateBtn = new JButton("Calculate");
    ClrBtn = new JButton("Clear Fields");
    CloseBtn = new JButton("Close");
    Amortize = new JButton("Amortize");//DEFINE PANEL(S)
    keypad = new JPanel();
    buttons = new JPanel();//DEFINE KEYPAD PANEL LAYOUT
    keypad.setLayout(new GridLayout( 4, 2, 5, 5));//SET CONTROLS ON KEYPAD PANEL
    keypad.add(new JLabel("Loan Amount$ : "));
    keypad.add(lcdLoanAmt);
    keypad.add(new JLabel("Term of loan and Interest Rate: "));
    keypad.add(rateTermList);
    keypad.add(new JLabel("Monthly Payment : "));
    keypad.add(lcdMonthlyPmt);
    lcdMonthlyPmt.setEditable(false);
    keypad.add(new JLabel("Amortize Table:"));
    keypad.add(displayArea);
    displayArea.setEditable(false);//DEFINE BUTTONS PANEL LAYOUT
    buttons.setLayout(new GridLayout( 1, 3, 5, 5));//SET CONTROLS ON BUTTONS PANEL
    buttons.add(CalculateBtn);
    buttons.add(Amortize);
    buttons.add(ClrBtn);
    buttons.add(CloseBtn);//ADD ACTION LISTENER
    CalculateBtn.addActionListener(this);
    ClrBtn.addActionListener(this);
    CloseBtn.addActionListener(this);
    Amortize.addActionListener(this);
    rateTermList.addActionListener(this);//ADD PANELS
    pane.add(keypad, BorderLayout.NORTH);
    pane.add(buttons, BorderLayout.SOUTH);
    pane.add(scroll, BorderLayout.CENTER);
    addWindowListener( new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    public void actionPerformed(ActionEvent e)
    String arg = lcdLoanAmt.getText();
    int combined = Integer.parseInt(arg);
    if (e.getSource() == CalculateBtn)
    try
    JOptionPane.showMessageDialog(null, "Got try here", "Error", JOptionPane.ERROR_MESSAGE);
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Got here", "Error", JOptionPane.ERROR_MESSAGE);
    if ((e.getSource() == CalculateBtn) && (arg != null))
    try{
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 1))
    monthlyInterest = interest[0] / (12 * 100);
    termInMonths = term[0] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 2))
    monthlyInterest = interest[1] / (12 * 100);
    termInMonths = term[1] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 3))
    monthlyInterest = interest[2] / (12 * 100);
    termInMonths = term[2] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease Try Again", "Error", JOptionPane.ERROR_MESSAGE);
    }                    //IF STATEMENTS FOR AMORTIZATION
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 1))
    loopy(7, 5.35);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 2))
    loopy(15, 5.5);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 3))
    loopy(30, 5.75);
    if (e.getSource() == ClrBtn)
    rateTermList.setSelectedIndex(0);
    lcdLoanAmt.setText(null);
    lcdMonthlyPmt.setText(null);
    displayArea.setText(null);
    if (e.getSource() == CloseBtn)
    System.exit(0);
    private void loopy(int lTerm,double lInterest)
    double total, monthly, monthlyrate, monthint, monthprin, balance, lastint, paid;
    int amount, months, termloop, monthloop;
    String lcd2 = lcdLoanAmt.getText();
    amount = Integer.parseInt(lcd2);
    termloop = 1;
    paid = 0.00;
    monthlyrate = lInterest / (12 * 100);
    months = lTerm * 12;
    monthly = amount *(monthlyrate/(1-Math.pow(1+monthlyrate,-months)));
    total = months * monthly;
    balance = amount;
    while (termloop <= lTerm)
    displayArea.setCaretPosition(0);
    displayArea.append("\n");
    displayArea.append("Year " + termloop + " of " + lTerm + ": payments\n");
    displayArea.append("\n");
    displayArea.append("Month\tMonthly\tPrinciple\tInterest\tBalance\n");
    monthloop = 1;
    while (monthloop <= 12)
    monthint = balance * monthlyrate;
    monthprin = monthly - monthint;
    balance -= monthprin;
    paid += monthly;
    displayArea.setCaretPosition(0);
    displayArea.append(monthloop + "\t" + calcPattern.format(monthly) + "\t" + calcPattern.format(monthprin) + "\t");
    displayArea.append(calcPattern.format(monthint) + "\t" + calcPattern.format(balance) + "\n");
    monthloop ++;
    termloop ++;
    public static void main(String args[])
    MORT_RETRY f = new MORT_RETRY();
    f.setTitle("MORTGAGE PAYMENT CALCULATOR");
    f.setBounds(600, 600, 500, 500);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }need help with displaying the textarea correctly and the scroll bar please.
    Message was edited by:
    new2this2020

    What's the problem you're having ???
    PS.

Maybe you are looking for