Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Object Oriented Problem

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Object Oriented Problem

    Hi, I am a fresh graduate from Diploma in IT. Recently I just went to an interview. The interviewer gave me a question. The question is, he want me to code him a program, base on a snake game(quite popular in nokia oldies handphone). Not a full program actually but just a part only. You have 4 buttons for go left, go right, go up, and go down. It also have a calculationOfAxis per second for the movement rate of the snake and also a callSnake function for the GUI. Below is a rough example of the function.

    moveUp(){...}
    moveDown(){...}
    moveRight(){...}
    moveLeft(){...}

    calculationOfAxis(x-axis, y-axis){
    callsnake()
    }

    Then he ask me that if I want to change the GUI of the snake, what should I do? Then I replied him just change the codes of the snake to car. Then he told me that wouldn't it be better if you do it in another way than keep changing your codes? Then i came out a solution which is the code below.

    public class Parents(){
    moveUp(){....};
    moveDown(){...};
    moveRight(){...};
    moveLeft(){...};
    calculationOfAxis(x-axis, y-axis){...};
    }

    public class Child extends Parents(){
    super(moveUp(),moveDown(),moveRight(),moveLeft(),c alculationOfAxis(x,y);

    callcar();
    }

    After that I said you can call whatever you want in the child class [eg: callShip(), callMotor()]

    Then he said my answer is acceptable but not the efficient way. So, he gave me a situation which he said that his company project roughly consists of millions of code. He want a method to add a new features in the project without the need of editing the existing code and can guarantee it will work with the old codes. He also said that he want to test the new codes ONLY. You can neglect the old codes for the sake of saving time.

    Well, that is where I am stuck now. Honestly I don't really quite get what he want. So, hopefully someone can show me the solution of this question.
    Last edited by -j-t-; June 12th, 2012 at 08:06 AM. Reason: bad english


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Object Oriented Problem

    I find your post really hard to read. I recommend you read the link in my signature on asking questions the smart way, especially the bit about proper spelling, grammar, punctuation, and capitalization.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Object Oriented Problem

    Quote Originally Posted by KevinWorkman View Post
    I find your post really hard to read. I recommend you read the link in my signature on asking questions the smart way, especially the bit about proper spelling, grammar, punctuation, and capitalization.
    Hi, I am sorry with my grammar. I have revamped my question and if you still having problem with understanding it then I am really sorry because of my low level of English writing.
    Last edited by -j-t-; June 12th, 2012 at 08:10 AM.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Object Oriented Problem

    Quote Originally Posted by -j-t- View Post
    Hi, I am sorry with my grammar. I have revamped my question and if you still having problem with understanding it then I am really sorry because of my low level of English writing.
    Thanks. Your English is okay, it was just your lack of capitalization and amount of abbreviations- many of our members are not native English speakers, so abbreviations and text-message language can be really confusing. Thanks for making the change.

    I think what he was getting at was something like MVC, model view controller. If the model part of it is written correctly, then it doesn't care what the view part is doing. So the model is what is already written, the view is the game screen, and the controller would be the keyboard inputs. You shouldn't have to change the underlying model to change the view or the controller.

    Much of Java is designed in this way. Recommended reading: Model?view?controller - Wikipedia, the free encyclopedia

    That's just a guess though, so he might have been talking about something else.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. help for Object Oriented Programming RMI
    By clapton in forum Object Oriented Programming
    Replies: 2
    Last Post: March 22nd, 2012, 05:38 AM
  2. Object oriented programming
    By merr78 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 9th, 2012, 01:32 AM
  3. Object oriented programming
    By jonnitwo in forum Object Oriented Programming
    Replies: 8
    Last Post: September 2nd, 2011, 12:18 PM
  4. Object-oriented mess
    By mjpam in forum Object Oriented Programming
    Replies: 3
    Last Post: May 7th, 2011, 11:27 AM
  5. Object-oriented applet
    By mjpam in forum Object Oriented Programming
    Replies: 26
    Last Post: September 15th, 2010, 06:43 AM