By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Class relationship question

100+
P: 122
Hello Everyone.
This is my 2nd to last project and I need this one in order to do the last project which will be inheritance. Anyway...
I have a project in which we need to create an application that will manage ticket sales to various events. This application need to track ticket sales and event and print the sorces as well.
We need to decide on the class relationship.
This is where I need help in:
1. I'm using two arraylist to hold on the event and the other one for the buyer info. is this a good ideal?
2. is my extends set right or should it be for the buyerTracker (class)


Here is part of my code...

Expand|Select|Wrap|Line Numbers
  1. class EventClass extends buyerTracker {
  2. private String evetid;
  3.  
  4. private String evetname;
  5.  
  6. private String evetdate;
  7.  
  8. private String eventime;
  9.  
  10. private String seatlayout;
  11.  
  12. private double price;
  13.  
  14. public EventClass(String id) {
  15. evetid = id;
  16. }
  17.  
  18. public EventClass(String id, String en, String ed, String vt, String sl,
  19. double pr) {
  20. this.evetid = id;
  21. this.evetname = en;
  22. this.evetdate = ed;
  23. this.eventime = vt;
  24. this.seatlayout = sl;
  25. this.price = pr;
  26.  
  27. }
  28.  
  29. // accessors
  30. public String getEventID() {
  31. return evetid;
  32. }
  33.  
  34. public String getEventname() {
  35. return evetname;
  36. }
  37.  
  38. public String getEventdate() {
  39. return evetdate;
  40. }
  41.  
  42. public String getEventime() {
  43. return eventime;
  44. }
  45.  
  46. public String getSeatlayout() {
  47. return seatlayout;
  48. }
  49.  
  50. public double getPrice() {
  51. return price;
  52. }
  53.  
  54.  
  55. /*
  56. * Mutator Methods
  57. */
  58.  
  59. public void setEventID(String id) {
  60. evetid = id;
  61. }
  62.  
  63. public void setEventname(String en) {
  64. evetname = en;
  65. }
  66.  
  67. public void setevtdate(String ed) {
  68. evetdate = ed;
  69. }
  70.  
  71. public void setEventime(String vt) {
  72. eventime = vt;
  73. }
  74.  
  75. public void setSeatlayout(String sl) {
  76. seatlayout = sl;
  77. }
  78.  
  79. public void setPrice(Double pr) {
  80. price = pr;
  81. }
  82.  
  83.  
  84. public String toString() {
  85. return "(" + evetid + "," + evetname + "," + evetdate + "," + eventime + "," + seatlayout + "," + price + ")";
  86.  
  87. }
  88. }
  89.  
  90. // /////////////////////////Class buyerTracker ///////////////////////////
  91. class buyerTracker {
  92. private String buyername;
  93.  
  94. private String buyeraddr;
  95.  
  96. private String seatnumber;
  97.  
  98. public buyerTracker() {
  99.  
  100. }
  101.  
  102. public buyerTracker(String bn, String ba, String sn, String vt, String sl, double pr, String bn2, String ba2, String sn2) {
  103. this.buyername = bn;
  104. this.buyeraddr = ba;
  105. this.seatnumber = sn;
  106. }
  107.  
  108. // accessors
  109. public String getBuyname() {
  110. return buyername;
  111. }
  112.  
  113. public String getBuyeraddr() {
  114. return buyeraddr;
  115. }
  116. public String getSeatnumber() {
  117. return seatnumber;
  118. }
  119.  
  120. public void setBuyername(String bn) {
  121. buyername = bn;
  122. }
  123.  
  124. public void setBuyerAddr(String ba) {
  125. buyeraddr = ba;
  126. }
  127.  
  128. public void setSeatnumber(String sn) {
  129. seatnumber = sn;
  130. }
  131.  
  132. public String toString() {
  133. return "(" + buyername + "," + buyeraddr + "," + seatnumber + ")";
  134. }
  135. }
  136. public class TicketSales {
  137. static ArrayList<EventClass> arlist;
  138. static Scanner kbd;
  139.  
  140. public static EventClass makeEvent() {
  141. EventClass temp = null;
  142. // prompt for data
  143.  
  144.  
  145. // make an object
  146.  
  147.  
  148. return temp;
  149. }
  150.  
  151. public static buyerTracker makeBuyer() {
  152. buyerTracker temp = null;
  153.  
  154. // prompt for data
  155.  
  156.  
  157. // make an object
  158.  
  159.  
  160.  
  161. return temp;
  162. }
  163.  
  164.  
  165. public static void main(String[] args) {
  166. // make array list object
  167. List < EventClass > arlist = new ArrayList < EventClass > ();
  168. arlist.add(new EventClass("CL123", "Concert", "May/12/2007", "12:00pm", "3500 Seats", 55.00));
  169. arlist.add(new EventClass("PL123", "Play", "May/14/2007", "2:00pm", "2000 Seats", 75.00));;
  170. arlist.add(new EventClass("DL123", "Dinner", "May/29/2007", "7:00pm", "1500 Seats", 100.00));
  171. System.out.println(arlist);
  172.  
  173. List < EventClass > buyer = new ArrayList < EventClass > ();//is this needed
  174.  
  175. System.out.println(buyer);
  176.  
Any help would be great
Thanks
red
May 15 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
Before you start banging your keyboard for code think of the three major classes
in your scenario:

1) an event has tickets for sale;
2) a ticket belongs to an event and possibly a buyer;
3) a buyer has tickets.

An event tracker just tracks buyers and events; obviously a buyer had bought
a ticket for the event otherwise s/he's not a buyer for that event,

So an event *has* zero or more tickets. A buyer *has* zero or more tickets and
an event tracker *has* zero or more ticket transfers. I don't see any inheritance
in here; just a possible fourth Transfer class that refers to a buyer and a ticket.

kind regards,

Jos
May 15 '07 #2

100+
P: 122
Before you start banging your keyboard for code think of the three major classes
in your scenario:

1) an event has tickets for sale;
2) a ticket belongs to an event and possibly a buyer;
3) a buyer has tickets.

An event tracker just tracks buyers and events; obviously a buyer had bought
a ticket for the event otherwise s/he's not a buyer for that event,

So an event *has* zero or more tickets. A buyer *has* zero or more tickets and
an event tracker *has* zero or more ticket transfers. I don't see any inheritance
in here; just a possible fourth Transfer class that refers to a buyer and a ticket.

kind regards,

Jos
Thanks Jos that makes sense...
If I could I would give you a couple of Duke stars...

sandy
May 15 '07 #3

Post your reply

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