Results 1 to 6 of 6
  1. #1
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Implementation problem

    Hello again, sorry to post again so soon

    I'm developing a class hierarchy of books, and my implementation skills are not quite adequate.
    take a look

    Java Code:
    //Book interface
    public interface Book
    {
        public int numPages();
        public String bookTitle();
        public String authorName();
        public boolean isHardCover();
        public boolean isOpen();
        public void open();
        public void close();
    }
    //novel class
    public class Novel implements Book
    {
        private int pages;
        private String title;
        private String authorfirst;
        private String authorlast;
        private boolean hardCover;
        private boolean Open;
        public Novel(String booktitle, int numpages, String lastname, String firstname, boolean _hardCover)
        {
            pages = numpages;
            title = booktitle;
            authorlast = lastname;
            authorfirst = firstname;
            hardCover = _hardCover;
            Open = false;
        }
        public int numPages()
        {
            return pages;
        }
        public String bookTitle()
        {
            return title;
        }
        public String authorName()
        {
            return authorlast + ", " + authorfirst;
        }
        public boolean isHardCover()
        {
            return hardCover;
        }
        public void isOpen()
        {
            return Open;
        }
        public void open()
        {
            isOpen = true;
        }
        public void close()
        {
            isOpen = false;
        }
    }
    it says that novel doesn't overwrite the abstract classes in book, am i overlooking something?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Implementation problem

    Java Code:
     public void isOpen()
        {
            return Open;
        }
        public void open()
        {
            isOpen = true;
        }
        public void close()
        {
            isOpen = false;
        }
    there is no variable isOpen! (do you mean Open? :D) and if a method is declared as void, you can`t return something :D

  3. #3
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Implementation problem

    wow. i need to drink some coffee can't believe i missed that. The variable Open was isOpen and i missed those. Also the declaration is just plain dumb on my part. thank you very much!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Implementation problem

    Just a note, but there's no need at all (and it's generally frowned upon) to declare the methods in an interface as 'public'.
    They're all public by default.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Implementation problem

    Oh i know tolls, its just that this is a class and she takes off if we don't use the public. The programs i do outside of homework i dont use the public keyword

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Implementation problem

    You're kidding?
    Blimey.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Problem with the result of the implementation
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 5
    Last Post: 01-11-2010, 05:33 AM
  2. Queue implementation - Enqueue problem
    By jefrazie in forum New To Java
    Replies: 5
    Last Post: 11-05-2009, 01:10 AM
  3. Problem in Calculator implementation using Stack
    By realahmed8 in forum New To Java
    Replies: 1
    Last Post: 12-19-2008, 11:58 PM
  4. Problem in file implementation
    By BHCluster in forum New To Java
    Replies: 6
    Last Post: 04-21-2008, 03:21 AM
  5. Replies: 0
    Last Post: 04-09-2008, 06:41 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
  •