Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2007, 04:08 PM
Member
 
Join Date: Dec 2007
Posts: 1
Jinxes is on a distinguished road
Object Interaction
Greetings,

I have classes called 'Date' and 'Information'. In date class i have defined how date should be stored as well as in Information. However, when i create an object using (BlueJ) Information, the stored date in the information class does not seem to transfer the details to the Date class, which it should be doing. To clarify what i mean, here are the codes;

Information (code)

public class Information
{

private int reference;
private String name;
private Date Date;

public Information(int ref, String nam)
{

reference = ref;
name = nam;

Date = null; //date should be stored as null unless user sets the date manually.

}

public void setDateRequired(int day, int month, int year)
{
Date = new Date(day, month, year);
}


Date

public class Date
{
/** Fields of a Date - just the day, month and year*/
private int day;
private int month;
private int year;

/**
* Constructor for objects of class Date, sets a default date of 1/1/2000
*/
public Date()
{
day = 1;
month = 1;
year = 2000;
}

/**
* Constructor for objects of class Date
* @param d - the day part of the date (1 - 31, depending on the month).
* @param m - the month part of the date (1 - 12).
* @param y - the year part of the date.
*/
public Date(int d, int m, int y)
{
day = d;
month = m;
year = y;
}



Could anyone please tell me what I' am doing wrong? There are no interaction between the two classes nor objects.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 02:05 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public class InformationRx { private int reference; private String name; private DateRx date; public InformationRx(int ref, String nam) { reference = ref; name = nam; date = null; //date should be stored as null. } public void setDateRequired(int day, int month, int year) { date = new DateRx(day, month, year); } public static void main(String[] args) { InformationRx irx = new InformationRx(25, "testingAgent"); irx.setDateRequired(2, 11, 2007); System.out.println(irx.date); } } class DateRx { /** Fields of a Date - just the day, month and year*/ private int day; private int month; private int year; /** * Constructor for objects of class Date, sets a default date of 1/1/2000 */ public DateRx() { this(1, 1, 2000); } /** * Constructor for objects of class Date * @param d - the day part of the date (1 - 31, depending on the month). * @param m - the month part of the date (1 - 12). * @param y - the year part of the date. */ public DateRx(int d, int m, int y) { day = d; month = m; year = y; } public String toString() { return "DateRx[day:" + day + " month:" + month + " year:" + year + "]"; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object sireesha New To Java 1 01-10-2008 03:31 AM
Object ID javaplus New To Java 4 11-26-2007 02:08 PM
Getting name of object class Java Tip Java Tips 0 11-05-2007 07:22 PM
Creating object of Type Object class venkatv New To Java 3 07-17-2007 05:33 PM
Operator < cannot be applied to java.lang.Object, Object Albert Advanced Java 1 07-13-2007 05:19 PM


All times are GMT +3. The time now is 03:46 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org