473,503 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two Class but not using extends...

nomad
664 Recognized Expert Contributor
Hello everyone:
I have one last project that is due today and I have a question. Class assignment the Airliner...
In this project that I'm working on it has several class in which each class has some data type it needs to use. It also need to two programs one to capture the required info. the other will create the user interface and db connections

I think I need at least three class.
Ticket
Buyer
The third one to conatin the main() to do the testing.

Question is I don't think I can use extends from what I have being read. So the question is how do I get the info from TicketClass to the BuyerClass.
The BuyerClass need info from the TicketClass in order to process a ticket and print out the in.

any help would be great.

nomad
May 17 '07 #1
8 1286
JosAH
11,448 Recognized Expert MVP
Ticket and Buyer would be fine classes but you need a 'TicketDispenser' that
can give a Ticket (sold out is sold out so no ticket then). If you follow that little
scenario, a Ticket is being instantiated given a Buyer. A ticket is associated
with a Buyer and the Buyer should be updated (he bought another ticket again).
Think 'physical' here: there are a number of tickets, the dispenser sells them to
a Buyer in which case the Buyer has (another?) ticket again and the dispenser
has one ticket less (because he sold it).

A Dispenser could be anything: an Airline company a Theatre etc. etc. All it
has to know how many tickets it has (and possibly the price for different type
of tickets, but that's just an 'implementation detail').

kind regards,

Jos
May 17 '07 #2
nomad
664 Recognized Expert Contributor
Ticket and Buyer would be fine classes but you need a 'TicketDispenser' that
can give a Ticket (sold out is sold out so no ticket then). If you follow that little
scenario, a Ticket is being instantiated given a Buyer. A ticket is associated
with a Buyer and the Buyer should be updated (he bought another ticket again).
Think 'physical' here: there are a number of tickets, the dispenser sells them to
a Buyer in which case the Buyer has (another?) ticket again and the dispenser
has one ticket less (because he sold it).

A Dispenser could be anything: an Airline company a Theatre etc. etc. All it
has to know how many tickets it has (and possibly the price for different type
of tickets, but that's just an 'implementation detail').

kind regards,

Jos
I understand that part..


So is this right?
TicketDispenerClass hold the information from ticket and buyer and return info
TicketClass - ticket information
BuyerClass --name and address plus info from TicketClass

But I don't get the data type to talk to each other from one class to the other class.
That where I'm stuck at.

Nomad
If I fig this out I just might write another article on this one.
May 17 '07 #3
JosAH
11,448 Recognized Expert MVP
Maybe the TicketDispenser keeps a lists of Tickets sold to Buyers? IOW the
TicketDispenser knows all? And maybe a TransAction object should be added:
Expand|Select|Wrap|Line Numbers
  1. public class TransAction {
  2.    private Ticket ticket;
  3.    private Buyer buyer;
  4.    public Transaction(Ticket ticket, Buyer buyer) {
  5.       this.ticket= ticket;
  6.       this.buyer= buyer;
  7.    }
  8.    public Ticket getTicket() { return ticket; }
  9.    public Buyer getBuyer() { return buyer; }
  10. }
kind regards,

Jos
May 17 '07 #4
nomad
664 Recognized Expert Contributor
Maybe the TicketDispenser keeps a lists of Tickets sold to Buyers? IOW the
TicketDispenser knows all? And maybe a TransAction object should be added:
Expand|Select|Wrap|Line Numbers
  1. public class TransAction {
  2.    private Ticket ticket;
  3.    private Buyer buyer;
  4.    public Transaction(Ticket ticket, Buyer buyer) {
  5.       this.ticket= ticket;
  6.       this.buyer= buyer;
  7.    }
  8.    public Ticket getTicket() { return ticket; }
  9.    public Buyer getBuyer() { return buyer; }
  10. }
kind regards,

Jos
Thanks Jos..
There was example from the Instructor on this..
But his example did not work 100 percent so I could not figure it out.
thanks
nomad
Howfull I can not finish this project.
May 17 '07 #5
nomad
664 Recognized Expert Contributor
Maybe the TicketDispenser keeps a lists of Tickets sold to Buyers? IOW the
TicketDispenser knows all? And maybe a TransAction object should be added:
Expand|Select|Wrap|Line Numbers
  1. public class TransAction {
  2.    private Ticket ticket;
  3.    private Buyer buyer;
  4.    public Transaction(Ticket ticket, Buyer buyer) {
  5.       this.ticket= ticket;
  6.       this.buyer= buyer;
  7.    }
  8.    public Ticket getTicket() { return ticket; }
  9.    public Buyer getBuyer() { return buyer; }
  10. }
kind regards,

Jos
One last question...RIGHTTT
Not to sure about this one. Should I use One arraylist or two.
Question you will ask why two.
1. to hold the ticket info.
the other two hold the buyer info.

or just want to hold everything.

nomad
May 17 '07 #6
JosAH
11,448 Recognized Expert MVP
One last question...RIGHTTT
Not to sure about this one. Should I use One arraylist or two.
Question you will ask why two.
1. to hold the ticket info.
the other two hold the buyer info.

or just want to hold everything.

nomad
The Transaction class (see above) would be ideal for that. The TIcketDispenser
should just hold one list of Transactions. A single Transaction tells you who
(which Buyer) bought what (Ticket). Never be afraid to create a new class if you
think that thing represents an entitiy/class and never ever use two arrays or
lists that both carry parts of another entity; build a new class instead.

kind regards,

Jos
May 17 '07 #7
nomad
664 Recognized Expert Contributor
OK
I'm very close in solving this project.

but I have two question to ask and I hope you can help me:

1. how do I do this
System.out.println("Event info is " .getTicket().getBuyer());

I know there is value that needs to go before the .getTicket().getBuuer())

2. I have a error in where buyerTracker temp = makeBuyer();
I get this error code The method makeBuyer() is undefined for the type TicketSales


Expand|Select|Wrap|Line Numbers
  1. if (choice == 2) { // if 2 is select go to find
  2.             boolean endData2 = false;
  3.  
  4.             while (!endData2) {
  5.                 buyerTracker temp = makeBuyer();
  6.                 arlist.addAll((Collection<? extends EventClass>) temp);
  7.                 System.out.println("Add More Events (Y/N)-->");
  8.  
  9.                 String ans = kbd.next();
  10.  
  11.                 if (ans.equalsIgnoreCase("N")) {
  12.                     System.out.println(temp);
  13.                     endData2 = true;
  14.                 }
  15.             }// close while loop
  16.         }// close choice 2
Thanks
nomad
May 17 '07 #8
emekadavid
46 New Member
you don't need to use extends at all. you already know what you need. see, every buyer needs a ticket. so, every buyer has a ticket. that's the catch. has a relationship was what you were thinking of or what is called composition in object oriented lingo.

you simply declare a ticket object in the buyer classes and that does the work. composition. beginner programmers from a book by bruce eckel i was reading should think of composition before inheritance even though inheritance seems a much more powerful concept.

lol
May 17 '07 #9

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

Similar topics

1
1794
by: Phil Powell | last post by:
http://www.phpbuilder.com/board/showthread.php?s=b93aeba2a407ce463fee98450a599299&postid=10541092#post10541092 I can't explain it better than to show you my thread Environments: PHP 4.1.2 and...
3
23424
by: Hal Vaughan | last post by:
I'm creating a sequence of JPanels that will each, in turn, be added to (then removed from) a window (kind of like a wizard). I want these panels to not only extend the JPanel class, but to...
2
3752
by: Ovid | last post by:
Hi, I'm trying to determine the cleanest way to override class data in a subclass. class Universe { public String name; private static double PI = 3.1415; Universe(String name) {
2
1439
by: Pierre Rouleau | last post by:
Greetings, I'm wondering why the >> operator does not use the write() method of a class derived from the built-in file class as in DerivedFile below. In the following example: - StringFile...
11
1579
by: Full Decent | last post by:
Hey all! I've been using PHP for a while and I'm hearing that I should look into using it OO. I'm looking into making changes to the program Camera Life (http://fdcl.sf.net). I want to abstract...
5
1984
by: Andy Jeffries | last post by:
OK, assuming the following class structure: class A { public function printConst() { print {something}::TEST_CONST; } } class B extends A {
21
7237
by: Daz | last post by:
Hi everyone. I am trying to create an extension of the mysqli class within PHP, and I am finding it quite difficult. I am fairly new to PHP classes, and decided to give them a go. Here's what I...
61
2901
by: Sanders Kaufman | last post by:
I'm wondering if I'm doing this right, as far as using another class object as a PHP class property. class my_baseclass { var $Database; var $ErrorMessage; var $TableName; var $RecordSet;...
8
1789
by: elmosik | last post by:
Is there any method to get this informations from php file? 1. Class methods 2. Check whether class in file is extended by 'XXX' or not (class MyClass extends XXX ...) - Class has same name...
4
4024
by: JNeko | last post by:
hello all, I have tried my hand at this for a couple hours but no luck. I am using JCreator. I used these two links for reference: http://www.tech-recipes.com/java_programming_tips1265.html...
0
7205
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
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.