Question

In: Computer Science

~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding...

~~~USING C# ONLY~~~

Create a console application

Design a class named Person with properties for holding a person’s name, address, and telephone number.

Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount.

All 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% discount on all future purchases.
  • When a preferred customer spends $1000, he or she gets a 6% discount on all future purchases.
  • When a preferred customer spends $1500, he or she gets an 8% discount on all future purchases.
  • When a preferred customer spends $2000, he or she gets a 10% discount on all future purchases.

Design a class named PreferredCustomer, which is derived from the Customer class. The PreferredCustomer class should have a variable, discountLevel, with a read-only property. It alsoincludes a setDiscountLevel function that determine the discount level based on the purchases amount using switch statement and an override function, calcAmount, calculates the spentAmount with the current discount level.

Create a CustomerDemo class. In the main function, the program calls the getData function to read the data from the “CustomerInfo.txt” file and create a dynamic array of PreferredCustomer object. Then, it prompts user to enter a customer number and displays a menu:

  1. Display Customer Information: display the specific customer information
  2. Update Spent Amount: update the total amount with the correct discount level

After update the spent Amount, the program writes the updated information back to file.

Solutions

Expert Solution

SOLUTION -

I have solve the problem in C# code with comments and screenshot for easy understanding :)

Screenshot

Program

using System;
using System.IO;

namespace CustomerDemo
{
    //MAin Program
    class Program
    {
        static void Main(string[] args)
        {
            //Array to store customers
            PrefferedCostumer[] pc = new PrefferedCostumer[] { };
            pc=getData();
            //Loop until exit
            while (true)
            {
                //Each option
                Console.WriteLine("OPTIONS:-\n1. Display Cutomer Information\n2. Update Spend Amount\n3. Exit");
                int opt = Convert.ToInt32(Console.ReadLine());
                //ErrorEventArgs check
                while(opt<1 || opt > 3)
                {
                    Console.WriteLine("\nIncorrect option|||\n");
                    Console.WriteLine("\nOPTIONS:-\n1. Display Cutomer Information\n2. Update Spend Amount\n3. Exit");
                    opt = Convert.ToInt32(Console.ReadLine());
                }
                //Execute options
                if (opt == 1)
                {
                    bool check = false;
                    //Get customer number
                    Console.WriteLine("\nEnter customer number: ");
                    string number = Console.ReadLine();
                    //If match display details
                    for(int i = 0; i < pc.Length; i++)
                    {
                        if (pc[i].GetNumber.CompareTo(number) == 0)
                        {
                            Console.WriteLine(pc[i]);
                            check = true;
                            break;
                        }
                    }
                    if (check == false)
                    {
                        Console.WriteLine("\nNot found!!!\n");
                    }
                }
                else if (opt == 2)
                {
                    bool check = false;
                    //Get customer number
                    Console.WriteLine("\nEnter customer number: ");
                    string number = Console.ReadLine();
                    //If match get cutomer spend amout and write into file
                    for (int i = 0; i < pc.Length; i++)
                    {
                        if (pc[i].GetNumber.CompareTo(number) == 0)
                        {
                            Console.WriteLine("Enter spend amount: ");
                            double amt = Convert.ToDouble(Console.ReadLine());
                            pc[i].GetSpend = amt;
                            pc[i].setDiscount();
                            pc[i].calculateAmt();
                            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:/Users/deept/source/repos/CustomerDemo/CustomerDemo/CustomerInfo.txt"))
                            {
                                file.WriteLine(pc.Length);
                                foreach (PrefferedCostumer p in pc)
                                {
                                    file.WriteLine(p);
                                }
                            }
                            check = true;
                            break;
                        }
                    }
                    if (check == false)
                    {
                        Console.WriteLine("\nNot found!!!\n");
                    }
                }
                else if (opt == 3)
                {
                    break;
                }
            }
        }
        //Method read data from file and store into array and return array
        static PrefferedCostumer[] getData()
        {
            PrefferedCostumer p=new PrefferedCostumer();
            PrefferedCostumer[] pc = new PrefferedCostumer[] { };
            using (StreamReader file = new StreamReader("C:/Users/deept/source/repos/CustomerDemo/CustomerDemo/CustomerInfo.txt"))
            {
                int counter = 0,i=0;
                string ln;
                int cnt = Convert.ToInt32(file.ReadLine());
                pc = new PrefferedCostumer[cnt];
                while ((ln = file.ReadLine()) != null)
                {
                    if (i == 0)
                    {
                        p.GetName = ln;
                        i++;
                    }
                    else if (i == 1)
                    {
                        p.GetAddress = ln;
                        i++;
                    }
                    else if (i == 2)
                    {
                        p.GetPhone = ln;
                        i++;
                    }
                    else if (i == 3)
                    {
                        p.GetNumber = ln;
                        i++;
                    }
                    else if (i == 4)
                    {
                        p.GetEmail = ln;
                        i++;
                    }
                    else if (i == 5)
                    {
                        p.GetSpend = Convert.ToDouble(ln);
                        i++;
                    }
                    else if (i == 6)
                    {
                        p.GetMail =ln;
                        pc[counter] = new PrefferedCostumer(p.GetName,p.GetAddress,p.GetPhone,p.GetNumber,p.GetEmail,p.GetSpend,bool.Parse(p.GetMail));
                        i=0;
                        counter += 1;
                    }
                }
                file.Close();
                return pc;
            }
        }
    }
    //Base class
    class Person
    {
        //Attributes
        private string name, phoneNum, address;
        // Default Constructor
        public Person()
        {
            name = phoneNum = address = "";
        }
        //Parameterized constructor
        public Person(string n,string a,string p)
        {
            name = n;
            phoneNum = p;
            address = a;
        }
        //Getters and setters
        public string GetName
        {
            get { return name; }
            set
            {
                name = value;
            }
        }
        public string GetPhone
        {
            get { return phoneNum; }
            set
            {
               phoneNum = value;
            }
        }
        public string GetAddress
        {
            get { return address; }
            set
            {
                address = value;
            }
        }
        //Get details as string
        public override string ToString()
        {
            return name + "\n" + address + "\n" + phoneNum ;
        }
    }
    //Derived class
    class Customer : Person
    {
        //Attributes
        private string number;
        private string email;
        private double spendAmt;
        private bool mailingListWish;
        //Default constructor
        public Customer(): base()
        {
            number="";
            email="";
            spendAmt=0;
            mailingListWish=false;
        }
        //DParameterized constructor
        public Customer(string n, string a, string p,string num,string em,double sAmt,bool wish) : base(n,a,p)
        {
            number = num;
            email = em;
            spendAmt = sAmt;
            mailingListWish = wish;
        }
        //Getters and setters
        public string GetNumber
        {
            get { return number;}
            set { number = value; }
        }
        public string GetEmail
        {
            get { return email; }
            set { email = value; }
        }
        public double GetSpend
        {
            get { return spendAmt; }
            set { spendAmt = value; }
        }
        public string GetMail
        {
            get { if (mailingListWish) return "true"; else return "false"; }
            set { if (value=="true") mailingListWish=true; else mailingListWish=false; }
        }
        //Details a string representation
        public override string ToString()
        {
            return base.ToString() + "\n" + number + "\n" + email + "\n" + spendAmt.ToString() + "\n" + GetMail;
        }
        //Overriding function for spend amount calculation
        public virtual void calculateAmt() { }
    }
    //Derived class
    class PrefferedCostumer : Customer
    {
        //Attribute
        private double discountLevel;
        //Constructors
        public PrefferedCostumer() : base() { }
        public PrefferedCostumer(string n, string a, string p, string num, string em, double sAmt, bool wish) : base(n,a,p,num,em,sAmt,wish) { }
        //Read only property
        public double GetDiscount { get { return discountLevel; } }
        //SetDiscount property
        public void setDiscount()
        {
            switch (base.GetSpend)
            {
                case 500:
                    discountLevel = .05;
                    break;
                case 1000:
                    discountLevel = .06;
                    break;
                case 1500:
                    discountLevel = .08;
                    break;
                case 2000:
                    discountLevel = .10;
                    break;
                default:
                    discountLevel = 0;
                    break;
            }
        }
        //Calculate spend amount
        public override void calculateAmt() { base.GetSpend = base.GetSpend - (base.GetSpend * discountLevel); }
    }
}

The CustomerInfo.txt file is:

5
Anna Alaniz
123 10th st, McAllen, TX 78504
956-456-7899
A0000001
aalaniz @ g mail.com
2500
true
Bob Ho
456 15th st, McAllen, TX 78504
956-456-1000
A0000002
bobho @ g mail.com
2500
true
Hector Alcoser
2004 44th st, McAllen, TX 78501
956-456-5555
A0000003
hAlcoser @ g mail.com
495
false
Jorge Lee
123 10th st, McAllen, TX 78504
956-555-6666
A0000004
jlee @ g mail.com
1200
true
Pablo Gonzalez
777 2th st, McAllen, TX 78502
956-100-2000
A0000005
pGonzalez @ yahoo.com
1750
false


Output

OPTIONS:-
1. Display Cutomer Information
2. Update Spend Amount
3. Exit
1

Enter customer number:
A0000001
Anna Alaniz
123 10th st, McAllen, TX 78504
956-456-7899
A0000001
aalaniz @ g mail.com
2500
true
OPTIONS:-
1. Display Cutomer Information
2. Update Spend Amount
3. Exit
2

Enter customer number:
A0000001
Enter spend amount:
2600
OPTIONS:-
1. Display Cutomer Information
2. Update Spend Amount
3. Exit
1

Enter customer number:
A0000001
Anna Alaniz
123 10th st, McAllen, TX 78504
956-456-7899
A0000001
aalaniz @ g mail.com
2600
true
OPTIONS:-
1. Display Cutomer Information
2. Update Spend Amount
3. Exit
3
Press any key to continue . . .


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount. All...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(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 and...
C# Create a console application named that creates a list of shapes, uses serialization to save...
C# Create a console application named that creates a list of shapes, uses serialization to save it to the filesystem using XML, and then deserializes it back: // create a list of Shapes to serialize var listOfShapes = new List<Shape> { new Circle { Colour = "Red", Radius = 2.5 }, new Rectangle { Colour = "Blue", Height = 20.0, Width = 10.0 }, new Circle { Colour = "Green", Radius = 8 }, new Circle { Colour = "Purple",...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Using C#: Write a class named Employee that has the following properties: Name - The Name...
Using C#: Write a class named Employee that has the following properties: Name - The Name property holds the employee's name IdNumber - The IdNumber property holds the employee's ID number Department - The Department property holds the name of the department in which the employee works Position - The Position property holds the employee's job title The class should have the following overloaded constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
with C# create a console application project that outputs the number of bytes in memory that...
with C# create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal. Try formatting the values into a nice-looking table! More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application. Your output should look...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT