Hey everyone and happy new year.

I'm a java beginner and I am doing my first program, a dvd rental system. I've got 4 classes with the following variables:

the main class
the dvd class - dvdID, title, rating, producer
the cleint class - cleintID, name, surname, address
the rentals class - clientID, dvd1, dvd2, dvd3

I need to know how to link the clientIDs. I am using arraylist.

Recommended Answers

All 4 Replies

That looks like a mistake - the Rentals (Java classes conventionally begin with an upper case letter) class should have an instance of Client, not just a clientID (ie like the 3 DVD members).

I understand the part were I need to create a instance of the client class but what I don't know is how to create a relationship using the clientID.

Forget about relational stuff. This is Object Oriented. You don't create a relationship using IDs, you have variables that contain direct to the objects themselves. Don't worry if this doesn't quite compute yet - it's a concept that sometimes takes a little time to grok, especially if you've just come from doing relational databases.
You get an instance of Client somehow, you get an instance of DVD somehow. You create an instance of Rental that has the Client and the DVD as its instance variables. The ID's play no part in that.

Forget about relational stuff. This is Object Oriented. You don't create a relationship using IDs, you have variables that contain direct to the objects themselves. Don't worry if this doesn't quite compute yet - it's a concept that sometimes takes a little time to grok, especially if you've just come from doing relational databases.
You get an instance of Client somehow, you get an instance of DVD somehow. You create an instance of Rental that has the Client and the DVD as its instance variables. The ID's play no part in that.

Thanks alot. It helped me get to the solution I was seeing the problem form a different point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.