Question

In: Computer Science

Using Visual Studio, C# Programming Lecture: Objects, Inheritance and abstract classes, member init list, shape, circle...

Using Visual Studio, C# Programming

Lecture: Objects, Inheritance and abstract classes, member init list, shape, circle and cylinder.

Complete Exercises 4 and 5 (100pts)

4. Person and customer classes

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 form 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, Demonstrate an object of the Customer class in a simple application.

5. PreferredCustomer Class

A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customers discount is determined by the amount of the customers cummulative 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 $1,000, he or she gets a 6 percent discount on all future purchases.

- When a preferred customer spends $1,500, he or she gets a 7 percent discount on all future purchases.

- When a preferred customer spends $2,000, he or she gets a 10 percent discount on all future purchases.

Design a class named PreferredCustomer, which is derived from the Customer class you created in Exercise 4. 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.

Complete below for 100pts extra credit

  • Use overloaded constructors and member initialization list
  • Person will be an abstract class with a virtual function called CalcDiscount
  • Override the discount method for a normal customer and for a preferred customer
    • A normal customer gets a 0% discount review #5 for a preferred customer
  • Create one array of the defined Person object where you instantiate Customers and Preferred Customers in the array
  • Implement and test your override of the discount method
  • Remember your array must be of the Person type

Person[] people=new Person[2];

people[0]=new Customer(arguments here);

people[1]=new Preferredcustomer(arguments here);

people[0].calcdiscount();

people[1].calcdiscount();

use overridden methods to effect polymorphism. overload operators to
enable them to manipulate
objects.
determine an object’s type
at execution time.
create sealed methods
and classes.
create abstract classes and
methods.

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks

Code:

Customer.cs

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

namespace CustomerManagement
{
public class Customer : Person
{
public Customer(string name, string address, string phone, string id,
bool onEmailList)
: base(name, address, phone)
{
CustomerID = id;
OnEmailList = onEmailList;
}

public string CustomerID { get; set; }
public bool OnEmailList { get; set; }

public override double calcDiscount()
{
return 0;
}

public override string ToString()
{
return
String.Format(
"CustomerID: {0}\nCustomer Name: {1}\nCustomerAddress: {2}\n" +
"Customer Phone: {3} \n" +
"Customer On Email List: {4}\nDiscount: {5}%",
CustomerID, CustomerName, Address, Phone, OnEmailList, 0
);
}

}
}

Person.cs

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

namespace CustomerManagement
{
public abstract class Person
{
public Person(string name, string address, string phone)
{
CustomerName = name;
Address = address;
Phone = phone;
}

public string CustomerName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }

public virtual double calcDiscount(){
return -1;
}

}
}

PreferredCustomer.cs

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

namespace CustomerManagement
{
public class PreferredCustomer : Customer
{
public PreferredCustomer(string name, string address, string phone, string id,
int spentAmount, bool onEmailList)
: base(name, address, phone, id, onEmailList)
{
this.spentAmount = spentAmount;
discountLevel = setDiscountLevel();
}

public double spentAmount { get; set; }
public double discountLevel { get; set; }

public double setDiscountLevel()
{
int range = (int)spentAmount / 500;
switch (range)
{
case 0:
return 0;
case 1:
return 0.05;

case 2:
return 0.06;

case 3:
return 0.07;

default:
return 0.10;
}
}

public override string ToString()
{
return
String.Format(
"CustomerID: {0}\nCustomer Name: {1}\nCustomerAddress: {2}\n" +
"Customer Phone: {3} \n" +
"Customer Spending: {4:C2}\nCustomer On Email List: {5}\nEligible for discount: {6}%",
CustomerID, CustomerName, Address, Phone, spentAmount, OnEmailList,discountLevel*100
);
}

public override double calcDiscount()
{
setDiscountLevel();
return discountLevel;
}

}
}
Main.cs

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

namespace CustomerManagement
{
class Program
{
static void Main(string[] args)
{
Person[] people=new Person[2];

people[0] = new Customer("Cust", "NYC", "98909", "1", false);

people[1]=new PreferredCustomer("Preffered Cust","NYC","98809","2",6000,true);


Console.WriteLine("Discount for normal customer :"+people[0].calcDiscount()*100 + " %");

Console.WriteLine("Discount for preferred customer :" + people[1].calcDiscount() * 100 + " %\n\n");

Console.WriteLine(people[0]);

Console.WriteLine(people[1]);
Console.ReadKey();
}
}
}

Output:


Related Solutions

there is a superclass SHAPE, and 2 derived classes CIRCLE and CYLINDER. The member methods of...
there is a superclass SHAPE, and 2 derived classes CIRCLE and CYLINDER. The member methods of class Shape: Shape(radius:double, height:double): Overloaded constructor. This constructor initializes the member attributes of the class radius and height to the value of its parameters and also initializes the constant variable PI to 3.142. Besides, it also sets the value of radius and height to default value 0 if no parameter is provided. setRadius(r int):This function sets the value of member attribute radius to the...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a Singapore Airlines Loyalty program. You are asked to write an inheritance hierarchy discount system that benefits KrisFlyer members program to calculate their profit. A brief about KrisFlyer is that it is useful for those who fly on Singapore Airlines (its partners like Virgin Australia and Air New Zealand) frequently. KrisFlyer miles can be earned through credit cards, flying and bonus miles promotions. The miles...
Please do this in visual studio C++. Overview In this programming challenge, you will create an...
Please do this in visual studio C++. Overview In this programming challenge, you will create an Employee Tree application. Instructions Begin this assignment by writing your own version of a class template that will create a binary tree that can hold values of any data type. Design an EmployeeInfo class that holds the following employee information: Employee ID Number (int) Employee Name (string) Next, use the template you designed to implement a binary tree whose nodes hold an instance of...
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects •...
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects • Methods • Arrays of Primitive Values • Arrays of Objects • Recursion • for and if Statements • Insertion Sort 2. Use the following Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP...
Chapter 9 Programming Project (Inheritance, Abstract Class/Methods, Overriding Methods) -For all classes, you need to provide...
Chapter 9 Programming Project (Inheritance, Abstract Class/Methods, Overriding Methods) -For all classes, you need to provide the accessor and mutator methods for all instance variables, and provide/override the toString methods. -Create a Customer class that has the attributes of name and age. Provide a method named importanceLevel. Based on the requirements below, I would make this method abstract. -Extend Customer to two subclasses: FlightCustomer, and RetailCustomer -FlightCustomer attributes: ticketPrice, seatNumber (The seat number should be a randomly generated number between...
This is a discussion question for my csc 252 computer programming c++ visual studio so post...
This is a discussion question for my csc 252 computer programming c++ visual studio so post in c++ visual studio so that i can copy and paste thank you. In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition....
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio development environment 3. To practice on writing a C# program Task 1: Create documentation for the following program which includes the following: a. Software Requirement Specification (SRS) b. Use Case Task 2: Write a syntactically and semantically correct C# program that models telephones. Your program has to be a C# Console Application. You will not implement classes in this program other than the class...
answer the following using C# Design and program a Visual Studio Console project in C# that...
answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT