Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with code!

Options
  • 24-04-2003 2:16pm
    #1
    Registered Users Posts: 4,946 ✭✭✭


    Im writing a program for college that inputs, deletes, edits and shows bookings for a cinema ticket.

    I have to use vectors for the program and we can use any other methods for the layout.

    Basicly i need help with the coding used to call a procedure..
    This is pseudo code of what i mean

    main(); // in here is the names of the sections i wish touse
    newbook();
    delbook();
    etc...

    static void main()
    ************
    1 newbook // shows a ****ty layout of options
    2 delbook
    3 editbook
    *************

    switch (book)
    case 1 : newbook
    case 2 :



    Right, heres the part i need help with. The parts in bold i need them to call a different procedure.
    So when i hit '1' it opens up the newbookings section, when i hit '2' it opens up delete booking and so on..

    What code do i use to make it call the different sections?

    Cheers

    reD.


Comments

  • Closed Accounts Posts: 1,672 ✭✭✭Wolf


    I take it this is in C++ ?


  • Registered Users Posts: 4,946 ✭✭✭red_ice


    sorry wolf - i ment to say its in java! :)

    you want me to tell arnie hensman you said hello? :P


  • Closed Accounts Posts: 1,672 ✭✭✭Wolf


    No tell him go to hell, go to hell and die ;)

    As to the question I have a program very much like that at home I wrote last year when does it ahve to be in for ?


  • Registered Users Posts: 4,946 ✭✭✭red_ice


    wednesday :)

    get onto fortress.ie!! :E

    /msg reDDY

    and ill explain what i need help with


  • Closed Accounts Posts: 1,672 ✭✭✭Wolf


    Sorry im in work atm and cant use mirc. Ill try if I get a chance. Is it the vector contruction you have probelms with or is it the sotorage ?


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    heh...

    ok, so your code looks somthing like:
    public class CinemaBooker {
    
        public newBook() { .... }
        public delBook() { .... }
        public editBook() { ....}
    
        public static void main(String[] args) {
            .....
        }
    }
    

    And in your main method you have (something like)
    int book = System.in.read();

    So for the switch statement, it would just be
    switch(book)
    case (1): newBook();
    break;
    case (2): delBook();
    break;
    case (3): editBook();
    break;
    default: System.exit(0);


    If that makes any sense :)


  • Registered Users Posts: 4,946 ✭✭✭red_ice


    it does, but for ''public newBook() { .... }'' do i put {return surname} or what ever?

    And the switch statement is not calling the procedures for me :/

    know what i mean?


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    You need to create the object of the class within the main section to access the methods.

    eg.
    Class myClass {
      public void helloWorld() {
        System.out.println("Hello World"); 
      }
    
      public static void main(String[] args) {
         myClass example = new myClass();
    
         example.helloWorld();
      }
    }
    

    Also if newbook() doesn't need to return a value (which guessing at what's written so far it doesn't) then use "public void newbook() {...}".


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Originally posted by Hobbes
    You need to create the object of the class within the main section to access the methods.

    eg.

    Class myClass {
      public void helloWorld() {
        System.out.println("Hello World"); 
      }
    
      public static void main(String[] args) {
         myClass example = new myClass();
    
         example.helloWorld();
      }
    }
    

    Also if newbook() doesn't need to return a value (which guessing at what's written so far it doesn't) then use "public void newbook() {...}".

    Oh look at that, I forgot to include type identifiers....Must have been tired last night.

    You could make the class purely static, from an aesthetic POV, but do what Hobbes said, it'll save on confusion...


Advertisement