Skip to content

Instantly share code, notes, and snippets.

@khan-hasan
Created December 14, 2018 16:45
Show Gist options
  • Save khan-hasan/2eec244e8de648cb3c80e2e4e66675fd to your computer and use it in GitHub Desktop.
Save khan-hasan/2eec244e8de648cb3c80e2e4e66675fd to your computer and use it in GitHub Desktop.
/*
Instructions:
Candidates are allowed to complete this problem at home using any computer you prefer.
While the preferred language for solving this problem is C#, if absolutely necessary javascript is also permitted.
If access to a C#/Javascript editor is not available to you, you can use the following
C# online IDE at: https://www.tutorialspoint.com/compile_csharp_online.php
This IDE has a decent text editor, as well as the ability to execute your code in a console application Environment. Unlike the previous test questions, syntax and style will be taken into account for this challenge.
If you have any questions regarding this take home challenge, feel free to email me at
[email protected]
You should have received an invitation to view a google drive folder by now.
Submit all code files related to the solution into this folder and email myself/Forest upon completion.
Sooner is always best, but absolute deadline to submit is 12/14/2018 at 11:59pm.
Questions:
1. Create a public class called Customer that contains the following fields or properties:
· string CustomerName
2. Using classes from questions 1, create a class called Customers that contains a private internal list or array of 5 customer objects with unique names, along with a the following:
Public Methods:
· Add(Customer c) - This method inserts the provided customer object ‘c’ into the internal list/array of customers
· Remove(Customer c) - This method searches the internal list/array of customers and removes it if found
· NextCustomer() - This method returns the first customer object in the internal list/array of customers. If there are no customer in the list, this method returns null.
Public Properties:
· NumberOfCustomersInLine - This read-only property returns an integer value with the count of how many customers are currently in the internal list/array of customers
3. Using classes from questions 1 & 2 along with the provided console application file ‘Program.cs’, write a small application that creates a customer list of 6-10 people and for every customer in the list prompt the user to in the following way:
“Next Customer Please…”
“Hello <customer name goes here>! How are you today?”
“To pay for your items, press ‘ENTER’ key now”
<user hits ENTER key now>
“Thank you, come again!!!”
***After all customers in the list have paid for their items, add the following prior to exiting and wait for user input:
“Press ENTER key to continue…”
*/
using System;
using System.Windows.Input;
namespace Problem1
{
class MainProgram
{
/// <summary>
/// This method simply logs the provided message to the screen
/// </summary>
/// <param name="message"></param>
private static void Log(string message)
{
Console.WriteLine($"{DateTime.Now} - {message}");
}
/// <summary>
/// This method clears any text on the console screen
/// </summary>
private static void ClearScreen()
{
Console.Clear();
}
private static string PromptForEnterKey()
{
return Console.ReadLine();
}
/// <summary>
/// This purpose of the application to create a list of customers and allow user to press ENTER to allow each customer to pay his/her bill, at which time you can log "Thank you, come again!!!" to the screen.
/// Continue looping until all customers have paid and prompt to press ENTER key to exit the application.
/// (We can attempt to verify this code using https://www.tutorialspoint.com/compile_csharp_online.php)
/// Please note: This code execution site does not handle Console.ReadLine() properly and will break user interaction
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
// Remove all Customers from CustomerList
CustomerList.Clear();
// Prompt user / customer until CustomerList is of size 6-10
do
{
// Prompt user to add new Customer to CustomerList
Console.WriteLine("Next Customer Please…");
CustomerList.Add(Customer(Console.ReadLine()));
Console.WriteLine("Hello {CustomerList[CustomerList.Length - 1].CustomerName}! How are you today?");
// Prompt user to press 'ENTER'
do
{
Console.WriteLine("To pay for your items, press 'ENTER' key now");
} while (Console.ReadLine() != Key.Enter);
// Print thank you note to user
Console.WriteLine("Thank you, come again!!!");
} while (CustomerList.Length < 6 && CustomerList.Length < 10);
Console.WriteLine("Press ENTER key to continue…");
}
}
public class Customer
{
string CustomerName;
// Constructor for Customer class
public Customer(string Name)
{
CustomerName = Name;
}
}
class Customers
{
// Read-only public int property that returns number Customers in CustomerList
public int NumberOfCustomersInLine = CustomerList.Length;
// Create new array of Customer objects and assign it 5 new Customer objects
internal Customer[] CustomerList = { new Customer("Bob"),
new Customer("Anne"),
new Customer("Tim"),
new Customer("Mary"),
new Customer("Harold") };
// Adds a new Customer object to CustomerList
public void Add(Customer c)
{
CustomerList.Add(c);
}
// Removes a Customer object with the specified CustomerName from the CustomerList if it exists. Otherwise, returns "Customer does not exist in our system."
public string Remove(Customer c)
{
if (Array.IndexOf(c) == null)
{
return "Customer does not exist in our system.";
}
else
{
CustomerList.Remove(IndexOf(Customer.CustomerName == c.CustomerName));
}
}
// Returns first instance of Customer in CustomerList. Returns null if CustomerList is empty.
public void NextCustomer()
{
if (CustomerList.Length > 0)
{
return CustomerList[0];
}
else
{
return null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment