• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FBNS: Have I completed enough to pass?

 
Gary Richards
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've only just got around to working on my Fly By Night SJCD assignment... I'm fairly sure it all works now, but it's a little rough around the edges, so I have some questions to anyone that can help:
1) Ok, the class i'm using for local database file access has no record locking. Is this ok? The record locking I have for RMI access has record locking which works, but I didn't see any sense in implementing it for direct access to the file.
2) My server doesn't have a clean way to shutdown, you have to hit ctrl-c, is this ok? Or should I try and implement a proper way to shut it down. If so, any ideas?
3) My GUI, although it works, is a little horrible looking. All columns in my JTable are the same width and all data etc. is aligned left in all the columns. I had the idea of trying to resize my column widths based on the widest element in each column, but this has so far proved fairly difficult to do in a nice way. So should I spend time on this, or would I still be likely to pass as it does allow you to see all data, select a flight, and books a flight. Any ideas on this whole area is greatly appreciated.
4) Exception handling for most of my client pops up some form of JOptionPane, displaying the name of the exception and the message from the exception. With a couple of buttons to continue or to exit. Is this the correct way to do things, or should I attempt to give slightly more useful messages to the user instead of the message from the exception thrown?
5) The criteriaFind method, although it works, IMHO it is a bit of a mess (I have quite alot of mess don't I ). At the moment it involves a number of StringTokenizer's, about three String arrays, an int array and an ArrayList. So, does anyone have any tips on how I might go about tidying this up, making the code better etc.?
I hope some people can help with this as i'm really not sure whether i've currently put enough work into this project to actually pass it. From what I can tell, i've implemented everything in the requirements, in some shape or form, and it all works...
Thanks in advance to anyone that replies
Gary
 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my take:
1) Ok, the class i'm using for local database file access has no record locking. Is this ok? The record locking I have for RMI access has record locking which works, but I didn't see any sense in implementing it for direct access to the file.

I don't know about that. My assignment (URLyBird), says that network/non networked modes should do the same thing, the only difference being that the network layer is bypassed. So.. I left the locking intact.
2) My server doesn't have a clean way to shutdown, you have to hit ctrl-c, is this ok? Or should I try and implement a proper way to shut it down. If so, any ideas?

Currently, my server has a UI that lets the admin start/stop the server. If he presses the stop server button, then the server stops accepting connections, waits around a little for any create/update/delete calls to finish, and then shuts down.
Probably best is to keep track of all create/update/delete calls with some sort of counter and then only exit when the counters reach zero? But.. I was afraid that might be overkill so I didn't do it.
3) My GUI, although it works, is a little horrible looking. All columns in my JTable are the same width and all data etc. is aligned left in all the columns. I had the idea of trying to resize my column widths based on the widest element in each column, but this has so far proved fairly difficult to do in a nice way. So should I spend time on this, or would I still be likely to pass as it does allow you to see all data, select a flight, and books a flight. Any ideas on this whole area is greatly appreciated.

You might lose points on GUI there. I made a compromise by just hardcoding the sizes
4) Exception handling for most of my client pops up some form of JOptionPane, displaying the name of the exception and the message from the exception. With a couple of buttons to continue or to exit. Is this the correct way to do things, or should I attempt to give slightly more useful messages to the user instead of the message from the exception thrown?

