Software Engineering 1 EEL5881 Spring 2009 Homework - 2 Submitted by Meenakshi Lakshmikanthan 04/01/2009
PROBLEM STATEMENT: Implement the classes as shown in the following diagram. You can use any programming language which supports object oriented programming such as Java/C++ for implementation. This is similar to the ticket reservation system described in Homework#1 (you could refer to it if needed) You need to provide an implementation of all the classes. o Every class should have a constructor. o In the constructor function of each class, you need to initialize the private attributes. o Create two different' Customer' objects within a 'Ticket System' where each customer looks for a different band performing. o Seat Assignment is carried out in the SeatAssignment class which finds the band, displays the seating chart and assigns seats. You may need to provide additional functions to carry out necessary operations or provide most functionality within the declared functions. o Once seats are assigned and selected, the checkout process should be initiated. The Ticket System is the primary controlling point of the system. The main objects need to be instantiated here.
SOLUTION The class diagram in the problem is implemented using a console application in C#.Net Following are the classes in the implementation 1. TicketReservationSystem instantiates the Ticket System 2. TicketSystem - instantiates all the main objects of the system 3. SeatingAssingment Composition with TicketSystem. 4. Customer 5. Administrator 6. Billing The implementation of the classes is as follows:
TicketReservationSystem.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the Initiator class of the Console Application which will instantiate the Ticket System public class TicketReservationSystem public static void Main(string[] args) //Instantiates the TicketSystem Class. TicketSystem t = new TicketSystem(); //prints the output of the Ticket System seat assignments to different customers Console.WriteLine(t.SearchBand());
TicketSystem.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the main class of the System, this class instantiates all the main objects of the system public class TicketSystem #region "Variables" private SeatAssignment mseatassignment; private Customer customer1; private Customer customer2; #region "Constructors" public TicketSystem() //Seating Assignment is instantiated and it is passed to every other class in the system. //Thus Ticket System is composed of Seating Assignment mseatassignment = new SeatAssignment(); //Instantiates Administrator and adds a new seat. Administrator admin = new Administrator(ref mseatassignment); admin.updatesystem("10"); //instantiates two new customers customer1 = new Customer("Meenakshi", "4000 Central Florida Blvd, Orlando, FL - 32817", 1234567890); customer2 = new Customer("Aarthi", "123 ABC Avenue, Oveido, FL - 32765", 1232) ; #region "Destructor" ~TicketSystem() //Seating Assignment is destroyed. Seating Assignment cannot exist without ticket system mseatassignment = null; #region "Methods" /// This method searches the seats for each customer for its specified band /// and shows the seating chart and lets the customer accept the seat and /// initiates the checkout process for each customer for the selected seat /// <returns></returns> public string SearchBand() //Customer 1 //search the band for available seats for band "ABC" and assign a seat string seat1 = customer1.searchband(ref mseatassignment,"abc");
TicketSystem.cs //display the seating chart customer1.getseatingchart(ref mseatassignment); 2 //customer accepts the seat customer1.acceptseats(ref mseatassignment, seat1); //initiate the billing and checkout process Billing bill1 = new Billing(customer1); bill1.checkoutprocess(); //Customer 2 //search the band for available seats for band "DEF" and assign a seat string seat2 = customer2.searchband(ref mseatassignment,"def"); //display the seating chart customer1.getseatingchart(ref mseatassignment); //customer accepts the seat customer2.acceptseats(ref mseatassignment, seat2); //initiate the billing and checkout process Billing bill2 = new Billing(customer2); bill2.checkoutprocess(); //returns the seats assigned for each customer return "customer 1 is assigned seat " + seat1 + " for band \"ABC\" and Customer 2 is assigned seat " + seat2 + " for band \"DEF\".";
SeatAssignment.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the seat assignment class, that holds the seats that can be searched for /// each band and assigned to each customer public class SeatAssignment #region "Variables" private string[] seatdetails; private System.Random RandNum; #region "Properties" public string[] SeatDetails get return seatdetails; set seatdetails = value; #region "Constructors" public SeatAssignment() seatdetails = new string[] "1", "2", "3", "4" ; RandNum = new System.Random(); public SeatAssignment(string[] pseatdetails) seatdetails = pseatdetails; RandNum = new System.Random(); #region "Methods" /// finds the available seats and assigns a seat randomly to the customer /// <param name="bandname">name of the band</param> /// <returns>seat Detail</returns> public string FindAvailableSeats(string bandname) int MyRandomNumber = RandNum.Next(0, seatdetails.length - 1); return seatdetails[myrandomnumber]; /// Returns the seating chart /// <returns></returns> public string DisplaySeatingChart()
SeatAssignment.cs string seatingchart=""; for (int i = 0; i < seatdetails.length; i++) seatingchart += seatdetails[i] + ","; seatingchart = seatingchart.trimend(','); return "Seating Chart: " + seatingchart; 2 ///Assigns the seat to the customer for that band and removes it from the availability /// for other customers for that band /// <param name="seatdetails">seat Details</param> /// <returns>assigned Seat</returns> public string AssignSeats(string SeatDetails) return "Seat Assigned: " + seatdetails; /// Adminsitrator Adds new seats to the seat assignment /// <param name="seat">new seat</param> public void UpdateSeats(string Seat) string[] newseats = new string[seatdetails.length + 1]; for (int i = 0; i < seatdetails.length; i++) newseats[i] = seatdetails[i]; newseats[newseats.length - 1] = Seat; seatdetails = newseats;
Customer.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the customer class who searches for seats for a band and buys the ticket public class Customer #region "Variables" private string name; private string address; private int CardNum; #region "Properies" public string Name get return name; set name = value; public string Address get return address; set address = value; public int CardNumber get return CardNum; set CardNum = value; #region "Constructors" public Customer() name = ""; address = ""; CardNum = 0; public Customer(string pname, string paddress, int pcardnumber) name = pname; address = paddress; CardNum = pcardnumber; #region "Methods" /// Searches for a band /// <param name="seatassignment">reference to the SeatAssignment in the TicketSystem</param> /// <param name="bandname">name of the band</param> /// <returns>gets the seat detail from seat assignment</returns> public string searchband(ref SeatAssignment seatassignment, string bandname) return seatassignment.findavailableseats(bandname);
Customer.cs 2 /// Gets the seating chart from the seat asssignment of the Ticket System /// <param name="seatassignment">reference to the SeatAssignment in the TicketSystem</param> public void GetSeatingChart(ref SeatAssignment seatassignment) seatassignment.displayseatingchart(); /// Accepts and reserves the seat /// <param name="seatassignment">reference to the SeatAssignment in the TicketSystem</param> /// <param name="seatdetails">assigned Seat</param> public void AcceptSeats(ref SeatAssignment seatassignment, string SeatDetails) seatassignment.assignseats(seatdetails);
Billing.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the Billing class that initiates the checkout process public class Billing #region "Variables" private Customer customer; #region "Constructors" public Billing() customer = new Customer(); public Billing(Customer pcustomer) customer = pcustomer; /// check out the ticket for the given customer public void CheckoutProcess() verifycard(); /// Does some validatiion of the credit card and returns the result /// <returns>credit Card Validation result</returns> private bool verifycard() if (customer.cardnumber!= 0) return true; else return false;
Administrator.cs using System; using System.Collections.Generic; using System.Text; 1 namespace TicketReservationSystem /// This is the administrator class /// who adds new seats to the seating assinment of the Ticket System public class Administrator //Seat Assignment of the TicketSystem private SeatAssignment seating; #region "Constructors" public Administrator(ref SeatAssignment seat) seating = seat; /// Adds new seat to the seating Assignment /// <param name="seat">seat Details for the new seat</param> public void UpdateSystem(string seat) seating.updateseats(seat);
PROGRAM OUTPUT