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 8059995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:50:38+00:00 2026-06-05T09:50:38+00:00

What I need suggestions for is the Equals method located at the near the

  • 0

What I need suggestions for is the “Equals” method located at the near the bottom of the code. To note, the Equals method MUST be contained within the Order class and I cannot use auto-implemented properties in case your wondering why I didn’t use them lol. The function of the equals method is to search ALL current order numbers (There is currently 1 User and 3 automated) for a duplicate. I cannot figure out how I could do this without user input or without the use of a bunch of “if” statements. Any suggestions would be awesome, thanks.
~~ The other two methods at the bottom are no finished~~

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment3
{
  class Program
  {
    static void Main(string[] args)
    {
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
        // USER CONTROLLED
        int ordNum;
        Console.Write("Enter Order Number: ");
        ordNum = Convert.ToInt16(Console.ReadLine());

        string custName;
        Console.Write("Enter Customer Name: ");
        custName = Console.ReadLine();

        int quantity;
        Console.Write("Enter Quantity: ");
        quantity = Convert.ToInt32(Console.ReadLine());

        Order firstOrder = new Order(ordNum, custName, quantity);

        Console.WriteLine("Customer: {0}\nOrder Number: {1}\nQuantity" +
        "Ordered: {2}\nTotal Price: {3}", firstOrder.Customer, firstOrder.OrderNum, firstOrder.QuantityOrd, firstOrder.Total);
        // USER CONTROLLED

        // AUTOMATED
        // FIRST
        int firstOrdNum = 678123;
        string firstName ="P Jenkins";
        int firstQuantity = 35;
        Order firstAutomated = new Order(firstOrdNum, firstName, firstQuantity); // first Instance of Order
        // END OF FIRST

        // SECOND
        int secondOrdNum = 678123;
        string secondName = "L Jenkins";
        int secondQuantity = 35;
        Order secondAutomated = new Order(secondOrdNum, secondName, secondQuantity);
        // END OF SECOND

        // THIRD
        int thirdOrdNum = 49284;
        string thirdName = "McDonalds";
        int thirdQuantity = 78;
        Order thirdAutomated = new Order(thirdOrdNum, thirdName, thirdQuantity);
        // END OF THIRD
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



    }
}
class Order
{
    private int orderNum;
    private string customer;
    private int quantityOrd;
    public const double amt = 19.95;
    private double totalPrice;
    // PROPERTIES TO ACCES PRIVATE DATA
    public int OrderNum // CHECK
    {
        get
        {
            return orderNum;
        }
        set
        {
            orderNum = value;
        }
    }
    public string Customer // CHECK
    {
        get
        {
            return customer;
        }
        set
        {
            customer = value;
        }
    }
    public int QuantityOrd // CHECK
    {
        get
        {
            return quantityOrd;
        }
        set
        {
            quantityOrd = value;
            CalcTotalPrice();
        }
    }
    public double Total // CHECK
    {
        get
        {
            return totalPrice;
        }
    }      
    // CALCULATE TOTAL
    private void CalcTotalPrice()
    {
        totalPrice = QuantityOrd * amt;
    }
    // EQUALS METHOD 
    public void Equals(int ordNum1, int ordNum2)
    {
        Console.WriteLine("The two orders by P Jenkens (Order Number: {0}) and L Jenkens (Order Number: {1})" +
            "are the same order!", ordNum1, ordNum2);
    }
    public void GetHashCode(string customer, double hashCode)
    {
        Console.WriteLine("The Hash Code of Customer {0} is {1}", customer, hashCode);
    }
    public void ToString()
    {
    }


    // CONSTRUCTOR TO ACCEPT VALUES
    public Order(int ordNum, string cust, int qntOrd)
    {
        OrderNum = ordNum;
        Customer = cust;
        QuantityOrd = qntOrd;
    }

}
  • 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-05T09:50:39+00:00Added an answer on June 5, 2026 at 9:50 am

    Sounds like each Order should have a unique Identifier.
    Checking if two orders are the same order, would be comparing their Id’s.
    Checking if two orders have the same inner state, is like a normal Equals.

    If you want to access the orders using their Id’s, you should save them in a dictionary.

    The general idea would be something like this, although a lot is missing here:

    public class Order
    {
        ...
    
        private static Dictionary<int, Order> _orders = new Dictionary<int, Order>();
    
        public static Order Get(int id)
        {
            return this._order[id];
        }
    
        private static object _idLocker = new object();
        private static int _nextId = 0;
        public readonly int Id;
    
        public Order()
        {
            // Just to make sure that the identifiers are unique,
            // even if you have threads messing around.
            lock (_idLocker)
            {
                this.Id = _nextId;
                _nextId++;
            }
    
            _orders.Add(this.Id, this);
        }
    
        public Order(int id)
        {
            this.Id = id;
            _orders.Add(this.Id, this);
        }
    
        public static bool Equals(int id1, int id2)
        {
            return _orders[id1].Equals(_orders[id2]);
        }
    
        public bool Equals(Order otherOrder)
        {
            // Check whether you have the same inner state as the other order
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some asp.net pagination code samples. I would like suggestions on open source
Need suggestions on implementing associating single or many objects to an entity. All soccer
I need suggestions on how can I download attachments from my IMAP mails which
I need to write a java application which can merge docx files. Any suggestions?
I'm just looking for suggestions on the best way to do this... I need
Locally I need to code against Java 1.4. I tried the suggestion in this
I'm working with expressions and I need a method which receives an object of
Making a simple Java code for Blackjack and need some advice. OK I am
I need suggestion about YAMI library . I have a system which receives Json
I know my question isn't about programming problem, I just need a suggestion to

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.