Question

In: Computer Science

Write a C# code that creates objects and classes with their member functions for KrisFlyer, a...

Write a C# code that creates objects and classes with their member functions for KrisFlyer,
a Singapore Airlines Loyalty program. You are asked to write an inheritance hierarchy discount
system that benefits KrisFlyer members program to calculate their profit.

A brief about KrisFlyer is that it is useful for those who fly on Singapore Airlines (its
partners like Virgin Australia and Air New Zealand) frequently. KrisFlyer miles can be earned
through credit cards, flying and bonus miles promotions. The miles can be redeemed for award
flights in all categories. It has three types of memberships namely Basic, Elite Silver and Elite
Gold. When registered for the first time, all the customers get instant access to the basic

membership level of KrisFlyer. In 2020, Singapore Airlines offers a flat 10%, 20% and 30%
discount to its Basic, Elite Silver and Elite Gold members respectively for all services provided.
Customers without membership receive no discount. The students have to implement basic OOPs
concepts such as inheritance, polymorphism and encapsulation.
Inheritance
Base class: Create an inheritance hierarchy to represent various types of memberships. Use
KrisFlyer as the base class of the hierarchy, then include derived classes Basic, Elite Silver and
Elite Gold that deriver from KrisFlyer. Base class KrisFlyer should have data members
representing name, membership, flight, price for flight, number of passengers for the members.
The constructor should initialize these data members. Ensure that flight price and number of
passengers contain positive values. KrisFlyer should include a public member function
calculateCost() that returns a double indicating the cost by multiplying the price for flight by the
number of passengers.
Derived class: Basic, Elite Silver and Elite Gold should inherit the functionality of base
class KrisFlyer, but also include a data member that represents a discount that the reward program
has offered recently. All the derived class’s constructor should receive a value to initialize this data
member. In 2020, Singapore Airlines offers a flat 10%, 20% and 30% discount to its Basic, Elite
Silver and Elite Gold members respectively for all services provided. All the derived members
should redefine calculateCost() so that it applies the discount to the booked flights. It shall compute
the total bill if a customer purchases y tickets for a price of $x for each flight for their visit using
Krisflyer.
Your system shall consist of four classes: 1. KrisFlyer (base class), derived classes
including Basic, Elite Silver, Elite Gold.
Polymorphism
Implement a method display() that displays all the records of the system. Another form of
the method display(string cust_name) that displays records related to the customer name passed in
the argument.

Encapsulation
Define the instance variables private/ public so that they cannot/can be accessed from
outside the class. Implement getter and setter method for the variables in the program.
Write a program that implements basic Object-oriented concepts including encapsulation
polymorphism and inheritance. Also, the program is expected to get the basic input from the user
based on either console/Desktop.
The student is expected to do the following tasks:
1. Draw the class diagram of the given scenario
2. Write the c# classes with suggested data members and functions
3. Write the base and derived classes for implementing inheritance in the program.
4. Implement polymorphism and encapsulation to check for accessibility of data members
and different form of the data member
5. Write the main logic that takes input from the user members with their bookings
6. Write the code to display the output as displayed (it is a sample)
Expected output

The given output is a sample. The student is free to use creative ideas to display the output of the
program. It needs to be an interactive session where the user feeds in dynamic information.

Sample

KrisFlyers Reward Discount system

Basic 10%
Elite silver 20%
Elite gold 30%
Hello, Input based on your requirement
1. To input new entry
2. Display a single record:
3. Display all records
4. Exit
1
Enter the name of the customer : XYZ
Enter the membership type : Basic
Enter the price for flight in dollars ($): 1200
Enter the number of passengers : 2
Hello, Input based on your requirement
1. To input new entry
2. Display a single record:
3. Display all records
4. Exit
2
Enter the name of the customer
XYZ
| Name | Price | No | Total | discount | Discounted Price |
| XYZ | $1200 | 2 | $2400 | 10% | $2160 |
Hello, Input based on your requirement
1. To input new entry
2. Display a single record:
3. Display all records
4. Exit
3
| Name | Price | No | Total | discount | Discounted Price |
| XYZ | $1200 | 2 | $2400 | 10% | $2160 |
| ABC | $1000 | 1 | $2000 | 10% | $1800 |

Code related Guidelines
1. Your c# console-based application should include the following:
a. The code should have a consistent, professional and well-organized appearance.
b. Carefully chosen, meaningful identifier names
c. Code is well organized: clear, simple, & DRY (Don't repeat Yourself)
d. Thoughtful comments, where needed, expressed in concise, precise English.
e. Code should compile without errors
2. The developed system takes input and handles the error in friendly manner.
3. Your project must adhere to OOPS concepts with implementation guidelines including
modularity, reusability, extensibility, maintainability and adaptability.

The c# console-based application developed must be submitted in a zip folder on the LMS
in the available link. The zip folder should include:
o A document that consists of introduction, requirements, proposed class diagram
with the attributes, screen shots and output with references.
o The c# project folder
o A readme.txt file, which include your information.

Solutions

Expert Solution

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<KrisFlyer> 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<KrisFlyer>();

}

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));

}

}

}


Related Solutions

I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
Don't use vectors use pointers ,classes & objects, functions and loop etc only C++ PROGRAM Following...
Don't use vectors use pointers ,classes & objects, functions and loop etc only C++ PROGRAM Following is a partial implementation of Set class. You are required to enhance and implement the following missing functions from the implementation: A) UNION B) reset C) intersection D) difference A SAMPLE driver program : int a1[] = {10,5,7,3,9}; Set s1(5); s1.insert(a1,5); s1.print("s1"); int a2[] = {2,9,6}; Set s2(3); s2.insert(a2,3); s2.print("s2"); Set s3 = s1.unionset(s2); Set s4 = s1.intersection(s2); Set s5 = s1.difference(s2); s3.print("s3"); s4.print("s4");...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored in Memory? D. Why do you not need to declare when you are finished using an Object in Java? E. Can you edits the contents of a String? View keyboard shortcuts EditViewInsertFormatToolsTable 12pt Paragraph
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
4.3 Lab: Queues 1 Write the c++ implementation of the following four member functions of the...
4.3 Lab: Queues 1 Write the c++ implementation of the following four member functions of the Queue class: getLength(): returns the number of elements in the queue isEmpty(): returns true if the queue is empty, false otherwise peek(): returns the value at the front of the queue without removing it. Assumes queue is not empty (no need to check) peekRear(): returns the value at the end of the queue without removing it. Assumes queue is not empty (no need to...
Write a Simple C++ Code to show that the Constructors of Composed Classes Execute before Container...
Write a Simple C++ Code to show that the Constructors of Composed Classes Execute before Container Classes.
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects •...
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects • Methods • Arrays of Primitive Values • Arrays of Objects • Recursion • for and if Statements • Insertion Sort 2. Use the following Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for...
Write a program in C++ Write three new functions, mean() and standard_deviation(). Modify your code to...
Write a program in C++ Write three new functions, mean() and standard_deviation(). Modify your code to call these functions instead of the inline code in your main(). In addition, add error checking for the user input. If the user inputs an incorrect value prompt the user to re-enter the number. The flow of the code should look something like: /** Calculate the mean of a vector of floating point numbers **/ float mean(vector& values) /** Calculate the standard deviation from...
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT