Go Back   CodeCall Programming Forum > Software Development > C# Programming
Register Blogs Search Today's Posts Mark Forums Read

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-05-2009, 05:52 PM
Newbie
 
Join Date: Jul 2009
Posts: 5
Buddinu is an unknown quantity at this point
Coding help

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
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-05-2009, 06:41 PM
WingedPanther's Avatar
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 11,435
WingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud of
Re: Coding help

How do you know there are errors? Are they compiler errors, functional errors, something else?
__________________
CodeCall Blog | CodeCall Wiki | Shareware
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-06-2009, 09:43 AM
Programming Expert
 
Join Date: May 2006
Posts: 354
dirkfirst is on a distinguished road
Re: Coding help

Please post or describe any errors you have. It is hard to diagnose the problem with out them.
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding style. Chinmoy General Programming 25 03-27-2009 01:49 PM
Linear predicate Coding or LPC Ubuntu_monster General Programming 0 08-11-2008 12:14 PM
Turning Conventional Video Coding Wisdom On Its Head Kernel News 0 05-22-2008 08:18 AM
Need some coding help!! Gianmbaio C and C++ 1 02-28-2008 12:42 AM
More Coding Methods RobSoftware General Programming 2 05-30-2006 05:42 PM


All times are GMT -5. The time now is 09:27 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0