|
-
2 questions, please help!
hello all, i just have a couple of questions (im also posting some code)
1. if you would, please take a look at my code and let me know if my compareTo method is the best way to compare what i am trying to compare. i am basically trying to make a program that will read in 3 text files, and then build 3 lists based on the info in the text files. well the class i am posting (Order) is just one of the three main classes that will be used to sort through and determine the alphabetical order the information will be in. so please take a look and tell me if it looks okay.
2. also, i am using jGrasp as my editor and i am trying to create a workbench so i can test my compareTo method. i tried to create 2 instances so i could compare them, but it keeps throwing an error when i try to enter a mock Date. the error says something along the lines of: int cannot be converted to type java.util.Date. i was just wondering why it is throwing this error?
well please take a look and please help! thanks in advance!
Code:
import java.util.Comparator;
import java.util.Date;
public class Order implements Comparable <Order>
{
private String lastName;
private String firstName;
private String title;
private Date dateOfPurchase;
public Order(String firstName, String lastName, String title, Date dateOfPurchase)
{
this.lastName = lastName;
this.firstName = firstName;
this.title = title;
this.dateOfPurchase = dateOfPurchase;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return lastName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return firstName;
}
public void setTitle(String title)
{
this.title = title;
}
public String getTitle()
{
return title;
}
public void setDateOfPurchase(Date dateOfPurchase)
{
this.dateOfPurchase = dateOfPurchase;
}
public Date getDateofPurchase()
{
return dateOfPurchase;
}
public int compareTo(Order anOrder)
{
int result;
result = this.dateOfPurchase.compareTo(anOrder.dateOfPurchase);
if (result == 0)
{
result = this.lastName.compareTo(anOrder.lastName);
}
else
{
if(result ==0)
{
result = this.firstName.compareTo(anOrder.firstName);
}
else
{
result = this.title.compareTo(anOrder.title);
}
}
return result;
}
public boolean equals(Order anOrder)
{
boolean result;
result = (this.dateOfPurchase.equals(anOrder.dateOfPurchase) && this.lastName.equals(anOrder.lastName)
&& this.firstName.equals(anOrder.firstName) && this.title.equals(anOrder.title));
return result;
}
Similar Threads
-
Replies: 13
Last Post: 05-23-2005, 05:22 PM
-
By semidieu in forum .NET
Replies: 0
Last Post: 02-18-2005, 06:40 AM
-
By Murray Foxcroft in forum VB Classic
Replies: 0
Last Post: 04-16-2002, 01:44 AM
-
By Paul Gardner in forum VB Classic
Replies: 1
Last Post: 06-15-2001, 09:10 AM
-
By Kevin Gray in forum authorevents.kurata
Replies: 1
Last Post: 04-17-2000, 01:14 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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks