Question

This must be written in C# with overloaded constructors and member initialization list 4. Person and...

This must be written in C# with overloaded constructors and member initialization list

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 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. 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 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 $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 or more, 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 Programming Problem 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Person.cs

namespace CheggConsoleApplication
{
class Person
{
// Properties for data members
public string Name { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }

// Constructor to initialize data members
public Person(string name, string address, string telephone)
{
Name = name;
Address = address;
Telephone = telephone;
}

// Return detail of Person
public override string ToString()
{
return "Name: " + Name +
"\nAddress: " + Address +
"\nTelephone Number: " + Telephone;
}
}
}

Customer.cs

namespace CheggConsoleApplication
{
class Customer : Person
{
// Properties for data members
public int CustomerNumber { get; set; }
public bool MailingList { get; set; }

// Constructor to initialize data members. Call base class constructor
public Customer(string name, string address, string telephone, int customerNumber, bool mailingList) : base(name, address, telephone)
{
CustomerNumber = customerNumber;
MailingList = mailingList;
}

// Return detail of Customer and call super class method too
public override string ToString()
{
return base.ToString()+"\nCustomer Number: " + CustomerNumber
+ "\nMailing List: " + MailingList;
}
}
}

PreferredCustomer.cs

namespace CheggConsoleApplication
{
class PreferredCustomer : Customer
{   
// Properties for data members
public double Purchases { get; set; }
public double Discount { get; set; }

// Constructor to initialize data members. Call base class constructor
public PreferredCustomer(string name, string address, string telephone, int customerNumber, bool mailingList, double purchases)
: base(name, address, telephone, customerNumber, mailingList)
{
Purchases = purchases;
setDiscount();
}

// Method to set Discount level
public void setDiscount()
{
if (Purchases >= 2000)
{
Discount = 10;
}else if (Purchases >= 1500)
{
Discount = 7;
}else if (Purchases >= 1000)
{
Discount = 6;
}else if(Purchases >= 500)
{
Discount = 5;
}else
{
Discount = 0;
}
}

// Return detail of PreferredCustomer and call super class method too
public override string ToString()
{
return base.ToString()+"\nPurchases: $" + Purchases +
"\nDiscount: " + Discount+"%";
}
}
}

PersonTest.cs

using System;

namespace CheggConsoleApplication
{
class PersonTest
{
static void Main(string[] args)
{
// Create customer object to test
Customer cust = new Customer("Jane","22B, Baker Street","93748272038",123,true);
Console.WriteLine(cust);
Console.WriteLine();

// Create PreferredCustomer to test
PreferredCustomer pc = new PreferredCustomer("John","12/34 H-Block","423979302",111,false,1999);
Console.WriteLine(pc);
  
}
}
}

OUTPUT-

Add a comment
Know the answer?
Add Answer to:
This must be written in C# with overloaded constructors and member initialization list 4. Person and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use Java Question 3: Person and Customer classes: Design a class named Person with properties...

    Please use Java Question 3: 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 from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether wishes to be on a mailing list. Demonstrate an object of customer class in a simple GUI application. Write the code include appropriate input validation,...

  • this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...

    this is java m. please use netbeans if you can. 7. Person and Customer Classes Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the cus- tomer wishes to...

  • Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to...

    Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to create Person, Customer classes described in the previous problem) Access A6 from pdf assignment file. Turn in the following files: a6main.java Customer.java Person.java PreferredCustomer.java program compile and run screenshots design document (including UML) A6 7. Person and Customer Classes esign a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator...

  • This is a C++ program Instructions Design a class named PersonData with the following member variables...

    This is a C++ program Instructions Design a class named PersonData with the following member variables declared as strings: lastName firstName address city state zip phone Create 3 constructors; a default constructor, a constructor that accepts the first and last name member variables, and a constructor that accepts all member variables. Write the appropriate accessor/getter and mutator/setter functions for these member variables. Create a method within this class called getFullName() that returns the person's first and last names as a...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using JAVA* Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator...

  • Program must be written in C++: Create a parent class called CompSciProfessor. Each professor has name...

    Program must be written in C++: Create a parent class called CompSciProfessor. Each professor has name (type string), email (type string), and facultyId (type long). Specialize the CompSciProfessor class into two more classes: AdjunctProf, and TenureTrackProf classes. The specialized class AdjunctProf has three attributes of its own: degree (type char), NoOfTA (type int), and NoOfCourses (type int). The attribute ‘degree’ refers to the degree of the adjunct professor. You assign ‘B’ to represent bachelor degree, ‘M’ for Master degree, and...

  • 36. Trespass to land is committed if, without the permission of the property owner, a person...

    36. Trespass to land is committed if, without the permission of the property owner, a person a. enters the property to assist someone in danger. b. causes water to back up onto the property. c. has a revocable license to come onto the property. d. all of the choices. 37. Tom and Bob are best friends and are on the school baseball team. Tom thinks Bob has great reflexes, so when he passes him in the hallway he yells, "Thank...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

  • This simple practical task is the start of a series of exercises in which you will...

    This simple practical task is the start of a series of exercises in which you will develop a small bank- ing system applying all important OOP concepts. Your first task is to complete the Account class, one of the core classes of the future program. You will need to focus on the use of classes and ob- jects and the ability to capture knowledge and behaviour within objects. The banking system you are developing must have an account, which allows...

  • For Java Program In this lab you will gain experience using all the concepts we learned...

    For Java Program In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team programming. This assignment will be completed by teams of 2. Each member must complete an equal amount of the work in order to receive credit for this assignment. You must write the programmer’s name in a comment for each method you write. You need to create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT