Results 1 to 5 of 5
  1. #1
    angelsface200 is offline Member
    Join Date
    Apr 2014
    Posts
    1
    Rep Power
    0

    Default Need help with program...

    I have been trying to learn object-oriented programming for a while but it's not clicking with me. I have to do this assignment, but I don't know what I'm doing wrong. It has to deal with implementation, abstraction, and making objects.

    This is the original game (it's called Battleship). There are a few places that are messed up, but I'm trying to work on it:
    public class Battleship { private static int player1Hits = 0; private stat - Pastebin.com

    These are the methods the instructor gave us:
    public interface Player{ /** * This player is being fired upon. Given a co - Pastebin.com

    And this is what I made out of it:
    public interface Player{ public char fireUpon(Coordinate x); for(int a - Pastebin.com

    And this is the main class
    public class Player_1051 implements Player{ private static int player1Hi - Pastebin.com

    Whenever I put the last two codes into eclipse, a whole bunch of red lines show up. I had already submitted in my project, but I think it's all wrong. I just need help, I am so frustrated. I know I have to change the main class, but where and how?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Need help with program...

    If you have some specific questions about your code, post the code here on the forum so it can be seen and ask your questions about it.
    Also copy the full text of the compiler's error messages and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Need help with program...

    Hi,

    You placed code inside the interface. That is completly wrong. An interface only defines functions that a class implementing the interface must have.

    Konrad

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    13

    Default Re: Need help with program...

    Quote Originally Posted by kneitzel View Post
    Hi,

    You placed code inside the interface. That is completly wrong. An interface only defines functions that a class implementing the interface must have.

    Konrad
    Careful: keep the Java 8 extensions in mind though.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Need help with program...

    Thank you gimbal for this correction. I have to confess that I didn't check all the new features of Java 8. I just had a quick look right now and found the default implementation that can be put inside the interface.

    With kind regards,

    Konrad

Similar Threads

  1. Replies: 6
    Last Post: 12-15-2013, 07:40 AM
  2. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  3. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •