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
  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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) {...

  • Chel Lynn Ally, owner of a local Subway shop, loaned $46,000 to Pete Hall to help...

    Chel Lynn Ally, owner of a local Subway shop, loaned $46,000 to Pete Hall to help him open a Subway franchise. Pete plans to repay Lynn at the end of 7 years with 4% interest compounded semiannually. How much will Lynn receive at the end of 7 years? (Do not round intermediate calculations. Round your answer to the nearest cent.) Future value 2. Key Steps in the Personal Selling Process Key Steps in the Personal Selling Process Selling is a...

  • 1) When employing the self-defeating test, you must ask yourself   (A) is the action self-defeating if...

    1) When employing the self-defeating test, you must ask yourself   (A) is the action self-defeating if everyone did it because the action could not be performed if everyone did it    (B) is the action self-defeating if everyone did it because the purpose you have in performing the action would be undermined (C) is the action self-defeating if everyone did it because there is no change in the amount of utility generated    (D) Both a and b. 2) The fundamental principle...

  • Hi, i just need the highlighted ones. Thank you! CHAPTER 1 Understanding Personal Finance 33 LET'S...

    Hi, i just need the highlighted ones. Thank you! CHAPTER 1 Understanding Personal Finance 33 LET'S TALK ABOUT IT 1. Economic Growth. What tpes of federal government Federal Reserve. Describe some economic circumstances that might persuade the Federal Reserve to lower short-term inter- ctfoets to help stimulate economic growth affect 2 The Business Cycle. Where is the United States in the economic cycle now, and where does it seem to be heading? List some indicators that suggest in which direction...

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
ADVERTISEMENT