C# Format You have been contracted to create an application that can be used to
ID: 3705734 • Letter: C
Question
C# Format
You have been contracted to create an application that can be used to determine the discount awarded for preferred customers. Because of the time limitation, you should focus your attention on the preferred customer class. Include data members of customer ID, customer name, and customer purchase. Define appropriate constructors and properties for the class. Include a method that returns the discount percentage based on the following: • When a preferred customer spends a minimum of $500, he or she gets a 5 percent discount • When a preferred customer spends a minimum of $1,000, his discount is 6 percent • When a preferred customer spends a minimum of $1,500, his discount is 7 percent discount • When a preferred customer spends at least $2,000, he or she gets a 10 percent discount Include an additional instance method that returns the actual reduced discounted price. Override the ToString( ) method to return the customer name, his purchase amount (formatted as currency), discount percentage (if any),and the reduced purchase price (formatted as currency). Define the 2nd class to test your preferred customer class. You may instantiate your objects with literal data sent as arguments to the constructors. You do not have to input the data. USE YOUR OWN NAME AS THE CUSTOMER NAME FOR ONE OF THE OBJECTS THAT YOU INSTANTIATE. Before instantiating an object of the class, check to make sure the purchase amount entered is a positive integer. If the value entered for the purchase amount is negative, display an error message indicating the input is in-valid. Modularize your solution.
Explanation / Answer
Hi Dear,
Please find my implementation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PreferredCustomer
{
//class for person
class person
{
//declare the variable for custName
private String custName;
//constructor
public person()
{
custName = "";
}
//initializes the constructor for person
public person(String custName)
{
this.custName = custName;
}
//set method property for customer name
public void setCName(String custName)
{
this.custName = custName;
}
//get method property for customer name
public String getCName()
{
return custName;
}
}
//class for customer
class Customer : person
{
//declare the variable for customer ID
private int custID;
//constructor for customer class
public Customer()
{
}
//initializes constructor for Customer class
public Customer(String custName,int custID): base(custName)
{
this.custID = custID;
}
//get method property for customer ID
public int getCID()
{
return custID;
}
//set method property for customer ID
public void setCID(int custID)
{
this.custID = custID;
}
//override method for return customer name and customer ID
public String toString()
{
return "Customer Name: " + getCName() + " Customer ID: " + custID;
}
}
//class for Preferred Customer
class PreferredCustomer : Customer
{
//declare variable for purchase
private double purchase;
//declare variable for discount
private double discount;
//declare variable for discount price
private double discountPrice;
//constructor for PreferredCustomer
public PreferredCustomer(String custName,int custID, double purchase)
: base(custName,custID)
{
this.purchase = purchase;
}
//set property for purchase
public void setPurchase(double purchase)
{
this.purchase = purchase;
}
//set property for discount
private void setDiscount(double discount)
{
this.discount = discount;
}
//get property for purchase
public double getPurchase()
{
return purchase;
}
//get property for discount
public double getDiscount()
{
//call findDiscount method
findDiscount();
return discount;
}
//set property for discount price
public void setDiscountPrice(double discountPrice)
{
this.discountPrice = discountPrice;
}
//get property for discount price
public double getDiscountPrice()
{
findDiscountPrice();
return discountPrice;
}
//method defintion for property for discount
private void findDiscountPrice()
{
discountPrice = getPurchase() - (getPurchase() * (getDiscount() / 100));
}
//get property for discount
private void findDiscount()
{
//check the purchase amount
if (getPurchase() >= 2000)
{
setDiscount(10);
}
else if (getPurchase() >= 1500)
{
setDiscount(7);
}
else if (getPurchase() >= 1000)
{
setDiscount(6);
}
else if (getPurchase() >= 500)
{
setDiscount(5);
}
}
//print the purchase amount, discount and dicount price
public String toString()
{
String pc = base.toString() +" Purchase amount: $" + getPurchase() +" Discount: " + getDiscount() +" %"+
" Discount Price: $" + getDiscountPrice();
return pc;
}
}
//main method
class Program
{
static void Main(string[] args)
{
//create the object for PreferredCustomer
PreferredCustomer pc = new PreferredCustomer("Pravesh",5050, 2000);
//print the all data using toString method
Console.WriteLine(pc.toString());
Console.ReadKey();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.