Question: [Note: For this section create a second project and call it Section-2-OOO ] Create a public class Product with the following Fields: Code as string
[Note: For this section create a second project and call it Section-2-OOO ]
-
Create a public class Product with the following
-
Fields:
-
Code as string
-
Description as string
-
Price as decimal
-
Constructor
-
An empty constructor
-
An overload constructor with the fields as parameters (Object initializer)
-
Properties
-
One for each field
-
Functions
-
A public function that returns a string such as
-
The Product Number + code + is a + description.
-
A public function that return a string such as
-
The Price for Product Number + code + is $+ price.
using System;
class Program {
static void Main(string[] args)
{
Product prod = new Product("AE10145", "Motor Cycle", 12.44m);
onsole.WriteLine(prod.prodctNumberDetails()); Console.WriteLine(prod.productPriceDetails());
}
}
class Product
{
private string ring code;
private string description;
private decimal price;
public Product() {
}
public Product(string code, string description, decimal price) {
this.code = code;
this.description = description;
this.price = price; }
public string Code {
get{return code;
}
set{code = value;}
}
public string Description {
get{return description;} set{description = value;
}
}
public decimal Price {
get{return price;
}
set{price = price;
}
}
public string prodctNumberDetails()
{
return "The Product Number " + code + " is a " + description;
}
public string productPriceDetails() {
return "The Price for Product Number " + code + " is $" + price;
}
}
-
Write the code to create an overload Function for the == Operator in the Product class created in the previous question [Hint: make your type implement the IEquatable
]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
