Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm getting an error in KrisFlayer Class of this program. The error is '$' unexpected characrter in the Console.WriteLine(string.Format($| {customer.Name} | {customer.Price} | {customer.PassengerNumber} |

I'm getting an error in KrisFlayer Class of this program.

The error is '$' unexpected characrter in the Console.WriteLine(string.Format($"| {customer.Name} | {customer.Price} | {customer.PassengerNumber} | {customer.Name} | {customer.Price * customer.PassengerNumber}| {customer.GetDiscount()} | {customer.CalculateCost()} |")); and if i remove that the program is not really working,

Kindly help me with that. Thanks

Program.cs

using System; namespace Flight { class Program { static void Main(string[] args) { Console.WriteLine(" KrisFlyers Reward Discount System"); Console.WriteLine("Basic 10 %"); Console.WriteLine("Elite silver 20 %"); Console.WriteLine("Elite gold 30 %"); Console.WriteLine("Hello, Input based on your requirement"); Console.WriteLine("1.To input new entry"); Console.WriteLine("2.Display a single record:"); Console.WriteLine("3.Display all records"); Console.WriteLine("4.Exit"); KrisFlyer memberClass = null; var option = Convert.ToInt32(Console.ReadLine()); do { switch (option) { case 1: memberClass = CreateCustomer(); memberClass.CustomerList.Add(memberClass); break; case 2: Console.WriteLine("Enter the name of the customer"); var custName = Console.ReadLine(); if (memberClass == null) { Console.WriteLine("Customer does not exist"); } else { memberClass.display(custName); } break; case 3: if (memberClass == null) { Console.WriteLine("Customers don't not exist"); } else { memberClass.display(); } break; case 4: break; default: break; } Console.WriteLine("Hello, Input based on your requirement"); Console.WriteLine("1.To input new entry"); Console.WriteLine("2.Display a single record:"); Console.WriteLine("3.Display all records"); Console.WriteLine("4.Exit"); option = Convert.ToInt32(Console.ReadLine()); } while (option != 4); } public static KrisFlyer CreateCustomer() { KrisFlyer memberClass = null; Console.Write("Enter the name of the customer : "); var name = Console.ReadLine(); Console.Write("Enter the membership type: "); var membership = Console.ReadLine(); Console.Write("Enter the price for flight in dollars($) : "); var price = Convert.ToInt32(Console.ReadLine()); if (price < 0) { Console.WriteLine("Value should be greater than 0"); Console.WriteLine("Please enter again"); price = Convert.ToInt32(Console.ReadLine()); } Console.Write("Enter the number of passengers : "); var num = Convert.ToInt32(Console.ReadLine()); if (num < 0) { Console.WriteLine("Value should be greater than 0"); Console.WriteLine("Please enter again"); num = Convert.ToInt32(Console.ReadLine()); } switch (membership) { case "Basic": memberClass = new Basic(name, membership, "", price, num, 10); break; case "Elite Silver": memberClass = new EliteSilver(name, membership, "", price, num, 10); break; case "Elite Gold": memberClass = new EliteGold(name, membership, "", price, num, 10); break; } return memberClass; } } }

KrisFlyer.cs

using System; using System.Collections.Generic; namespace Flight { public class KrisFlyer { public string Name { get; set; } public string Membership { get; set; } public string Flight { get; set; } public int Price { get; set; } public int PassengerNumber { get; set; } public List CustomerList; public KrisFlyer(string name, string membership, string flight, int price, int passengerNumber) { Name = name; Membership = membership; Flight = flight; Price = Price; PassengerNumber = passengerNumber; CustomerList = new List(); } public virtual int GetDiscount() { return 0; } public void display() { Console.WriteLine("| Name | Price | No | Total | discount | Discounted Price |"); foreach (var customer in CustomerList) { Console.WriteLine(string.Format($"| {customer.Name} | {customer.Price} | {customer.PassengerNumber} | {customer.Name} | {customer.Price * customer.PassengerNumber}| {customer.GetDiscount()} | {customer.CalculateCost()} |")); } } public void display(string cust_name) { Console.WriteLine("| Name | Price | No | Total | discount | Discounted Price |"); var customer = CustomerList.Find(x => x.Name == cust_name); Console.WriteLine(string.Format($"| {customer.Name} | {customer.Price} | {customer.PassengerNumber} | {customer.Name} | {customer.Price * customer.PassengerNumber}| {customer.GetDiscount()} | {customer.CalculateCost()} |")); } public virtual double CalculateCost() { return Price * PassengerNumber; } } }

Basic.cs

namespace Flight { public class Basic : KrisFlyer { private readonly int _discount; public Basic(string name, string membership, string flight, int price, int passengerNumber, int discountValue ) : base(name, membership, flight, price, passengerNumber) { _discount = discountValue; } public override int GetDiscount() { return _discount; } public override double CalculateCost() { return Price * PassengerNumber *(1- (_discount / 100)); } } }

EliteSilver.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Flight { public class EliteSilver : KrisFlyer { private readonly int _discount; public EliteSilver(string name, string membership, string flight, int price, int passengerNumber, int discountValue) : base(name, membership, flight, price, passengerNumber) { _discount = discountValue; } public override double CalculateCost() { return Price * PassengerNumber * (1 - (_discount / 100)); } } }

EliteGold.cs

using System; using System.Collections.Generic; using System.Linq; namespace Flight { public class EliteGold : KrisFlyer { private readonly int _discount; public EliteGold(string name, string membership, string flight, int price, int passengerNumber, int discountValue) : base(name, membership, flight, price, passengerNumber) { _discount = discountValue; } public override double CalculateCost() { return Price * PassengerNumber * (1 - (_discount / 100)); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

help asp

Answered: 1 week ago