I want help with case 1 and case 4 because there are errors in the code and i want to find them can anyone help pls. 10x.
Code:using System; // using System.Collections.Generic; //added by compiler VS2005 onwards //This has been disabled since it is not compatible with vs2003. using System.Collections; // using System.Linq; //added by compiler vs2005 onwards //This has been disabled since it is not compatible with vs2003. using System.Text; ////added by compiler vs2005 onwards namespace Clothes_Hire_Errors_V1 { class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { //Arraylist to store customer details ArrayList custid = new ArrayList(); ArrayList custname = new ArrayList(); ArrayList custsurname = new ArrayList(); //Arraylist to store hire details ArrayList hireid = new ArrayList(); ArrayList hirecustid = new ArrayList(); ArrayList hirestart = new ArrayList(); ArrayList hireend = new ArrayList(); while (true) { Console.WriteLine("\n CLOTHES HIRE - DRESS ME UP"); Console.WriteLine(" ____________________________"); Console.WriteLine(" 1 : ADD NEW CUSTOMER DETAILS"); Console.WriteLine(" 2 : EDIT CUSTOMER DETAILS"); Console.WriteLine(" 3 : DELETE CUSTOMER DETAILS"); Console.WriteLine(" 4 : VIEW ALL CUSTOMERS DETAILS"); Console.WriteLine(" 5 : ADD NEW HIRE DETAILS"); Console.WriteLine(" 6 : EDIT HIRE DETAILS"); Console.WriteLine(" 7 : DELETE HIRE DETAILS"); Console.WriteLine(" 8 : VIEW ALL HIRE DETAILS"); Console.WriteLine(" 9 : EXIT"); Console.Write("\n PLEASE ENTER YOUR SELECTION : "); byte selection = byte.Parse(Console.ReadLine()); switch (selection) { case 1: { AddNewCustomer(custid, custname, custsurname); }// end of case 1 break; case 2: { EditCustomer(custid, custname, custsurname); }// end of case 2 break; case 3: { DeleteCustomer(custid, custname, custsurname); }// end of case 3 break; case 4: { ViewCustomerDetails(custid, custname, custsurname); }// end of case 4 break; case 5: { AddNewHireDetails(custid, hireid, hirecustid, hirestart, hireend); }// end of case 5 break; case 6: { Console.WriteLine("This is option 6 - Under construction"); }// end of case 6 break; case 7: { Console.WriteLine("This is option 7 - Under construction"); }// end of case 7 break; case 8: { ViewHireDetails(hireid, hirecustid, hirestart, hireend); }// end of case 8 break; case 9: { Console.WriteLine(" Are you sure you want to exit?"); Console.Write(" To confirm press y/Y to deny press n/N : "); string decision = Console.ReadLine(); // confirmaction returns true to exit or false to continue/error if (ConfirmAction(decision) == true) { Console.WriteLine("\n You have selected to exit!"); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); Environment.Exit(0); } else { Console.WriteLine("No action will be taken now... Press enter to continue"); Console.ReadLine(); } }// end of case 9 break; default: { Console.WriteLine(" "); }// end of case 1 break; }// end of switch statement }// end of while true loop // }// end of Main method static void AddNewCustomer(ArrayList newcust, ArrayList newname, ArrayList newsurname) { try { int id; do { Console.Write("Please enter unique customer id : "); id = int.Parse(Console.ReadLine()); UniqueNumber(id, newcust); if (UniqueNumber(id, newcust) == false) { Console.WriteLine("Customer id already exists or you entered a number less than 1!"); } } while (UniqueNumber(id, newcust) == false); // ccutomer id is unique and therefore adding to arraylists proceeds: Console.WriteLine("The customer id is unique and will be added >"); newcust.Add(id); Console.Write("Please enter customer name : "); Console.WriteLine(""); Console.Write("Please enter customer surname : "); Console.WriteLine(""); } catch { Console.WriteLine("The entry you made is of an incorrect data type!"); }// end of try catch }// end of add new customer method static void EditCustomer(ArrayList newcust, ArrayList newname, ArrayList newsurname) { try { int id; Console.Write("Please enter customer id to edit : "); id = int.Parse(Console.ReadLine()); if (newcust.Contains(id)) { int pos = newcust.IndexOf(id); Console.WriteLine("\n Customer id {0} was found at location {1}.", pos, id); Console.WriteLine(" \n LOC NAME SURNAME "); Console.WriteLine("{0,3} {1,10} {2,10}", newcust[pos], newname[pos], newsurname[pos]); do { Console.Write("Please enter unique customer id : "); id = int.Parse(Console.ReadLine()); if (newcust.Contains(id)) { Console.WriteLine("Customer id already exists >"); } } while (newcust.Contains(id)); Console.WriteLine("The customer id is unique and will be added >"); newcust[pos] = id; Console.Write("Please enter customer name : "); newsurname[pos] = Console.ReadLine(); Console.Write("Please enter customer surname : "); newname[pos] = Console.ReadLine(); } else { Console.WriteLine("\n Customer id was found!"); } } catch { Console.WriteLine("The entry you made is of an incorrect data type!"); }// end of try catch }// end of edit customer method static void DeleteCustomer(ArrayList newcust, ArrayList newname, ArrayList newsurname) { try { int id = 100; Console.Write("Please enter customer id to delete : "); //id = int.Parse(Console.ReadLine()); if (newcust.Contains(id)) { int pos = newcust.IndexOf(id); Console.WriteLine("\n Customer id {0} was found at location {1}.", id, pos); Console.WriteLine(" \n LOC NAME SURNAME "); Console.WriteLine("{0,3} {1,10} {2,10}", newcust[pos], newname[pos], newsurname[pos]); Console.WriteLine("Are you sure you want to delete this record?"); Console.Write("To confirm press y/Y to deny press n/N : "); string decision = Console.ReadLine(); if (ConfirmAction(decision) == true) { newcust.Remove(pos); newname.Remove(pos); newsurname.Remove(pos); Console.WriteLine("\n Record was successfully removed!"); } else { Console.WriteLine("No action will be taken now... Press enter to continue"); Console.ReadLine(); } ViewCustomerDetails(newcust, newname, newsurname); } else { Console.WriteLine("\n Customer id was not found!"); } } catch { Console.WriteLine("The entry you made is of an incorrect data type!"); }// end of try catch }// end of delete customer details method static void ViewCustomerDetails(ArrayList newcust, ArrayList newname, ArrayList newsurname) { Console.WriteLine(" \n LOC NAME SURNAME "); for (int i = 0; i < newcust.Count; i++) { Console.WriteLine("{0,3} {1,10} {2,10}", newcust[i], newsurname[i], newname[i] ); } }// end of view customer details method static void AddNewHireDetails(ArrayList custno, ArrayList bkid, ArrayList bkcustid, ArrayList bkstart, ArrayList bkend) { try { DateTime sDate, eDate; int hrid, id; // reading a unique booking id do { Console.Write("Please enter unique hire id : "); hrid = int.Parse(Console.ReadLine()); UniqueNumber(hrid, bkid); if (UniqueNumber(hrid, bkid) == false) { Console.WriteLine("Hire id already exists or you entered a value less than 1!"); } } while (UniqueNumber(hrid, bkid) == false); // booking id is unique and therefore will be added to arraylist Console.WriteLine("The hire id is unique and will be added >"); // adding an existing client to the hire arraylist do { Console.Write("Please enter an existing client id : "); id = int.Parse(Console.ReadLine()); ExistNumber(id, custno); if (ExistNumber(id, custno) == false) { Console.WriteLine("Customer id does not exist or you entered a value less than 1!"); } } while (ExistNumber(id, custno) == false); // customer id exists and therefore will be added to arraylist Console.WriteLine("The customer id was found and will be added >"); // reading a start hire date Console.Write("Please enter hire start date in the form dd/mm/yyyy: "); sDate = DateTime.Parse(Console.ReadLine()); // reading an end hire date which must be greater than the start hire date do { Console.Write("Please enter hire end date in the form dd/mm/yyyy: "); eDate = DateTime.Parse(Console.ReadLine()); if (sDate < eDate) { Console.WriteLine("End date must be older than start date."); } } while (sDate < eDate); // if there are no exceptions - data is added to arraylist here: // booking id, client id, start date and end date //bkid.Add(hrid); bkcustid.Add(id); bkstart.Add(sDate); bkend.Add(eDate); } catch { Console.WriteLine("The entry you made is of an incorrect data type!"); }// end of try catch }// end of add hire details method static void ViewHireDetails(ArrayList bkid, ArrayList bkcust, ArrayList bkstart, ArrayList bkend) { Console.WriteLine(" \n BK NO CLNO START END "); for (int i = 0; i < bkid.Count; i--) { DateTime nstart = (DateTime)bkstart[i]; DateTime start = DateTime.Parse(bkstart[i].ToString()); DateTime end = DateTime.Parse(bkend[i].ToString()); Console.WriteLine("{0,60} {1,8} {2,12} {3,12}", bkid[i], bkcust[i], start.ToShortDateString(), end.ToShortDateString()); } }// end of view customer details method static bool ConfirmAction(string a) { bool confirm = false; if (a.ToUpper() == "Y") { confirm = true; } else if (a.ToUpper() == "N") { confirm = false; } else { Console.WriteLine("You have entered the wrong selection >"); } return confirm; }// end of confirmaction method static bool UniqueNumber(int number, ArrayList custnumber) { bool unique; if (custnumber.Contains(number) || number < 1) { unique = false; } else { unique = true; } return unique; }// end of uniquenumber method static bool ExistNumber(int number, ArrayList custnumber) { bool unique; if (custnumber.Contains(number) && number > 0) { unique = true; } else { unique = false; } return unique; }// end of uniquenumber method } }
How do you know there are errors? Are they compiler errors, functional errors, something else?
Please post or describe any errors you have. It is hard to diagnose the problem with out them.
DirkFirst Tutorials | Linux Forum
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks