Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:07:18+00:00 2026-06-14T19:07:18+00:00

Hey So I need to design a program that Can add Pickups or Delivery’s

  • 0

Hey So I need to design a program that Can add Pickups or Delivery’s for a company to a list for my coursework, I have made a list called visits as shown bellow.

I would like to know how to add each pickup or delivery to the list in a way that it can differentiate between what is was originally so that I can show Only pickups or only delivery’s.

class List
{
/*
 * This object represents the List. It has a 1:M relationship with the Visit class
 */

    private List<Visits> visits = new List<Visits>();
    //List object use to implement the relationshio with Visits

    public void addVisits(Visits vis)
    {
        //Add a new Visit to the List
        visits.Add(vis);
    }

    public List<String> listVisits()
    {//Generate a list of String objects, each one of which represents a Visit in List.

        List<String> listVisits = new List<string>();
        //This list object will be populated with Strings representing the Visits in the lists

        foreach (Visits vis in visits)
        {
            String visAsString = vis.ToString();
            //Get a string representing the current visit object

            listVisits.Add(visAsString);
            //Add the visit object to the List
        }

        return listVisits;
        //Return the list of strings
    }

    public Visits getVisits(int index)
    {
        //Return the visit object at the <index> place in the list

        int count = 0;
        foreach (Visits vis in visits)
        {
            //Go through all the visit objects
            if (index == count)
                //If we're at the correct point in the list...
                return vis;
            //exit this method and return the current visit
            count++;
            //Keep counting
        }
        return null;
        //Return null if an index was entered that could not be found
    }

SHOW CODE

       /*
         * Update the list on this form the reflect the visits in the list
         */
        lstVisits.Items.Clear();
        //Clear all the existing visits from the list

        List<String> listOfVis = theList.listVisits();
        //Get a list of strings to display in the list box


        lstVisits.Items.AddRange(listOfVis.ToArray());
        //Add the strings to the listBox. Note to add a list of strings in one go we have to 
        //use AddRange and we have to use the ToArray() method of the list that we are adding
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:07:19+00:00Added an answer on June 14, 2026 at 7:07 pm

    It looks like you have both Pickup and Delivery inheriting a common class called Visits*.

    Alter Visits to provide a way to differentiate the kinds of visits, for example, like this:

    enum VisitKind {
        Pickup,
        Delivery
    }
    
    public class Visits {
        public VisitKind KindOfVisit {get;private set;}
        protected Visits(VisitKind kind) {
            KindOfVisit = kind;
        }
    }
    

    Now modify the constructors of Pickup and Delivery to pass the correct kind to the constructor of their superclass, like this:

    public class Pickup : Visits {
        public Pickup() : base(VisitKind.Pickup) {}
    }
    public class Delivery : Visits {
        public Delivery() : base(VisitKind.Delivery) {}
    }
    

    Now you can examine the KindOfVisit property common to Pickup and Delivery in order to tell the kind of the visit at runtime:

    public IList<Delivery> GetDeliveries() {
        var res = new List<Delivery>();
        foreach (var v in visits) {
            if (v.KindOfVisit == VisitKind.Delivery) {
                res.Add((Delivery)v);
            }
        }
        return res;
    }
    

    This solution is not ideal, because when someone adds a new kind of visit, the code that processes visits would continue compiling as usual. A solution to this problem is a lot harder than adding a property, though: one solution is to employ the Visitor Pattern which is better than a simple Kind attribute, but it has limitations of its own.


    * Naming a class with a plural of a noun is unconventional – Visit would probably be a better name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I have a wordpress blog, and I need to add some negative margin
Hey everyone, I have a database result that returns from a method. I need
Hey guys, I need to make a list of some functions that are listed
Hey all i have 2 dates that i need to see the days that
Hey can any one tell me should i need open a port for outgoing
Hey, I need to delete all images from a string and I just can't
Hey, I need help isolating part of a url in PHP. say I have
Hey, I'm using php 5 and need to communicate with another server that runs
Hey i need to make a count on a few tables where i have
Hey, need a little help here. I have two models: class User < ActiveRecord::Base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.