//ScheduleItem.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 青鸟影院 { [Serializable] /// <summary> /// 放映场次 /// </summary> public class ScheduleItem { public ScheduleItem() { } public ScheduleItem(Movie movie,string time) { this.Movie = movie; this.Time = time; } //电影 public Movie Movie { get; set; } //放映时间 public string Time { get; set; } } }
//Seat.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace 青鸟影院 { [Serializable] /// <summary> /// 座位类 /// </summary> public class Seat { public Seat() { } public Seat(string seatNum,Color color) { this.SeatNum = seatNum; this.Color = color; } //座位号 public string SeatNum { get; set; } //颜色 public Color Color { get; set; } } }
//StudentTicket.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace 青鸟影院 { [Serializable] /// <summary> /// 学生票 /// </summary> public class StudentTicket:Ticket { public StudentTicket() { } public StudentTicket(ScheduleItem scheduleItem,Seat seat,double discount):base(scheduleItem,seat) { this.Discount = discount; this.Price = CalcPrice(); } //折扣 public double Discount { get; set; } /// <summary> /// 计算学生票价格 /// </summary> /// <returns></returns> public override double CalcPrice() { return this.ScheduleItem.Movie.Price * this.Discount /10; } /// <summary> /// 打印学生票 /// </summary> public override void Print() { string path = (this.ScheduleItem.Time + " " + this.Seat.SeatNum).Replace(":", "-") + ".txt"; using (FileStream fs = new FileStream(path, FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.Default)) { sw.WriteLine("*******************************"); sw.WriteLine(" 青鸟影院(学生票) "); sw.WriteLine("-------------------------------"); sw.WriteLine("电影名:" + ScheduleItem.Movie.MovieName); sw.WriteLine("时间:" + this.ScheduleItem.Time); sw.WriteLine("座位号:" + this.Seat.SeatNum); sw.WriteLine("折扣:"+this.Discount); sw.WriteLine("价格:" + this.Price); sw.WriteLine("*******************************"); } } } } }
//Ticket.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace 青鸟影院 { [Serializable] /// <summary> /// 电影票父类 /// </summary> public class Ticket { public Ticket() { } public Ticket(ScheduleItem scheduleItem,Seat seat) { this.ScheduleItem = scheduleItem; this.Seat = seat; this.Price = CalcPrice(); } //价格 public double Price { get; set; } //放映场次 public ScheduleItem ScheduleItem { get; set; } //座位 public Seat Seat { get; set; } /// <summary> /// 计算价格 /// </summary> /// <returns></returns> public virtual double CalcPrice() { return this.ScheduleItem.Movie.Price; } /// <summary> /// 打印电影票 /// </summary> public virtual void Print() { string path = (this.ScheduleItem.Time + " " + this.Seat.SeatNum).Replace(":", "-") + ".txt"; using (FileStream fs = new FileStream(path,FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs,Encoding.Default)) { sw.WriteLine("*******************************"); sw.WriteLine(" 青鸟影院 "); sw.WriteLine("-------------------------------"); sw.WriteLine("电影名:"+ScheduleItem.Movie.MovieName); sw.WriteLine("时间:"+this.ScheduleItem.Time); sw.WriteLine("座位号:"+this.Seat.SeatNum); sw.WriteLine("价格:"+this.Price); sw.WriteLine("*******************************"); } } } } }
//TicketUtil.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 青鸟影院 { /// <summary> /// 创建电影票工具类 /// 使用简单工厂模式创建票 /// </summary> public class TicketUtil { public static Ticket CreateTicket(ScheduleItem item,Seat seat,string customerName,double discount,string type) { Ticket ticket = null; switch (type) { case "normal": ticket = new Ticket(item, seat); break; case "free": ticket = new FreeTicket(customerName, item, seat); break; case "student": ticket = new StudentTicket(item, seat, discount); break; } return ticket; } } }
