Professional Documents
Culture Documents
Dsa Assignment 1 (Code)
Dsa Assignment 1 (Code)
Dsa Assignment 1 (Code)
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services_System
{
class Delivery
{
public string userName;
public string userID;
public string itemCode;
public string itemDesc;
public int itemQuant;
public string itemLocation;
} // class for storing data
class Program
{
static public ArrayList delivery_data = new ArrayList();
if (choice == 4)
{
Console.WriteLine("| THANK YOU FOR USING THIS SYSTEM |");
Console.WriteLine("| \tPLEASE COME AGAIN! |");
break;
}
switch (choice)
{
case 1:
Console.Clear();
parcel_data_menu();
break;
case 2:
Console.Clear();
display_data_menu();
break;
default:
Console.WriteLine("| Sorry, but you've entered the wrong input!");
Console.WriteLine("| Press enter and please try again\n");
Console.ReadKey();
Console.Clear();
break;
}
}
}
if (choice == "E")
{
break;
}
switch (choice)
{
case "A":
Console.Clear();
Console.WriteLine("------------------------PARCEL INFORMATION
MENU---------------------");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| In this menu, the user can add or either remove parcel information");
Console.WriteLine("| from the system. There is a few options to choose from: ");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| 1. An option to add parcel data into the system");
Console.WriteLine("| 2. An option to remove a data from the the system");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
break;
case "B":
Console.Clear();
Console.WriteLine("--------------------DISPLAY PARCEL INFORMATION
MENU----------------");
Console.WriteLine("-------------------------------------------------------------------");
Console.WriteLine("| In this menu, the user can view the information of each parcels");
Console.WriteLine("| within the system, in either sorted or non sorted. The user can also");
Console.WriteLine("| search for the parcel to view the individual parcel details");
Console.WriteLine("| with much detailed information data");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| 1. An option to search for a parcel detail and view the details");
Console.WriteLine("| 2. An option to view all the data within the system");
Console.WriteLine("| 3. An option to view the data in such sorted manner");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
break;
default:
Console.WriteLine("| You've entered the wrong the input |");
Console.WriteLine("| Press enter and please try again |");
Console.ReadKey();
Console.Clear();
break;
}
}
} // end of help menu
while (true)
{
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("\t - Parcel Information Menu - ");
Console.WriteLine("\t - Configure The Parcel Informations - ");
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("|\t In this section, parcel information \t|");
Console.WriteLine("|\t As well as remove any of the parcel information\t|");
Console.WriteLine("|\t For checking and ordering as such. If you need help, |");
Console.WriteLine("|\t Press the corresponding H key at the selection section |");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| Please select the options to continue: \t\t\t|");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("|\t A. Add parcel information \t\t\t\t|");
Console.WriteLine("|\t B. Remove a parcel information \t\t\t|");
Console.WriteLine("|\t H. View the Help \t\t\t\t|");
Console.WriteLine("|\t E. Exit to Main Menu \t\t\t\t|");
Console.WriteLine("---------------------------------------------------------------");
Console.Write("| Choice: ");
choice = Console.ReadLine().ToUpper();
Console.Clear();
// Parcel Information Menu
if (choice == "E")
{
break;
}
switch (choice)
{
case "A":
Console.Clear();
add_data(); // Load to add data method
break;
case "B":
Console.Clear();
remove_data(); // load to remove data method
break;
case "H":
help_menu(); // load to help menu method
break;
default:
Console.WriteLine("You've entered the wrong input");
Console.WriteLine("Press enter and please try again");
Console.ReadKey();
Console.Clear();
break;
}
}
} // end of parcel data menu
do
{
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine("\t\t\t - Add Parcel Informations Menu - ");
Console.WriteLine("\t\t - Entering Parcel Information In To The System - ");
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine("| Please follow the instruction in order to enter the parcel information");
Console.WriteLine("| for completing the delivery to the client");
Console.WriteLine("-------------------INSTRUCTIONS---------------------------------------------");
Console.WriteLine("| The format for inputing the data: ");
Console.WriteLine("| Receiver Name: Mohamad Imran bin Mohamad Yusri");
Console.WriteLine("| Receiver ID: BCS1000");
Console.WriteLine("| Parcel Code: P0303");
Console.WriteLine("| Parcel Description: Fish in a box");
Console.WriteLine("| Parcel Quantity: 3");
Console.WriteLine("| Parcel Destinations: No. 85, Jalan SM1D2/2, Fasa 1D2, Seri Manjung,
Perak");
Console.WriteLine("| Courier Type: 1");
Console.WriteLine("---------------------------------------------------------------------------");
Console.Write("| Press enter to continue: "); Console.ReadKey();
Console.WriteLine("---------------------------------------------------------------------------");
Console.Write("| How many parcels do you want to enter?: ");
int p = int.Parse(Console.ReadLine());
Console.WriteLine("---------------------------------------------------------------------------");
// Menu for showing adding tutorial menu
delivery_data.Add(data);
}
Console.WriteLine("-----------------------------------------------------------------------");
Console.WriteLine("\t\t - Remove Parcel Informations Menu - ");
Console.WriteLine("\t - Removing any available parcel informations from the data - ");
Console.WriteLine("-----------------------------------------------------------------------");
Console.WriteLine("| In this section, users can search and remove any available parcel data");
Console.WriteLine("| From the system, by searching through thr parcel code");
Console.WriteLine("-----------------------INSTRUCTIONS-------------------------------------");
Console.WriteLine("| The format for searching data to be remove: ");
Console.WriteLine("| Parcel Code: BCS020");
Console.WriteLine("| Then the user will be given the options to either");
Console.WriteLine("| to view first the data or remove it immediately");
Console.WriteLine("------------------------------------------------------------------------");
Console.Write("| Parcel Code: ");
code = Console.ReadLine().ToUpper(); Console.Write("|");
Console.WriteLine("----------------------NOW SEARCHING FOR
CODE----------------------------");
// menu for inputing search code for searching
if (count == 0)
{
Console.WriteLine("\t - Parcel List Is Empty - ");
Console.WriteLine("\t - Press enter and please try again later - ");
Console.ReadKey();
Console.Clear();
} // notify the user if code not available
else
{
foreach (object d in delivery_data)
{
delivery = (Delivery)d;
if (code == delivery.itemCode)
{
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("|\t - Item has been found! - |");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("------------------DATA INFORMATION------------------------------");
Console.WriteLine("| Parcel Code: {0}", delivery.itemCode);
Console.WriteLine("| Parcel Description: {0}", delivery.itemDesc);
Console.WriteLine("| Parcel Quantity: {0}", delivery.itemQuant);
Console.WriteLine("| Parcel Destination: {0}", delivery.itemLocation);
Console.WriteLine("---------------------------------------------------------------");
Console.Write("Do you want to remove the following data? (Y|N): ");
option = Console.ReadLine().ToUpper();
Console.WriteLine("---------------------------------------------------------------");
status = 1;
// menu for confirmation for removing data
switch (option)
{
case "Y":
Console.WriteLine("----------------------------------------------------");
Console.WriteLine("- Item has been removed from the system -");
delivery_data.Remove(delivery);
Console.WriteLine("- Press enter to continue -");
Console.ReadKey();
Console.Clear();
break; // notify the user that item has been removed
case "N":
Console.WriteLine(" - Item was not removed from the system - ");
Console.WriteLine(" - Press enter to continue - ");
Console.ReadKey();
Console.Clear();
break; // notify the user that the item was not removed
default:
Console.WriteLine(" - Wrong input has been entered -");
Console.WriteLine(" - Press enter and please try again - ");
Console.ReadKey();
Console.Clear();
break; // wrong input
}
}
if (status == 0)
{
Console.WriteLine("- Item was not found in the system - ");
Console.WriteLine("- Press enter and please try again - ");
Console.ReadKey();
Console.Clear();
} // Item not found
}
}
} // end of removing data menu
static void display_data_menu()
{
string choice;
while (true)
{
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("\t - The Parcel Information Display Menu - ");
Console.WriteLine("\t - Displaying the data of sending parcels");
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("| In this section, the user can input any of the available code");
Console.WriteLine("| to output the details of the certain parcel that has been searched");
Console.WriteLine("| Each of the displayed information can be determined from the");
Console.WriteLine("| Code, description, type, courier type and many more!");
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("| \tPlease choose an option below!: ");
Console.WriteLine("-----------------------------OPTIONS----------------------------------");
Console.WriteLine("| \tA. Search for a parcel information");
Console.WriteLine("| \tB. Display all available parcel");
Console.WriteLine("| \tC. Display the parcels informations by sorted");
Console.WriteLine("| \tH. View the help menu");
Console.WriteLine("| \tE. Exit to main menu");
Console.WriteLine("----------------------------------------------------------------------");
Console.Write("| Choice: ");
choice = Console.ReadLine().ToUpper();
// menu for the parcel display menu
if (choice == "E")
{
Console.Clear();
break;
}
switch (choice)
{
case "A":
Console.Clear();
search_parcel(); // load into search parcel method
break;
case "B":
Console.Clear();
display_all_parcel(); // load into display parcel method
break;
case "C":
Console.Clear();
display_parcel_sorted(); // load into sorted parcel method
break;
case "H":
Console.Clear();
help_menu(); // load into help menu method
break;
default:
Console.WriteLine("- You've entered the wrong input -");
Console.WriteLine("- Press enter to try again -");
Console.ReadKey();
Console.Clear();
break; // wrong input
}
}
} // end of display data menu
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("\t\t - Search Parcel Information Menu - ");
Console.WriteLine("\t\t - Search for parcel details and display the details");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("| In this section, the user can search for any parcel code");
Console.WriteLine("| and display the parcel's detail for any inspection");
Console.WriteLine("| It can display the parcels receiver name, receiver code,");
Console.WriteLine("| parcel's code, description and many more!");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("| Please enter the parcel code to be search: ");
Console.WriteLine("--------------------------INPUT-----------------------------------");
Console.Write("| Parcel code to be search: ");
code = Console.ReadLine().ToUpper();
// Showing the menu for searching data
if (count == 0)
{
Console.WriteLine("- No data available in the system - ");
Console.WriteLine("- Press enter to continue -");
Console.ReadKey();
Console.Clear();
// notify the user that the list is empty
}
else
{
foreach (Delivery d in delivery_data)
{
data = d;
if (code == data.itemCode)
{
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("| \t- Item has been found in the system -");
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("--------------------- DISPLAY ---------------------------");
Console.WriteLine("| User Name: {0}", data.userName);
Console.WriteLine("| User ID: {0}", data.userID);
Console.WriteLine("| Parcel Code: {0}", data.itemCode);
Console.WriteLine("| Parcel Description: {0}", data.itemDesc);
Console.WriteLine("| Parcel Quantity: {0}", data.itemQuant);
Console.WriteLine("| Parcel Destination: {0}", data.itemLocation);
Console.WriteLine("----------------------------------------------------------");
Console.WriteLine("| Please press enter to continue");
Console.ReadKey();
Console.Clear();
status = 1;
// notify the user that the item has found
}
}
if (status == 0)
{
Console.WriteLine("\t - Item not found in the system -");
Console.WriteLine("\t - Press enter to continue and please try again -");
Console.ReadKey();
Console.Clear();
// notify the user that the item has not found
}
}
} // end of search menu
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("\t\t - Display All Parcel Informations -");
Console.WriteLine("\t - Displaying all available parcel details in the system -");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| In this section, parcel informations can be display");
Console.WriteLine("| From every inch of details within the system");
Console.WriteLine("| The details will be listed from the receiver");
Console.WriteLine("| To the parcel destination arrivals");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("-------------------------DISPLAY PARCELS------------------------");
Console.WriteLine("| Receiver Name | Receiver ID | Parcel Code | Parcel Description | Parcel
Quantity" +
" | Parcel Location |");
Console.WriteLine("----------------------------------------------------------------");
// the menu for display data method
int index = 1;
foreach (object d in delivery_data)
{
delivery = (Delivery)d;
Console.WriteLine("| " + delivery.userName + " \t" + delivery.userID + "\t " +
delivery.itemCode
+ "\t " + delivery.itemDesc + "\t" + delivery.itemQuant + " \t" + delivery.itemLocation);
index++;
// looping for displaying the data
}
Console.WriteLine("-----------------------------END OF DISPLAY--------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
} // end of display data menu
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("\t - Display Sorted Parcel Details Menu -");
Console.WriteLine("\t - Displaying the sorted parcel informations - ");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| In this section, the parcel informations will be");
Console.WriteLine("| displayed in such a sorted by quantity of the parcel");
Console.WriteLine("| Instead of non - arranged display, everything");
Console.WriteLine("| Everything will look organized and such");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("-------------------------DISPLAY PARCELS------------------------");
Console.WriteLine("| Receiver Name | Receiver ID | Parcel Code | Parcel Description | Parcel
Quantity" +
" | Parcel Location |");
Console.WriteLine("----------------------------------------------------------------");
// Display the sort display parcel menu
if (pivot > 1)
{
Quicksort_Recursive(quantity, left, pivot - 1);
}
while (true)
{
while(quantity[left] < pivot)
{
left++;
}
else
{
return right;
}
}
}
}
}