aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Please Comment on Data Section Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Please Comment on Data Section" Watch "Please Comment on Data Section" New topic
Author

Please Comment on Data Section

Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all
I am shy of posting,some points in assignment puzzle me.
My data section describes like this,

Database schema
The database that URLyBird uses contains the following fields: Field descriptive name Database field name Field length Detailed description
Hotel Name name 64 The name of the hotel this vacancy record relates to
City location 64 The location of this hotel
Maximum occupancy of this room size 4 The maximum number of people permitted in this room, not including infants
Is the room smoking or non-smoking smoking 1 Flag indicating if smoking is permitted. Valid values are "Y" indicating a smoking room, and "N" indicating a non-smoking room
Price per night rate 8 Charge per night for the room. This field includes the currency symbol
Date available date 10 The single night to which this record relates, format is yyyy/mm/dd.
Customer holding this record owner 8 The id value (an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customers and CSRs know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them. If this field is all blanks, the record is available for sale.

I have two problems.
1)These length of fields are 'byte' type,they have to be convert other types(likes 'double rate' or'boolean smoking')?
If not,what should I do convert the all strings to relational types?
2)Many of friends think that the record length is fixed(simply represent as "byte recordSize=64+64+4+1+8+10+8;",correct?),whether it implys that following or not?
A.I can declare it as a CONSTANT.
B.I don't have to modify the field count and length but invoking them.
Regards,
Richard


Regards, Richard
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234

)These length of fields are 'byte' type,they have to be convert other types(likes 'double rate' or'boolean smoking')?
If not,what should I do convert the all strings to relational types?

I am not sure what you mean. Give me an example

2)Many of friends think that the record length is fixed(simply represent as "byte recordSize=64+64+4+1+8+10+8;",correct?),whether it implys that following or not?
A.I can declare it as a CONSTANT.
B.I don't have to modify the field count and length but invoking them.

Yes, you could hard code them. But your file header probably indicates the
length of each field. If so, read the lengths from you header and store
them in a field and allow other classes to retrieve them you "getters"
(i.e. getNameLength()). This is much more robust and flexible than using
constants. And most importantly easier to argue your case to Sun.
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Richard,

1)These length of fields are 'byte' type,they have to be convert other types(likes 'double rate' or'boolean smoking')?
If not,what should I do convert the all strings to relational types?

My assignment, in the "Data file Format" section, said "All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes." It's very easy, just check the Javadoc for these classes and the DataInput and DataOuput interfaces that they implement.
You will also want to look at any statement in the specification regarding character encoding. This topic has been well covered, simply search this forum on "character encoding".

2)Many of friends think that the record length is fixed(simply represent as "byte recordSize=64+64+4+1+8+10+8;",correct?),whether it implys that following or not?
A.I can declare it as a CONSTANT.
B.I don't have to modify the field count and length but invoking them.

You can do this and this is in fact what I did (use constants). I also verified that the info in the specification was correct by examining what was actually in the supplied data file. I then used this information to check against what was encoded in the header to make sure the file selected by the user was indeed a compatible data file and as part of a general file corruption check. In the real world, if you wanted to be a bit more flexible on the file format, you could supply the constants from a properties, xml, csv, or some other type of configuration file. For the purpose of this assignment though, it is overkill.
kktec
SCJP, SCWCD, SCJD


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Bill and Ken,thank you.
Bill,
But your file header probably indicates the
length of each field.

In my URLyBird assignment, there are states,
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block
Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
End of file

So, the "header" of file doesn't contain field length but "Schema section".
I've written relational code,

Here,
> raf-------> new RandomAccessFile(dbName,"rw");
> numFields-> short numFields; //Number of fields
> 4---------> length of bytes of magic cookie

Ken
Your advice is also worthy of doing that.
As you said,I can declare the record size with FIXED LENGTH as below,

a)"public " -I probably invoke the constant in other methods.
b)"final"----because "record length" is fixed and never be modified.
c)"64+64+4+1+8+10+8"--describing in my "database schema section" specification.
Is it right?
What else things to do about data section?
Regards,
Richard
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all
I have other two problems about data section.

1)The 'rate' field need formatting as "$ XXX" style with NumberFormat class?

2)The 'data' field need formatting as "yyyy/mm/dd" with GregorianCalendar class?
Compare to all fields in the data section,they are suitable used to present to String type or their own relative type?
Regards,
Richard
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
I simply used a String
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

Hi Richard,
As Mark suggested earlier this week - keep your assignment as simple as possible. Don't go adding to your work load.
With the price field - do you have to do any work at all with it? Is there any verification to be done on that field / any calculations? If not, then why not just leave it as a String?
With the date field - do you have to do any calculations on it? If you have to only allow bookings within a certain timeframe, then you might have to convert this to one of the date classes so you can do comparisons.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,Bill and Andrew
Thank you very much!
So simple problem puzzled me for a long time.
With the price field - do you have to do any work at all with it? Is there any verification to be done on that field / any calculations? If not, then why not just leave it as a String?
With the date field - do you have to do any calculations on it? If you have to only allow bookings within a certain timeframe, then you might have to convert this to one of the date classes so you can do comparisons.

Yes,I decide to leave their original string into data access.
You make me clean up my brain.
Thanks again.
Regards,
Richard
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
Its the simple things that always get us.
Seid Myadiyev
Ranch Hand

