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
1 TicketReservationSystem.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the Initiator class of the Console Application which will instantiate the Ticket System
/// </summary>
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());
}
1 TicketSystem.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the main class of the System, this class instantiates all the main objects of the system
/// </summary>
public class TicketSystem
{
#region "Variables"
private SeatAssignment mSeatAssignment; private Customer customer1;
private Customer customer2;
#endregion
#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) ; } #endregion #region "Destructor" ~TicketSystem() {
//Seating Assignment is destroyed. Seating Assignment cannot exist without ticket system mSeatAssignment = null; } #endregion #region "Methods" /// <summary>
/// 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
/// </summary>
/// <returns></returns>
public string SearchBand() {
//Customer 1
//search the band for available seats for band "ABC" and assign a seat
2 TicketSystem.cs
//display the seating chart
customer1.GetSeatingChart(ref mSeatAssignment);
//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\".";
}
#endregion
1 SeatAssignment.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the seat assignment class, that holds the seats that can be searched for
/// each band and assigned to each customer
/// </summary>
public class SeatAssignment
{
#region "Variables"
private string[] seatDetails; private System.Random RandNum;
#endregion
#region "Properties"
public string[] SeatDetails {
get { return seatDetails; } set { seatDetails = value; } }
#endregion
#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(); }
#endregion
#region "Methods"
/// <summary>
/// finds the available seats and assigns a seat randomly to the customer
/// </summary>
/// <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]; }
/// <summary>
/// Returns the seating chart
/// </summary>
/// <returns></returns>
2 SeatAssignment.cs
{
string seatingchart="";
for (int i = 0; i < seatDetails.Length; i++) {
seatingchart += seatDetails[i] + ","; }
seatingchart = seatingchart.TrimEnd(','); return "Seating Chart: " + seatingchart; }
/// <summary>
///Assigns the seat to the customer for that band and removes it from the availability
/// for other customers for that band
/// </summary>
/// <param name="SeatDetails">Seat Details</param>
/// <returns>Assigned Seat</returns>
public string AssignSeats(string SeatDetails) {
return "Seat Assigned: " + seatDetails; }
/// <summary>
/// Adminsitrator Adds new seats to the seat assignment
/// </summary>
/// <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; } #endregion
1 Customer.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the customer class who searches for seats for a band and buys the ticket
/// </summary>
public class Customer {
#region "Variables"
private string name; private string address; private int CardNum;
#endregion
#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; } } #endregion #region "Constructors" public Customer() { name = ""; address = ""; CardNum = 0; }
public Customer(string pName, string pAddress, int pCardNumber) { name = pName; address = pAddress; CardNum = pCardNumber; } #endregion #region "Methods" /// <summary>
/// Searches for a band
/// </summary>
/// <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);
2 Customer.cs
/// <summary>
/// Gets the seating chart from the seat asssignment of the Ticket System
/// </summary>
/// <param name="seatAssignment">Reference to the SeatAssignment in the TicketSystem</param>
public void GetSeatingChart(ref SeatAssignment seatAssignment) { seatAssignment.DisplaySeatingChart();
}
/// <summary>
/// Accepts and reserves the seat
/// </summary>
/// <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);
}
#endregion
1 Billing.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the Billing class that initiates the checkout process
/// </summary>
public class Billing
{
#region "Variables"
private Customer customer;
#endregion
#region "Constructors"
public Billing() {
customer = new Customer(); }
public Billing(Customer pCustomer) {
customer = pCustomer; }
#endregion
/// <summary>
/// check out the ticket for the given customer
/// </summary>
public void CheckoutProcess() {
verifyCard(); }
/// <summary>
/// Does some validatiion of the credit card and returns the result
/// </summary>
/// <returns>Credit Card Validation result</returns>
private bool verifyCard() { if (customer.CardNumber != 0) return true; else return false; } } }
1 Administrator.cs using System; using System.Collections.Generic; using System.Text; namespace TicketReservationSystem { /// <summary>
/// This is the administrator class
/// who adds new seats to the seating assinment of the Ticket System
/// </summary>
public class Administrator
{
//Seat Assignment of the TicketSystem
private SeatAssignment seating;
#region "Constructors"
public Administrator(ref SeatAssignment seat) {
seating = seat; }
#endregion
/// <summary>
/// Adds new seat to the seating Assignment
/// </summary>
/// <param name="seat">Seat Details for the new seat</param>
public void UpdateSystem(string seat) {
seating.UpdateSeats(seat); }