I think that'll definitely cost you some points there. The CSR has no business actually knowing the exception name or the specifics of the exception. He wouldn't know what to do with it and he'd be confused.
Instead of displaying "RecordNotFoundException: Record 14 is deleted." or somesuch, you might want to display "The record you tried to update has been deleted". The latter is a much more user friendly message. If you want the advanced users to know more about what happened, refer them to the log file (if you generated one).
Oh, and another thing. Having buttons for your alerts that ask the user to continue or quit doesn't sound like a good idea to me. The CSR is probably going to have a lot of these alerts come up (he entered invalid data in the owner field, he couldn't book a record, etc), and he most likely doesn't want to quit at that point, rather just fix his error and continue. By placing a quit button in such an easy to access location, the CSR may accidentally press quit when he didn't mean to.
5) The criteriaFind method, although it works, IMHO it is a bit of a mess (I have quite alot of mess don't I ). At the moment it involves a number of StringTokenizer's, about three String arrays, an int array and an ArrayList. So, does anyone have any tips on how I might go about tidying this up, making the code better etc.?

Hm.. Mine uses a HashMap (recNo => data), String.trim(), and String.startsWith(String), but I'm not sure what the requirements for your find method are, so I'll keep my mouth shut.
Cheers and beers.
[ April 12, 2004: Message edited by: Min Huang ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gary,

1) Ok, the class i'm using for local database file access has no record locking. Is this ok? The record locking I have for RMI access has record locking which works, but I didn't see any sense in implementing it for direct access to the file.

Plenty of people have passed the FBNS assignment without using locking in the local connection.
I did have locking in my local connection simply because it ensured that the same code was used in both local and networked modes. In both cases, my client's book method was identical - it called the relevant methods on an interface which may have been implemented by either a local or a remote connection. But the important thing was that the client code was unaware of whether it was local or remote.

2) My server doesn't have a clean way to shutdown, you have to hit ctrl-c, is this ok? Or should I try and implement a proper way to shut it down. If so, any ideas?

Have you considered why you have the ability to lock the entire database? It is not needed for deleting a record, and may not be needed for creating a record. But where it is really useful is when you want to shut down the database - if you get the lock on the entire database you know that no clients are in the middle of writing an update.
Perhaps you could look at Runtime.addShutdownHook() - that will give you a way of handling the Ctrl-C event, and shutting down cleanly (rather than potentially exiting in the middle of a write to the datafile).

3) My GUI, although it works, is a little horrible looking. All columns in my JTable are the same width and all data etc. is aligned left in all the columns. I had the idea of trying to resize my column widths based on the widest element in each column, but this has so far proved fairly difficult to do in a nice way. So should I spend time on this, or would I still be likely to pass as it does allow you to see all data, select a flight, and books a flight. Any ideas on this whole area is greatly appreciated.

You have 24 points available for "layout uses good/accepted Human/Computer Interaction (HCI) principles", so you may want to consider what you can do to make this a little nicer.

4) Exception handling for most of my client pops up some form of JOptionPane, displaying the name of the exception and the message from the exception. With a couple of buttons to continue or to exit. Is this the correct way to do things, or should I attempt to give slightly more useful messages to the user instead of the message from the exception thrown?

You will have to consider whether displaying the name and description of the exception will provide the user with something they can understand and report back to the IT staff. I think it is almost always better to display a more human friendly message.

