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
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
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.
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: -
public class TransAction {
-
private Ticket ticket;
-
private Buyer buyer;
-
public Transaction(Ticket ticket, Buyer buyer) {
-
this.ticket= ticket;
-
this.buyer= buyer;
-
}
-
public Ticket getTicket() { return ticket; }
-
public Buyer getBuyer() { return buyer; }
-
}
kind regards,
Jos
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: -
public class TransAction {
-
private Ticket ticket;
-
private Buyer buyer;
-
public Transaction(Ticket ticket, Buyer buyer) {
-
this.ticket= ticket;
-
this.buyer= buyer;
-
}
-
public Ticket getTicket() { return ticket; }
-
public Buyer getBuyer() { return buyer; }
-
}
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.
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: -
public class TransAction {
-
private Ticket ticket;
-
private Buyer buyer;
-
public Transaction(Ticket ticket, Buyer buyer) {
-
this.ticket= ticket;
-
this.buyer= buyer;
-
}
-
public Ticket getTicket() { return ticket; }
-
public Buyer getBuyer() { return buyer; }
-
}
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
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
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 - if (choice == 2) { // if 2 is select go to find
-
boolean endData2 = false;
-
-
while (!endData2) {
-
buyerTracker temp = makeBuyer();
-
arlist.addAll((Collection<? extends EventClass>) temp);
-
System.out.println("Add More Events (Y/N)-->");
-
-
String ans = kbd.next();
-
-
if (ans.equalsIgnoreCase("N")) {
-
System.out.println(temp);
-
endData2 = true;
-
}
-
}// close while loop
-
}// close choice 2
Thanks
nomad
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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) {
|
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...
|
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...
| |
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 {
|
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...
|
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;...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |