473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Urgent help required

34
Hi all,

I have an assignment due next week. I don't realy know simple two way association which this program requires. Here is the requirement.


This exercise is about simple two-way associations. An example of a simple two-way association is the ownership relation between a Person and a Car. To ensure consistency, the following three rules should be obeyed.
Each car is owned by exactly one person, that is, no car is without an owner, and no car is owned by more than one person.
Each Person can own at most one car.
If a person owns a car, that car is owned by that person, and vice versa.


It is common for simple two-way associations that one side X must be associated to the other side Y, while Y might be associated to an X.

Write the two classes Person and Car, such that each has a public (declaring it private will make the exercise much harder) reference field that can refer to one of the other kind, that is, class Person as a field Car car, and class Car has a field Person owner. Hint. Use the constructor of Car to make sure that a car is never created without a owner, this should take care of rule 1 & 2 above.
Add a method void newOwner(Person p) to the car class. It should make p the new owner of this car. Make sure rule 1, 2 & 3 are respected by the method. You may assume that the person p is not the owner of an other car.


I have no clue how to implement this. Could you guys give me some Idea how to design these two classes according to the requirements.

I appreciate your help.

Looking forward to your reply.

Koonda
Mar 20 '07 #1
6 1237
sicarie
4,677 Expert Mod 4TB
Hi all,

I have an assignment due next week. I don't realy know simple two way association which this program requires. Here is the requirement.


This exercise is about simple two-way associations. An example of a simple two-way association is the ownership relation between a Person and a Car. To ensure consistency, the following three rules should be obeyed.
Each car is owned by exactly one person, that is, no car is without an owner, and no car is owned by more than one person.
Each Person can own at most one car.
If a person owns a car, that car is owned by that person, and vice versa.


It is common for simple two-way associations that one side X must be associated to the other side Y, while Y might be associated to an X.

Write the two classes Person and Car, such that each has a public (declaring it private will make the exercise much harder) reference field that can refer to one of the other kind, that is, class Person as a field Car car, and class Car has a field Person owner. Hint. Use the constructor of Car to make sure that a car is never created without a owner, this should take care of rule 1 & 2 above.
Add a method void newOwner(Person p) to the car class. It should make p the new owner of this car. Make sure rule 1, 2 & 3 are respected by the method. You may assume that the person p is not the owner of an other car.


I have no clue how to implement this. Could you guys give me some Idea how to design these two classes according to the requirements.

I appreciate your help.

Looking forward to your reply.

Koonda
I would recommend designing a UML representation of the two classes. That will give you a good base and reference guide before you sit down and program them.
Mar 20 '07 #2
r035198x
13,262 8TB
Hi all,

I have an assignment due next week. I don't realy know simple two way association which this program requires. Here is the requirement.


This exercise is about simple two-way associations. An example of a simple two-way association is the ownership relation between a Person and a Car. To ensure consistency, the following three rules should be obeyed.
Each car is owned by exactly one person, that is, no car is without an owner, and no car is owned by more than one person.
Each Person can own at most one car.
If a person owns a car, that car is owned by that person, and vice versa.


It is common for simple two-way associations that one side X must be associated to the other side Y, while Y might be associated to an X.

Write the two classes Person and Car, such that each has a public (declaring it private will make the exercise much harder) reference field that can refer to one of the other kind, that is, class Person as a field Car car, and class Car has a field Person owner. Hint. Use the constructor of Car to make sure that a car is never created without a owner, this should take care of rule 1 & 2 above.
Add a method void newOwner(Person p) to the car class. It should make p the new owner of this car. Make sure rule 1, 2 & 3 are respected by the method. You may assume that the person p is not the owner of an other car.


I have no clue how to implement this. Could you guys give me some Idea how to design these two classes according to the requirements.

I appreciate your help.

Looking forward to your reply.

Koonda
But you haven't done anything yet. What do you think should be done? The rules here require you to have done some work for you to get any help on your assignment.
Mar 21 '07 #3
koonda
34
Here is the code but I don't know how to implement it further.

public class Person
{

public Car car;

//constructor

public Person()
{

}

} //end class


public class Car
{
piblic Person owner;

//constructor

public Car()
{

owner = new Person()
}

public void newOwner(Person p)
{

p = owner;

}

} //end car

}


I don't know how to implement it further. Looking forward to your reply
Mar 21 '07 #4
r035198x
13,262 8TB
Here is the code but I don't know how to implement it further.

public class Person
{

public Car car;

//constructor

public Person()
{

}

} //end class


public class Car
{
piblic Person owner;

//constructor

public Car()
{

owner = new Person()
}

public void newOwner(Person p)
{

p = owner;

}

} //end car

}


I don't know how to implement it further. Looking forward to your reply
If you didn't understand the assignment well, maybe you should go back to your teacher and ask about it more.
Mar 21 '07 #5
koonda
34
Thanks a lot anyways, It is working a little bit and I will try to Implement it soon.

I still have some question on some other Java Assignments and I hope you will be able to help me.

Thanks a lot.

Koonda
Mar 21 '07 #6
r035198x
13,262 8TB
Thanks a lot anyways, It is working a little bit and I will try to Implement it soon.

I still have some question on some other Java Assignments and I hope you will be able to help me.

Thanks a lot.

Koonda
We are willing to help with assignments if you are willing to do most of the work yourself. If you don't know how to begin, then we simply refer you back to the teacher.
Mar 22 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: deepagulati | last post by:
Hi, I need an urgent help from you. When we dynamically genrate any list box (Select Box) it shows one default value as selected. Is there any way that we can deselect that value. I...
1
by: SpiderSwamy | last post by:
Hi, I know little bit about asp, I am facing a problem in Validating the ASP Form.. Example: Stud ID: 501242016 FirstName: Ajit LastName: Kar
1
by: optionsindia | last post by:
hi, we are having urgent requirement for one of our client cmmi level5 company in hyd and chennai. if u r intrested send me ur updated resume gangadhar.sadhu@optionsindia.com Skill Microsoft...
3
by: optionsindia | last post by:
hi partners, we are having a urgent requirement for java architect with our clients located at chennai,hyderabad and bangalore if u r intrested send u r updated resume mail to:...
5
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
2
by: samsalmanu | last post by:
I'm trying to ftp from a Unix machine to a Windows machine.. I've tried the following #!/bin/sh #set -x USER="user1" PASS="pass1" HOSTNAME="host1"
77
by: Hans Schneider | last post by:
1. in the prg bellow what vars are stored on stack, heap, data segment? int i; void main() { int j; int *k = (void *)malloc(1); }
0
by: Chandu | last post by:
Urgent Openings for SE/SSE/TL in .Net for Bangalor Dear , Greetings from Job Cookies India Pvt Ltd., We have Urgent Openings for SE/SSE/TL in .Net for Bangalore Skills Required: 4+Yeard...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.