Needs to be solved with C# Only please! Inheritance and Polymorphism A retail st
ID: 3780343 • Letter: N
Question
Needs to be solved with C# Only please!
Inheritance and Polymorphism
A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customer's discount is determined by the amount of the customer's cumulative purchases in the store as follows:
When a preferred customer spends $500, he or she gets a 5 percent discount on all future purchases.
When a preferred customer spends $1000, he or she gets a 6 percent discount on all future purchases.
When a preferred customer spends $1500, he or she gets a 7 percent discount on all future purchases.
When a preferred customer spends $2000 or more, he or she gets a 10 percent discount on all future purchases.
Design a class named Person with properties for holding a person's name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Finally, design a class named PreferredCustomer, which is derived from the Customer class. The PreferredCustomer class should have properties for the amount of the customer's purchases and the customer's discount level. Demonstrate the class in a simple application.
Also I dont know how to design the form. Can you Please also design the form me. Thank you!
Explanation / Answer
Below are the three classes written in C# code. The code is bug free.
Person class :
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace RETAILSTORE
{
abstract class Person
{
//Fields decleration
private string _name, _address; // address declared
private int _number; // number
public Person() //public class person
{
_name = "";
_address = "";
_number = 0;
}
//Constructor part
public Person(string name, string add, int phone)
{
_name = name;
_address = add;
_number = phone;
}
//Below is the Name property
public string Name
{
get { return _name; }
set { _name = value; }
}
//Below is the Address property
public string Address
{
get { return _address; }
set { _address = value; }
}
//Below is the telephonenumber property
public int telphn
{
get { return _number; }
set { _number = value; }
}
}
}
Customer Class:
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
namespace RETAILSTORE
{
class Customer : Person //customer class declared
{
//Below are the Fields
private string customNum;
private bool mailing;
public Customer() //public class customer
{
}
//Constructor part
public Customer(string name, string address, int phone, string CuNu, bool emailid)
: base(name, address, phone)
{
customNum = CuNu;
mailing = emailid = true;
}
//Below is the CustomerNum property
public string CustomerNum
{
get { return customNum; }
set { customNum = value; }
}
//Below is the Mailing property
public bool Mailing
{
get { return mailing; }
set { mailing = value; }
}
}
}
Form Class:
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Data;
namespace RETAILSTORE
{
public partial class Formnew : Form
{
public Formnew()
{
InitializeComponent();
}
private void Formnew_Load(object sender, EventArguments f)
{
}
private void buttonnew_Click(object sender, EventArguments f)
{
string person, address, number;
string telphnNum;
bool mailngAdd = true || false;
if (mailngAdd == true)
{
label5.Text = "Yes";
}
if (mailngAdd == false)
{
label5.Text = "No";
}
person = textBox1.Text;
address = textBox2.Text;
telphnNum = textBox3.Text;
number = textBox4.Text;
label1.Text = person;
label2.Text = address;
label3.Text = telphnNum;
label4.Text = number;
Customer add1 = new Customer(person, address, telphnNum, number, mailngAdd);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.