Hey guys I am writing this program for my final where i have to create a library database type thing and then create a GUI for it. I have 3 fields(author, title, and due date) i have the author and title but i cant figure out how to pass the due date to the other object. Here is my classes...
please help
Code:
public class Date
{
private int month; //variable to store the month
private int day; //variable to store the day
private int year; //variable to store the year
//sets all three fields to -1;
public Date()
{
setMonth(-1);
setDay(-1);
setYear(-1);
}
//sets the values by invoking the setDate method
public Date(int month, int day, int year)
{
setDate(month, day, year);
}
public void setDate(int month, int day, int year)
{
setMonth(month);
setDay(day);
setYear(year);
}
public void setDay(int d) { day = d; }
public void setMonth(int m) { month = m; }
public void setYear(int y) { year = y; }
public int getMonth() { return month; }
public int getDay() { return day; }
public int getYear() { return year; }
//Returns the date in the form mm-dd-yyyy
public String toString()
{
return (month + "-" + day + "-" + year);
}}
Code:
public class testFinalProjectEver
{
public static void main(String[] args)
{
libraryBook b1 = new libraryBook();//instantiantion
Date d1= new Date();
d1.setDate(02, 28, 1991);
b1.setAuthor("Mike");
b1.setTitle("Poop");
System.out.println(b1.toString());
}
}
Code:
import java.util.Date;
public class libraryBook
{
private String title;
private String author;
private Date dueDate;
public libraryBook()
{
title="XXXBLANKXXXXX";
author="XXXXBLANKXXXX";
}//end default constructor
public libraryBook(String theTitle,String theAuthor,Date theDueDate)
{
author=theAuthor;
title=theTitle;
dueDate=theDueDate;
}
//DEFAULT CONSTRUCTOR
public void setTitle(String ti) {title=ti;}
public void setAuthor(String au) {author=au;}
public void setDate(Date da) {dueDate=da;}
public String getTitle() {return title;}
public String getAuthor() {return author;}
public Date getDueDate() {return dueDate;}
public String toString()
{
String s;
return s=("The title is "+getTitle()+", The author is"+ getAuthor()+",The Due Date is "+getDueDate());
}
}//end libraryBook