Question

In: Computer Science

Create an application named SalesLeader. Add a class to your project called SalesPerson. (The default class...

Create an application named SalesLeader.

Add a class to your project called SalesPerson. (The default class may be called Program. Do not change this)

The SalesPerson class contains the following Properties:

FirstName - The salesperson's firs name (as a string)

SalesAmount - The sales amount ( as a double)

SalesArea - The 3 areas are the enumeration West Coast, MidWest, and East Coast.

Add a constructor which sets FirstName to "None", SalesAmount to 0 and SalesArea to MidWest.

Add a method which checks if the SalesAmount is greater than $100,000. If so, add 10% to the SalesAmount.

In the main class (Program), create the following:

Create 3 objects from SalesPerson.

                salesperson1

                salesperson2

                salesperson3

Prompt the user to set the amount of sales, first name and sales area for each object.

Display the name, sales amount and area for each sales person. Display which sales person is the Sales Leader this month and their commission (15% of total sales) … but first, add a method SalesLeaderTie to Program class to check if there might be a tie for Sales Leader. (Write Code in C#).

Solutions

Expert Solution

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new Console Application in C# is created using Visual Studio 2019 with name "SalesLeader".This application contains a form with class "Program.cs".Below is the details of this class.

SalesPerson.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace SalesLeader
{
//enum
enum areas
{
WestCoast,
MidWest,
EastCoast
};
class SalesPerson //C# class
{
//properties
public string FirstName { get; set; }
public double SalesAmount { get; set; }
public areas SalesArea { get; set; }

//constructor
public SalesPerson()
{
FirstName = "none";
SalesAmount = 0;
SalesArea = areas.MidWest;
}
//method to check sales amount
public void checkAmount()
{
//checking saleAmount
if(SalesAmount>100000)
{
//if SalesAmount is greater than 10% the add 10% to SaleAmount
SalesAmount = SalesAmount + SalesAmount * 0.10;
}
}
}
}

*************************************

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace SalesLeader
{
class Program //C# class
{
static void Main(string[] args) //entry point , Main() method
{
//creating object of SalesPerson
SalesPerson salesperson1 = new SalesPerson();
SalesPerson salesperson2 = new SalesPerson();
SalesPerson salesperson3 = new SalesPerson();
//asking user details
Console.WriteLine("---SalesPerson 1 details-");
Console.Write("Enter First Name :");//asking firstname
salesperson1.FirstName = Console.ReadLine();//reading firstName
Console.Write("Enter SalesAmount :");//asking SalesAmount
salesperson1.SalesAmount = double.Parse(Console.ReadLine());//reading SalesAmount
Console.Write("Enter Sales area (enter either 0,1 or 2):");//asking sales area
salesperson1.SalesArea =(areas) int.Parse(Console.ReadLine());//reading SalesAmount
Console.WriteLine("---SalesPerson 2 details-");
Console.Write("Enter First Name :");//asking firstname
salesperson2.FirstName = Console.ReadLine();//reading firstName
Console.Write("Enter SalesAmount :");//asking SalesAmount
salesperson2.SalesAmount = double.Parse(Console.ReadLine());//reading SalesAmount
Console.Write("Enter Sales area (enter either 0,1 or 2) :");//asking sales area
salesperson2.SalesArea = (areas)int.Parse(Console.ReadLine());//reading SalesAmount
Console.WriteLine("---SalesPerson 3 details-");
Console.Write("Enter First Name :");//asking firstname
salesperson3.FirstName = Console.ReadLine();//reading firstName
Console.Write("Enter SalesAmount :");//asking SalesAmount
salesperson3.SalesAmount = double.Parse(Console.ReadLine());//reading SalesAmount
Console.Write("Enter Sales area (enter either 0,1 or 2):");//asking sales area
salesperson3.SalesArea = (areas)int.Parse(Console.ReadLine());//reading SalesAmount
//display details
Console.WriteLine("\n----Details for salespersons----");
Console.WriteLine(salesperson1.FirstName + "," + salesperson1.SalesAmount +","+salesperson1.SalesArea.ToString());
Console.WriteLine(salesperson2.FirstName + "," + salesperson2.SalesAmount + "," + salesperson2.SalesArea.ToString());
Console.WriteLine(salesperson3.FirstName + "," + salesperson3.SalesAmount + "," + salesperson3.SalesArea.ToString());
//call methot to check salesAmount
salesperson1.checkAmount();
salesperson2.checkAmount();
salesperson3.checkAmount();
//call method to check tie
if(SalesLeaderTie(salesperson1,salesperson2,salesperson3))
{
//if their is not tie then
if(salesperson1.SalesAmount > salesperson2.SalesAmount && salesperson1.SalesAmount > salesperson3.SalesAmount)
{
//if salesperson1 salesAmount is greater than salesperson2 and salesperson3 salesAmount then
//salesperson1 is Sales Leader this month,
//calculate commission
double comission = salesperson1.SalesAmount * 0.15;
//print details
Console.WriteLine(salesperson1.FirstName+" is leader for this month with comission of "+comission);
}
else if (salesperson2.SalesAmount > salesperson3.SalesAmount && salesperson2.SalesAmount > salesperson1.SalesAmount)
{
//if salesperson2 salesAmount is greater than salesperson1 and salesperson3 salesAmount then
//salesperson2 is Sales Leader this month,
//calculate commission
double comission = salesperson2.SalesAmount * 0.15;
//print details
Console.WriteLine(salesperson2.FirstName + " is leader for this month with comission of " + comission);
}
else if (salesperson3.SalesAmount > salesperson1.SalesAmount && salesperson3.SalesAmount > salesperson2.SalesAmount)
{
//if salesperson3 salesAmount is greater than salesperson1 and salesperson2 salesAmount then
//salesperson3 is Sales Leader this month,
//calculate commission
double comission = salesperson3.SalesAmount * 0.15;
//print details
Console.WriteLine(salesperson3.FirstName + " is leader for this month with comission of " + comission);
}
//to hold the screen
Console.ReadKey();

}


}
//method to check for the tie
public static bool SalesLeaderTie(SalesPerson salesperson1, SalesPerson salesperson2, SalesPerson salesperson3)
{
bool flag = true;
//checking for the tie
if(salesperson1.SalesAmount==salesperson2.SalesAmount && salesperson1.SalesAmount == salesperson3.SalesAmount && salesperson2.SalesAmount == salesperson3.SalesAmount)
{
//if salesAmount for three salesPerson are equal then
Console.WriteLine("All three sales person having equal sales Amount hence tie.");
flag = false;//set flag to false
}
else if(salesperson1.SalesAmount == salesperson2.SalesAmount && salesperson3.SalesAmount< salesperson2.SalesAmount)
{
//if salesAmount for salesperson1 and salesperson2 are equal then
Console.WriteLine("There is tie between salesperson1 and salesperson2 ");
flag = false;//set flag to false
}
else if (salesperson1.SalesAmount == salesperson3.SalesAmount && salesperson2.SalesAmount < salesperson1.SalesAmount)
{
//if salesAmount for salesperson1 and salesperson3 are equal then
Console.WriteLine("There is tie between salesperson1 and salesperson3 ");
flag = false;//set flag to false
}
else if (salesperson2.SalesAmount == salesperson3.SalesAmount && salesperson1.SalesAmount < salesperson3.SalesAmount)
{
//if salesAmount for salesperson2 and salesperson3 are equal then
Console.WriteLine("There is tie between salesperson2 and salesperson3 ");
flag = false;//set flag to false
}
return flag;
}
}
}

==================================

Output :Run application using F5 and will get the screen as shown below

Screen 1:

Screen 2:

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Create a project called rise. Add a class called GCD. Complete a program that reads in...
Create a project called rise. Add a class called GCD. Complete a program that reads in a numerator (as an int) and a denominator (again, as an int), computes and outputs the GCD, and then outputs the fraction in lowest terms. Write your program so that your output looks as close to the following sample output as possible. In this sample, the user entered 42 and 56, shown in green. Enter the numerator: 42 Enter the denominator: 56 The GCD...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert number grades to letter grades and another class for data validation. Make comments including your name, date, and project name as well as appropriate comments throughout your application that include the step number. Step 2: Create code to print Titles Step 3: Create a variable to hold user’s choice. Remember that all variables must begin with your initials and should be descriptive. Step 4:...
Step 1: Create a new Java project named ContainerPartyProject --------- Step 2: Add a ContainerParty class...
Step 1: Create a new Java project named ContainerPartyProject --------- Step 2: Add a ContainerParty class to your project. It should contain:             - The date of the party             - A list of people attending             - A list of containers at the party             - The address of the party (this can be either a String or a Class) --------- Step 3: Add a Container class in your project. It should be an abstract class. Your Container class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT