Results 1 to 6 of 6
  1. #1
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Help With Inheritance

    I am trying to figure out inheritance, but am still running into problems. I do not fully understand where I am going wrong. Any help would be awesome.

    Java Code:
    public class DemoBook
    {
      public static void main (String[] args)
      {
        Textbook aTextbook = new Textbook();
        aTextbook.showPages();
        
      }
    }
    Java Code:
    import javax.swing.*;
    
    public class Book
    {
      private int pages;
      private String title;
      private int grade;
      
      public void showTitle()
      {
        JOptionPane.showMessageDialog (null, "Title of book: " + title);
      }
      
      public void inputTitle(String title)
      {
        String titleString = new String(" ");
        titleString = JOptionPane.showInputDialog(null,
           "Enter the name of your book");
        this.title = titleString;
      }
    
      
      public void inputPages(int pages)
      {
        String pagesString = new String(" ");
        pagesString = JOptionPane.showInputDialog(null,
           "Enter the number of pages in your book");
        this.pages = Integer.parseInt(pagesString);
      }
      
        public void gradeLevel(int grade)
      {
        String gradeString = new String(" ");
        gradeString = JOptionPane.showInputDialog(null,
           "Enter the grade level of your book");
        this.grade = Integer.parseInt(gradeString);
      }
       
    }
    Java Code:
    import javax.swing.*;
    public class Textbook extends Book
    {   
      public void showPages(String title, int pages, int grade)
      {
        JOptionPane.showMessageDialog (null, "The number of pages in " + title + " is " + pages +
      ". It is made for grade " + grade);
      }
    }

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help With Inheritance

    You haven't provided enough information for anyone to tell where you're going wrong. Are you getting some error message? Does the program not behave as expected? What is the expected behavior, and what is the actual behavior?
    Get in the habit of using standard Java naming conventions!

  3. #3
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Re: Help With Inheritance

    Sorry. I am trying to gather information in the Book class and then use the Textbook class to output the information. As it stands now I am getting an error on line 6 of the DemoBook class. The error is saying "showPages(java.lang.String,int,int) in Textbook cannot be applied to ()" Unfortunately I do not know where I made the error as I do not think that the error is actually in that line of code. So...???? Not sure if that is helpful.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help With Inheritance

    Your showPages(...) method has three parameters, but you're calling it with no parameters.
    Get in the habit of using standard Java naming conventions!

  5. #5
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Re: Help With Inheritance

    I am sorry but I do not know exactly what you mean. Does this mean that when I call it in my main method that I should include (title, pages, grade) or (String title, int pages, int grade)? I have tried this approach and it throws an error of "expected )"???

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help With Inheritance

    It would look something like this:

    Java Code:
    aTextbook.showPages("World History", 354, 10);
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Inheritance
    By Nazneen Ali in forum New To Java
    Replies: 12
    Last Post: 10-10-2013, 10:01 PM
  2. Inheritance
    By new_2_j in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 06:56 PM
  3. JPA Inheritance
    By videanuadrian in forum Advanced Java
    Replies: 0
    Last Post: 01-11-2011, 07:30 AM
  4. JPA Inheritance
    By videanuadrian in forum New To Java
    Replies: 1
    Last Post: 01-10-2011, 07:44 AM
  5. using inheritance
    By senca in forum New To Java
    Replies: 4
    Last Post: 08-15-2010, 08: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
  •