2
I created a class called Order
, and in it I created a field for the purpose of entering a date of delivery of the order.
But I created the object on Main()
, and at the time I execute it fills in with the date default, I’ve already done the debug but I don’t know where I’m going wrong.
This is my class Order
:
namespace SergioS_301011342_LIB
{
public class Order
{
private DateTime orderDateMade;
private DateTime orderDateDeli;
private AddressStruct orderAddressDeli;
private decimal cost;
private Customer customer;
private static int orderNumber;
private OrderItem[] orderItems;
private int noOrders;
private const uint MAX_NUMBER_OF_ORDERS = 50;
public Order()
{
orderItems = new OrderItem[MAX_NUMBER_OF_ORDERS];
noOrders = 0;
orderNumber += 1;
orderDateDeli = new DateTime();
}
public Customer Customer
{
get { return customer; }
set { customer = value; }
}
public OrderItem[] OrderItems
{
get { return orderItems; }
set { orderItems = value; }
}
public int OrderId
{
get { return orderNumber; }
}
public DateTime OrderDateMade
{
get { return orderDateMade; }
set { orderDateMade = DateTime.Now; }
}
public DateTime OrderDateDeli
{
get { return orderDateDeli; }
set { orderDateMade = DateTime.Today; }
}
public AddressStruct OrderAddressDeli
{
get { return orderAddressDeli; }
set {orderAddressDeli = value; }
}
public decimal Cost
{
get { return cost; }
set { cost = value; }
}
public void AddOrderItem(OrderItem orderItem)
{
orderItems[noOrders++] = orderItem;//verify if the array is not full before save it.
Cost += orderItem.MenuItem.MenuBaseCost;
}
public string GetInfo()
{
string result = string.Empty;
result += "\n\t\t\t\t\tId Order : " + orderNumber + "\n";
result += "========================================================================================";
result += "\nDate of the order: " + this.OrderDateMade.ToString();
result += "\t\tDate of the delivery: " + orderDateDeli.ToString();
result += "\nDelivery Address: " + this.orderAddressDeli.streetNumber + ", ";
result += this.orderAddressDeli.streetName + ", " + this.orderAddressDeli.city + "-";
result += this.orderAddressDeli.province + "\n";
result += "Orders: \n";
foreach (OrderItem item in this.orderItems)
{
if (item == null)break;
result += item.GetInfo();
}
result += "\n========================================================================================";
result += "\nCost total of the order: " + this.Cost.ToString("C2");
result += "\n========================================================================================";
return result;
}
}
}
That’s the Main
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SergioS_301011342_LIB;
namespace SergioS_301011342_A1
{
class Program
{
static void Main(string[] args)
{
OrderItem orderItem = new OrderItem(new MenuItem()
{
MenuName = "Hot Coffee",
MenuDescription = "Dark Coffee with 2 milks and 2 creams",
MenuBaseCost = 3.5M,
});
OrderItem orderItem2 = new OrderItem(new MenuItem()
{
MenuName = "Milk",
MenuDescription = "Hot Milk",
MenuBaseCost = 2.5M,
});
Customer customer1 = new Customer();
customer1.Name = "Richard Silva";
customer1.PhoneNumber = "6471231212";
var address = new AddressStruct()
{
streetNumber = 1600,
streetName = "Progress Avenue",
city = "Toronto",
province = "ON",
};
customer1.Address = address;
var addressDelivery = new AddressStruct()
{
streetNumber = 890,
streetName = "Keele Street",
city = "Toronto",
province = "ON",
};
var order = new Order();
order.OrderAddressDeli = addressDelivery;
order.AddOrderItem(orderItem);order.OrderItems[0] = orderItem;
order.AddOrderItem(orderItem2);order.OrderItems[1] = orderItem2;
customer1.Orders[0] = order;
order.OrderDateMade = new DateTime();
order.OrderDateDeli = new DateTime();
Console.WriteLine(customer1.GetInfo());
Console.ReadLine();
}
I understood, but my teacher is so boring ( to the point of giving a test to be done on no Notepad instead of Visual Studio) so he banned the use of self-applied properties. He said that once we learn how it’s done, we can use the self-applied.
– Sérgio Silva