5) The criteriaFind method, although it works, IMHO it is a bit of a mess (I have quite alot of mess don't I ). At the moment it involves a number of StringTokenizer's, about three String arrays, an int array and an ArrayList. So, does anyone have any tips on how I might go about tidying this up, making the code better etc.?

Very hard to tell what, if anything, needs to be cleaned up here. Perhaps you might like to open a separate thread and discuss your code (in psuedocode please).
Regards, Andrew
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. No local mode does not need to have any locking code. As being stand-alone there is no reason to lock a record. I did not lock in local mode.
2. Ctrl-C is OK for closing the server. Some of us created Server GUIs, but that is not a requirement for closing the server. However, you still need to have code to lock all the records if "-1" is passed to the lock method.
3. I am hoping that you have a way for the user to search for flights, and when they complete the search the JTable only shows the records that match that search. This is a requirement, and you will fail if no searching capabilities are in your submission. I don't see any code in my submission that resized the columns, so that should be fine. I got 24/24 in GUI section.
4. I think for the sake of learning, wrapping all your exceptions thrown into a self-made "Application" exception, and showing a more descriptive and readable error to the user is important. Not sure how the grading will be affected by keeping it your current way.
5. You will have a couple of StringTokenizers, and a couple of Arrays. The code for criteriaFind is usually done the brute-force way, and that is fine. If your method is more than 15 lines of code, I am sure you can break it apart into more manageable methods that call each other.
Good Luck
Mark
 
Gary Richards
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, thanks for your answers, they've helped alot.
I think i'll leave my record locking out of the local code. I can also presumably leave out locking the whole database in local mode?
I hadn't realised you could Runtime.addShutdownHook(), presumably to do this I implement the shutdown code in the constructor of the thread that I pass to this method?
I do have a way to search for flights. My gui is still fairly simple, a couple of JCombobox's, a JTable (in a scroll pane), a few buttons, for search and order and a JSpinEdit (or whatever it's called). But as I said, the column widths are all the same and it just doesn't quite look as good as I think it could. I found out that with FontMetrics, you can essentially get the width that would be needed to display a String, therefore, my idea is to try and resize my columns to at least display all the column headings correctly. I've also been playing with setting things aligned centrally and aligned right, which has tidied the look of the table up a little too. Any other suggestions in this whole area are still greatly appreciated.
My main problem with Exceptions is that they could mean any number of different things. For instance a RemoteException, from what I imagine, most of the time that this is thrown means that I cannot continue, at least not without getting an instance of my remote objects, but trying to tell this to the user in a nice way without making my dialogs too generic seems quite difficult.
My criteriaFind method is quite long and uses sections of code that would mainly be useless in other methods as they'd never be reused by anything else in this class so it would seem pretty pointless to move sections of code out into other methods. I might do as Andrew suggested and start another post relating to this if i'm finding it quite hard to rewrte myself and make it sensible
Again thanks for all replies, they've been most helpful so far.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My criteriaFind method is quite long and uses sections of code that would mainly be useless in other methods as they'd never be reused by anything else in this class so it would seem pretty pointless to move sections of code out into other methods. I might do as Andrew suggested and start another post relating to this if i'm finding it quite hard to rewrte myself and make it sensible

pointless? What the.
OK here comes the Rant.
Readability is not pointless at all. Actually it is so pointful that it can costs companies billions of dollars in maintenance and enhancement costs. Never assume that because a piece of code won't be reused, that refactoring it would be pointless. That is so far from the truth, that I want to stop you from thinking like that right now, and forever in your future you will never this making code readable and easy to be maintained as a pointless gesture.
It is the same thing with following coding and naming standards. Not because they want to slow you down and bog you down up front, they do it so that everyone speaks the same language, that code is readable, which really reduces costs on the back end.
This point is probably the my biggest montra for programming. It took me over 26 years to realize that this is so so important to do, and to look at it as being the best programmer anyone can be, realizing the importance of this stuff.
OK rant over
Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was ranting so much, that a couple of the sentences wasn't quite correct english. But I think you get the points.
Mark
 
Gary Richards
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Not having the programming experience is mainly why it's useful to know this kind of thing. When I originally started writing java code, I had a fairly huge number of methods in some classes, mainly because some things that I could move out into their own methods, I did. Someone commented on this approach at the time and said that it often wasn't a good idea to do that, I forget most of the reasons he gave now, but I took this guys word for it and started trying to keep any code that wasn't going to be used more than once in its own method.
But thanks for your input, it's nice to know some of this stuff from people that have been coding alot longer than you have.
Thanks
Gary
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2. Ctrl-C is OK for closing the server. Some of us created Server GUIs, but that is not a requirement for closing the server. However, you still need to have code to lock all the records if "-1" is passed to the lock method.
I am thinking of shutting down the server properly, but haven't got a good idea yet.
Locking all the records seems to be a good idea, but it seems too completed and I don't know how to do it properly. Are there any other symple way to shutdown server?
Mark or others, could you give me some help?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
You really should open a new topic for this - you are working on the Hotel assignment, if I remember correctly, so answering your question may confuse people expecting to see Fly By Night Services comments in this thread.
Locking all the records is not really necessary - all you need to do is ensure that no updates to the file can occur while you are shutting down. You might want to consider having some sort of flag to indicate that you are shutting down, and block any new attempts to update while that flag is set. You could then shut down as soon as any old update attempts finish.
Regards, Andrew
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic