Thread: Java - Need help ASAP
-
March 12th, 2010, 08:55 AM #1Junior Member
- Join Date
- Mar 2010
- Posts
- 1
Java - Need help ASAP
I am a newbie with Java, and seriously need some help. I have an assignment due, and have no idea how to start.
Question 1 is as foolows:
Create a class named Pet to represent pets. A pet is described using three data fields 1) type
(dog, cat, bird, etc) 2) breed (pit bull, Egyptian, African grey, etc.) and 3) age of the pet.
Two constructors are given for the class; one is the default constructor where the data fields
type, breed and age are initialized to unknown, unknown and 0 respectively. The
second constructor allows the object to be initialized to the values specified by the user.
Provide methods getType(), getBreed() and getAge() to obtain the values of
type, breed and age of the pet. Also provide methods setType(), setBreed() and
setAge() for setting the values of type, breed and age of the pet.
Include a method compareAge (Pet p), which compares the ages of the current pet to
the Pet p. If the current pet is older than Pet p, then the method returns true otherwise it
returns false.
Include a method to print the details of a pet.
Develop a test class to test Pet.
Next question:
Write a class PetList which represents a list of Pets a person owns. The class PetList
has a one-to-many association between itself and the Pet class (Question mentioned above). This class
should have methods to add Pets to the list (use the assert statement to ensure that pet
names are unique), to check if one owns a specific type of pet and to return the age of a pet if
the name is provided.
Develop a test class to test PetList.
Can somebody PLEASE help, I am stressing like mad!!! Hope to have a response soon!!!!
-
March 24th, 2010, 11:14 PM #2Member
- Join Date
- Mar 2010
- Location
- Ontario
- Posts
- 159
Wow I can't believe noone answered you for a whole week! For shame.
I realize your assignment is probably long over-due by now, but in the interest of higher education, I will answer anyways. Hopefully you will someday come back and check this, and if not, maybe it will be useful to someone else.
for question 1: Im assuming you have no knowledge of Java at all then? Well, we make classes thusly >
public class Pet {
// Data Members
private String type;
private String breed;
private int age;
// this is a default constructor. Default because it has no parameters
public Pet () {
type = "unknown";
breed = "unknown";
age = 0;
}
// this is the second constructor, because.. well because there was one before this?
public Pet ( String t, String b, int a ) {
type = t;
breed = b;
age = a;
}
// this is a getter. They're basically all the same, so if you cant get it from this,
// I feel for you
public String getType () {
return type;
}
// this is a setter. Again...
public void setType ( String ty ) {
type = ty;
}
// and finally the compare method, which i think you should have been able to piece
// together by now
public boolean compareAge ( Pet p ) {
if ( age > p.age ) return true;
else return false;
}
}
Other than that, as long as you understand the whole concept of object.method() or object.member, you should be able to piece together the whole "test class" thing. Except unless this is a major project, it was probably already due, in which case, sorry we couldn't help in time!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Launching Java webpages with different Java settings?
By LostBok in forum Webmastering and ProgrammingReplies: 1Last Post: December 11th, 2006, 03:38 AM -
need help ASAP!
By mista_haqeem in forum Graphics Cards and DisplaysReplies: 4Last Post: July 23rd, 2006, 11:29 PM -
Need TV Help ASAP
By MitaDC in forum General Tech DiscussionReplies: 1Last Post: February 17th, 2006, 02:17 PM -
What is Better!? Help ASAP!!
By Crisstina in forum Graphics Cards and DisplaysReplies: 12Last Post: May 18th, 2005, 09:35 PM



LinkBack URL
About LinkBacks



Reply With Quote

Hi This is a really nice screenshot programmer. I like most in programme is screen shots of Green shots in action, its looks nice.
Really nice screenshot program