Simple Hotel Front-Desk System.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    Simple Hotel Front-Desk System.

    This is for my friend. He is a HRM student and was assigned to demo on how to operate a Simple Hotel front-desk system.

    I've searched on the net to help him, but all of those freeware softwares are difficult to handle and manipulate.....

    My last option is to create a program for him.
    Easy to deploy and no hustle to maintain version.
    First version is to implement it through "Pure file handling"
    Second is to use a database.

    (Adding to my experience while learning java)

    Im now starting @ first version

    Im now designing this program which i call it Simple Hotel Front-Desk System.

    There are 17 values that should be handled in every guest's data

    eg. complete guest's name, contact numbers etc.....

    What came first on my mind is to implement them with few arrays
    The purpose is to manipulate them carefully ( an experiment )

    I doubt about the other options to reimplement it in a safer handling.

    Can you advice me experts? about how to implement it more safer?
    Maybe arraylist, but for me it is more heavy to implement when it comes to updating those values inside of it if the primary value ( primary key in database ) will be changed in position

    This is for the first version, "pure file handling"

    Im waiting for your replies,
    sukatoa
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Never, ever go the route of those silly arrays:

    [code=java]
    String[] firstName;
    String[] lastName;
    [/code]

    Java compilers should forbid such code and wipe your harddisk for it. Better think
    of your data model a bit more, especially when you want to take the route of a
    RDBMS for storage purposes. What comes to mind is:

    [code=java]
    interface PK extends Comparable<PK> { .. }
    ...
    interface Record {
    PK getPrimaryKey() ;
    }
    ...
    class Table extends HashMap<PK, Record> { ... }
    [/code]

    but never go for that silly arrays route.

    kind regards,

    Jos

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Originally posted by JosAH
      Never, ever go the route of those silly arrays:

      [code=java]
      String[] firstName;
      String[] lastName;
      [/code]

      Java compilers should forbid such code and wipe your harddisk for it. Better think
      of your data model a bit more, especially when you want to take the route of a
      RDBMS for storage purposes. What comes to mind is:

      [code=java]
      interface PK extends Comparable<PK> { .. }
      ...
      interface Record {
      PK getPrimaryKey() ;
      }
      ...
      class Table extends HashMap<PK, Record> { ... }
      [/code]

      but never go for that silly arrays route.

      kind regards,

      Jos
      Ok, im on my way to hashmap..... Thank you....

      This program's max data set input is limited to 100.

      It is ok if i implement a class that uses Collator setting it into PRIMARY strength to compare all of those datas?
      (For Black List Search Feature purposes)

      Im afraid im starting again a bad idea... hope not.....

      Thanks for your reply Jos,
      It really helps

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by sukatoa
        Ok, im on my way to hashmap..... Thank you....

        This program's max data set input is limited to 100.

        It is ok if i implement a class that uses Collator setting it into PRIMARY strength to compare all of those datas?
        (For Black List Search Feature purposes)

        Im afraid im starting again a bad idea... hope not.....

        Thanks for your reply Jos,
        It really helps
        There's a small hotel just a few blocks away from me; it has 120 rooms so I can't
        sell them your software then? How silly ...

        Most of the time ideas aren't bad, it's the implementations that are extremely bad.
        Better think about the requirements a bit more and think about your object model
        first before you start thinking about nifty data structures.

        kind regards,

        Jos

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          Originally posted by JosAH
          There's a small hotel just a few blocks away from me; it has 120 rooms so I can't
          sell them your software then? How silly ...

          Most of the time ideas aren't bad, it's the implementations that are extremely bad.
          Better think about the requirements a bit more and think about your object model
          first before you start thinking about nifty data structures.

          kind regards,

          Jos
          Yah, i got it, thanks again...

          Comment

          • sukatoa
            Contributor
            • Nov 2007
            • 539

            #6
            Here is what i've done so far on the experiment

            [CODE=JAVA]import java.util.HashM ap;
            import java.util.Itera tor;
            import java.util.Array List;
            import java.util.Scann er;
            import java.util.Rando m;

            public class HashMapTest{

            HashMap<String, ArrayList> table = new HashMap<String, ArrayList>();
            ArrayList<Strin g> list;
            Scanner scan = new Scanner(System. in);
            int key = 0; //UniqueKey
            Random r = new Random();

            public static void main(String sukatoa[]){
            new HashMapTest();
            }

            public HashMapTest(){
            while(true){
            try{
            System.out.prin t("[1]Add\n[2]Show\n\n[3]Exit ");
            int t = Integer.valueOf (scan.next());
            switch(t){
            case 1:add();break;
            case 2:show();break;
            case 3:scan.close(); System.gc();Sys tem.exit(0);
            default: continue;
            }
            }catch(Exceptio n e){
            System.out.prin tln("\nWrong input\n\n\n");
            }System.gc();
            }
            }

            void add(){
            list = new ArrayList<Strin g>();
            list.add("Surna me: ".concat(getRan domValue()));
            list.add("First name: ".concat(getRan domValue()));
            list.add("Middl eName: ".concat(getRan domValue()));
            list.add("Addre ss: ".concat(getRan domValue()));
            list.add("Compa nyAddress: ".concat(getRan domValue()));
            list.add("Landl ine: ".concat(getRan domValue()));
            list.add("Mobil e: ".concat(getRan domValue()));
            list.add("Fax: ".concat(getRan domValue()));
            list.add("Email : ".concat(getRan domValue()));
            list.add("Room Type: ".concat(getRan domValue()));
            list.add("Room Number: ".concat(getRan domValue()));
            list.add("Addit ional Guests: ".concat(getRan domValue()));
            list.add("Their Names: ".concat(getRan domValue()));
            list.add("Payme nt Type: ".concat(getRan domValue()));
            list.add("Arriv al & Departure: ".concat(getRan domValue()));
            list.add("Billi ng Arrangement: ".concat(getRan domValue()));
            list.add("Desk Clerk: ".concat(getRan domValue()));
            table.put(getUn iqueKey(),list) ;
            key++;
            }

            void show(){
            Iterator i = table.keySet(). iterator();
            while(i.hasNext ()){
            String t = (String)i.next( );
            System.out.prin tln("\n\n"+t);
            for(Object entry : table.get(t)){
            System.out.prin tln("\t-"+entry);
            }
            }
            }

            String getUniqueKey(){
            return String.valueOf( key);
            }

            String getRandomValue( ){
            return String.valueOf( r.nextInt(500)) ;
            }
            }
            }[/CODE]

            since the returned elements are not in particular order. (iterator)

            I have no idea how to implement like

            (unless this set is an instance of some class that provides a guarantee). this comes from the API iterator method on Set
            Can you advice me how to deal about it?

            it should be 0 1 2 3 4 5 6 7 8 etc....

            Is there a safer way to sort this first after showing the output?

            May idea is,
            to get all of those key, store in an array... sort,
            and iterate to get the list by using

            table.get(key) where key is from an sorted array.....


            waiting for you replies,
            sukatoa

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Have a look at TreeSet.

              Also read the initializers article for where to put all those add calls.

              Comment

              • sukatoa
                Contributor
                • Nov 2007
                • 539

                #8
                Originally posted by r035198x
                Have a look at TreeSet.

                Also read the initializers article for where to put all those add calls.

                Copy that,

                Thanks for the reply.
                sukatoa

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  I still think this is a silly array solution in disguise. Those data members (first name,
                  last name, payment etc.) belong in another class object, say, Reservation.
                  Such a Reservation object should be able to cough up a unique primary key
                  and it should override equals, hashCode and be Comparable at least; oh,
                  before I forget make the Reservation class implement the Serializable object.

                  Also don't, I repeat don't stick all that input jam in the Reservation class and
                  especially not in its constructor. This is intended as positive criticism but don't
                  mix all that I/O stuff in your classes. Separate that stuff into a ReservationFact ory
                  class and the Reservation class itself.

                  As I wrote: ideas are not that bad; implementations are bad and yours' is going
                  to be one if you don't take care.

                  kind regards,

                  Jos

                  Comment

                  • sukatoa
                    Contributor
                    • Nov 2007
                    • 539

                    #10
                    Such a Reservation object should be able to cough up a unique primary key
                    and it should override equals,
                    I have doubt about this. Can you explain it further Jos?

                    Separate that stuff into a ReservationFact ory
                    class and the Reservation class itself.
                    That was one of my plan.... now confirmed... :)

                    As I wrote: ideas are not that bad; implementations are bad and yours' is going
                    to be one if you don't take care.
                    I should care of it.

                    Thanks for the reply. :)
                    sukatoa

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by sukatoa
                      I have doubt about this. Can you explain it further Jos?
                      Given those records you showed us; think of questions you want to be able to
                      answer:

                      - is room X taken? if so, show the inhabitants' details.
                      - family Y leaves; what do they have to pay?
                      - family Z wants three rooms; are they available?
                      - etc.

                      for each of those questions you want to iterate over certain rooms, associated
                      with certain primary keys to do it fast.

                      kind regards,

                      Jos

                      Comment

                      • sukatoa
                        Contributor
                        • Nov 2007
                        • 539

                        #12
                        Originally posted by JosAH
                        Given those records you showed us; think of questions you want to be able to
                        answer:

                        - is room X taken? if so, show the inhabitants' details.
                        - family Y leaves; what do they have to pay?
                        - family Z wants three rooms; are they available?
                        - etc.

                        for each of those questions you want to iterate over certain rooms, associated
                        with certain primary keys to do it fast.

                        kind regards,

                        Jos
                        Ok, i got it. I doubt about what kind of primary key should i use. It should be one of the records.

                        My choice is the room number, since room number never be duplicated....
                        What's the advantage when it choose this to be the prime key?

                        What can you suggest?

                        About comparing Strings.

                        Which is a little bit faster when comparing?
                        [CODE=JAVA]Collator.compar e(st 1,st 2) [/CODE] that was set to PRIMARY strength

                        or
                        [CODE=JAVA]String.compareT oIgnoreCase(ano ther string)[/CODE]

                        Waiting for your replies,
                        Sukatoa

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by sukatoa
                          Ok, i got it. I doubt about what kind of primary key should i use. It should be one of the records.

                          My choice is the room number, since room number never be duplicated....
                          What's the advantage when it choose this to be the prime key?

                          What can you suggest?

                          About comparing Strings.

                          Which is a little bit faster when comparing?
                          [CODE=JAVA]Collator.compar e(st 1,st 2) [/CODE] that was set to PRIMARY strength

                          or
                          [CODE=JAVA]String.compareT oIgnoreCase(ano ther string)[/CODE]

                          Waiting for your replies,
                          Sukatoa
                          Primary key : Room number is OK if you don't have duplicates for them (you could if you have many floors and reset the count on each floor).
                          Comparing Strings? Just use the equals or equalsIgnoreCas e method.

                          Comment

                          • sukatoa
                            Contributor
                            • Nov 2007
                            • 539

                            #14
                            Originally posted by r035198x
                            Primary key : Room number is OK if you don't have duplicates for them (you could if you have many floors and reset the count on each floor).
                            Comparing Strings? Just use the equals or equalsIgnoreCas e method.
                            Thanks, im on my way.....

                            Thanks again....

                            Comment

                            • sukatoa
                              Contributor
                              • Nov 2007
                              • 539

                              #15
                              Just a quick,

                              What if i will not serialized my classes...
                              eg. not setting the serialVersionUI D....
                              What will happen to my program?
                              What will be the disadvantage of doing like this?

                              waiting for your replies,
                              sukatoa

                              Comment

                              Working...