Question: Can someone fix my code? I honestly don't know what's wrong with it. C# and please answer with the modified code. using System; namespace TicketAssignment
Can someone fix my code? I honestly don't know what's wrong with it. C# and please answer with the modified code.
using System;
namespace TicketAssignment { public abstract class Ticket { private int ticketNumber; private static int nextTicketNumber = 1;
public Ticket() { ticketNumber = nextTicketNumber++; } public Ticket(int t) { ticketNumber = t; }
internal abstract int Price { get; }
internal virtual int TicketNumber { get { return ticketNumber; } } internal virtual int NextTicketNumber { get { return nextTicketNumber; } }
public override string ToString() { return "Ticket Number: " + ticketNumber; } } }
using System; using System.Collections.Generic; using System.Text;
namespace TicketAssignment { public class PurchaseTicket { public static void Main(string[] args) { Scanner scnr = new Scanner(System.in);
List
while (input != 5) { displayMenu(); input = scnr.Next();
switch (input) { case 1: Console.WriteLine("How many days until the game?"); temp = new AdvanceBooking(scnr.Next()); tickets.Add(temp); Console.WriteLine(temp); break; case 2: temp = new CurrentBooking(); tickets.Add(temp); Console.WriteLine(temp); break; case 3: Console.WriteLine("How many days until the game? [0 for today]"); temp = new DiscountBooking(scnr.Next()); tickets.Add(temp); Console.WriteLine(temp); break; case 4: Console.WriteLine("Here are all the tickets you sold:"); foreach (Ticket t in tickets) { Console.Write(t); } break; case 5: break; default: Console.WriteLine("Invalid Choice"); break; } }
scnr.close(); }
internal static void displayMenu() { Console.WriteLine("Choose from the following:"); Console.WriteLine("1. Sell a Ticket for a future game"); Console.WriteLine("2. Sell a Ticket for today's game"); Console.WriteLine("3. Sell a Discount Ticket"); Console.WriteLine("4. Print All Tickets"); Console.WriteLine("5. Exit"); } } }
using System; using System.Collections.Generic; using System.Text;
namespace TicketAssignment { public class DiscountBooking : Ticket { private int numDaysUntilGame, ticketPrice;
public DiscountBooking() : base() { numDaysUntilGame = 0; } public DiscountBooking(int n) : base() { numDaysUntilGame = n; if (numDaysUntilGame > 0) { ticketPrice = 10; } else { ticketPrice = 75; } }
internal virtual int Price { get { return ticketPrice; } set { ticketPrice = value; } } internal virtual int NumDaysUntilGame { get { return numDaysUntilGame; } }
internal virtual int DaysUntil { set { numDaysUntilGame = value; } }
public override string ToString() { return "Ticket number " + base.TicketNumber + " with a price of $" + Price + " is a discount ticket for a game in " + numDaysUntilGame + " days. "; } } }
using System; using System.Collections.Generic; using System.Text;
namespace TicketAssignment { public class CurrentBooking : Ticket {
private int ticketPrice;
public CurrentBooking() : base() { ticketPrice = 75; } public CurrentBooking(int p) : base() { ticketPrice = p; } public CurrentBooking(int t, int p) : base(t) { ticketPrice = p; }
internal virtual int Price { get { return ticketPrice; } set { ticketPrice = value; } }
public override string ToString() { return "You sold: Ticket number " + base.TicketNumber + " with a price of $" + Price + " for today's game. "; } } }
using System; using System.Collections.Generic; using System.Text;
namespace TicketAssignment { public class AdvanceBooking : Ticket { private int numDaysUntilGame, ticketPrice;
public AdvanceBooking() : base() { numDaysUntilGame = 0; ticketPrice = 0; } public AdvanceBooking(int n) : base() { numDaysUntilGame = n; if (numDaysUntilGame > 15) { ticketPrice = 25; } else { ticketPrice = 50; } }
internal virtual int Price { get { return ticketPrice; } set { ticketPrice = value; } } internal virtual int NumDaysUntilGame { get { return numDaysUntilGame; } }
internal virtual int DaysUntil { set { numDaysUntilGame = value; } }
public override string ToString() { return "You sold: Ticket number " + base.TicketNumber + " with a price of $" + Price + " for a game in " + numDaysUntilGame + " days. "; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