Joined: Jul 02, 2002
Posts: 196
Dear developers,
I would like to share my point of view about why I chose appropriate data types for my instance fields,
for example:
// class code...
private String location;
private Integer size;
// more class code...
The instructions document says:
"Your user interface should be designed with the expectation of future functionality enhancements..."
Being able render cells (check box for smoking /non-smoking) and to sort table columns by price and date available is a "future functionality enhancement" and will require the appropriate data types returned from the Record class and thus will require code modification in this class if all its instance variable have been implemented as String.
IMHO the "expectation " has not been met in this situation.
Please share your ideas on this!
Thank you!
+Seid
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

Hi Seid,
Your position is defendable, but so is the opposite position.
Another future enhancement might be that we need to manage more tables simultaneously. If we are reading the schema from the physical file, and treating each record as a String, then the same Data class code can be used unchanged for additional tables.
Converting the Strings to the object that represents the data contained means that your Data class becomes specific to the table currently being used. To add a new table, you would have to create a new class to handle it.
The point to all this is that we don't know what the future enhancement might be. Any enhancement we try to cater for now
  • may not ever get used,
  • or it may be used in a slightly different way than we envisaged (requiring a rewrite of your code which was only written for this enhancement)
  • and it might make it difficult for us to implement a different enhancement

  • You might be interested to read You Arent Gonna Need It (YAGNI)
    The advantage of applying YAGNI is that it gives you less work to do today
    So what it all boils down to is that this is another design decision which you need to make and then document.
    Regards, Andrew
    Richard Jackson
    Ranch Hand

    Joined: Jun 25, 2003
    Posts: 128
    Hi,Andrew
    After being busy for a week,I consider those past posts about this topic.
    Another future enhancement might be that we need to manage more tables simultaneously.

    The "more tables" means what?
    If we are reading the schema from the physical file, and treating each record as a String, then the same Data class code can be used unchanged for additional tables.

    Yes,I am able to treat them as a String,like this:

    But when I add some getXX or setXX methods to the field class,I dont know if the above fields (or several fields,like date/smoking/rate) should be converted to suitable format .
    For instance,I write sample code

    To smoking field:

    Is it essential or not?Correct?
    Please criticise and point me to correct direction.
    Regards,
    Richard
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11503
        
      95

    Hi Richard,

    Originally posted by Andrew Monkhouse:
    Another future enhancement might be that we need to manage more tables simultaneously.
    Originally posted by Richard Jackson:
    The "more tables" means what?

    A "table" is commonly used to describe the storage area for a common set of records. Another term is "entity". In this case, the only table is the file which holds the hotel rooms information.
    What I was talking about was the potential for another table or entity to be added to the system at a later date. Currently all you store is an 8 digit Customer ID value in the hotel table. But that number tells us nothing on it's own. So you might want to have an additional table which stores customer records, with the unique index being the 8 digit customer ID.
    Note that this is all just a theoretical enhancement. It is not anything you need to worry about for the current assignment.

    Originally posted by Richard Jackson:
    when I add some getXX or setXX methods to the field class,I dont know if the above fields (or several fields,like date/smoking/rate) should be converted to suitable format

    Consider whether you need the fields in a format other than a String in order to complete the assignment.
    You may choose to convert the smoking field into a boolean, either so you can display it in a format that you consider more natural, or because (like Seid) you feel that it is valuable for future enhancements. Both reasons are valid.
    Alternatively you might decide that the current format is understandable by the user of the system, and you do not want to spend time writing code for an enhancment that may never be desired or implemented. In which case you can save yourself the effort of writing methods to convert between the String format and the Boolean format. This is also a valid choice to take.
    You can pass no matter whether you convert the data formats or whether you leave them in String formats. Either option is acceptable. What you must do though, is write down your design decision in your choices.txt file - let the examiner know that you have considered this issue, and what your decision was.
    As for the date field - you may want to see if there are any instructions about whether you are allowed to accept bookings within a certain period of the start of room occupancy. If so, then you may have to convert the String representation of the date into a real date format so that you can do date comparisons.
    Regards, Andrew
    [ November 22, 2003: Message edited by: Andrew Monkhouse ]
    Richard Jackson
    Ranch Hand

    Joined: Jun 25, 2003
    Posts: 128
    Hi,Andrew
    Thanks for your explanation.
    As for the date field - you may want to see if there are any instructions about whether you are allowed to accept bookings within a certain period of the start of room occupancy. If so, then you may have to convert the String representation of the date into a real date format so that you can do date comparisons.

    In fact,I would like to design my assignment as simply as possible.
    At the same time,I like to do anything as long as clear and resonable.(IMO)

    Consider whether you need the fields in a format other than a String in order to complete the assignment.

    I would like to do that like you said.
    But what can I do present their special format in the fields?
    For instance,
    1. date -> yyyy/mm/dd What else can do it other than "yyyy" string plus "/" plus "mm"...?
    2. rate -> $200 Decribe the US dollar symbol
    3. smoking -> Y or N char or String about smoking is permitted or not
    Please comment on this.
    Regards, Richard
     
    jQuery in Action, 2nd edition
     
    subject: Please Comment on Data Section