Results 1 to 2 of 2
  1. #1
    jcm2302 is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Set ang get methods

    help i cant get this to work i keep getting null values



    //************************************************** ******************
    // BookShelf.java Author: James Marshall
    //
    // Demonstrates the implementation of multiple text fields.
    //************************************************** ******************

    public class BookShelf
    {


    public static void main (String[] args)
    {

    //This is an abstantiated variable//





    Book Book1 = new Book ("Java Software Solutions", "Lewis & Loftus", "Addison Wesley", "2009");
    Book Book2 = new Book ("Cisco Working at a Small-to-Medium Buisness or ISP", "Allan Reid, Jim Lorenz", "Cisco Press", "2008");

    System.out.println (Book1.getTitle());
    System.out.println (Book1.getAuthor());
    System.out.println (Book1.getPublisher());
    System.out.println (Book1.getDate());

    System.out.println (Book2.getTitle());
    System.out.println (Book2.getAuthor());
    System.out.println (Book2.getPublisher());
    System.out.println (Book2.getDate());

    Book1.setTitle ("Java Software Solutions");
    Book1.setAuthor ("Lewis & Loftus");
    Book1.setPublisher ("Addison Wesley");
    Book1.setDate ("2009");

    Book2.setTitle ("Cisco Working at a Small-to-Medium Buisness or ISP");
    Book2.setAuthor ("Allan Reid, Jim Lorenz");
    Book2.setPublisher ("Cisco Press");
    Book2.setDate ("2008");

    }
    }





    //************************************************** ******************
    // BookPanel.java Author: James Marshall
    //
    // Demonstrates the implementation of multiple text fields.
    //************************************************** ******************

    public class Book
    {

    private String Title, Author, Publisher, Date;

    public Book (String t, String a, String p, String d)
    {
    }
    //String Mutations//

    public void setTitle (String t)
    {
    Title = t;
    }

    public void setAuthor (String a)
    {
    Author = a;
    }

    public void setPublisher (String p)
    {
    Publisher = p;
    }

    public void setDate (String d)
    {
    Date = d;
    }

    //Return Accessor//

    public String getTitle()
    {
    return Title;
    }

    public String getAuthor()
    {
    return Author;
    }

    public String getPublisher()
    {
    return Publisher;
    }

    public String getDate()
    {
    return Date;
    }


    public String toString()
    {

    return "The Title is: " + Title + ",Author is: " + Author + ",Publisher is: " + Publisher + ",Copyright Date is: " + Date;
    }
    }

    any help is appriciated

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Idk if it would fix something, cause Idk what is null..
    But in your methods, this for example:
    Java Code:
    public void setDate (String d)
    {
    Date = d;
    }
    I think here you set the static Date value to be d.
    You must do: this.Data = d; to assign it to the instance Book1 or Book2.
    Same goes for your getter methods..

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Methods
    By soccer_kid_6 in forum New To Java
    Replies: 3
    Last Post: 03-02-2010, 01:14 AM
  3. methods
    By lilac87 in forum New To Java
    Replies: 7
    Last Post: 07-22-2009, 07:37 PM
  4. Replies: 4
    Last Post: 04-03-2009, 07:36 AM
  5. JSP methods example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 11:00 AM

Tags for this Thread

Posting Permissions

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