Results 1 to 2 of 2
Thread: Set ang get methods
- 03-06-2010, 08:46 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
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
- 03-06-2010, 09:09 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Idk if it would fix something, cause Idk what is null..
But in your methods, this for example:
I think here you set the static Date value to be d.Java Code:public void setDate (String d) { Date = d; }
You must do: this.Data = d; to assign it to the instance Book1 or Book2.
Same goes for your getter methods..
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
Methods
By soccer_kid_6 in forum New To JavaReplies: 3Last Post: 03-02-2010, 12:14 AM -
methods
By lilac87 in forum New To JavaReplies: 7Last Post: 07-22-2009, 06:37 PM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:36 AM -
JSP methods example
By Java Tip in forum Java TipReplies: 0Last Post: 01-30-2008, 10:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks