Question

In C#, Write an application to determine the bonus of a sales person. The sales person...

In C#, Write an application to determine the bonus of a sales person. The sales person receives a 5% bonus on sales $1,000,000 or over and 4% of sales under $1,000,000. They also receive an additional bonus for their pay code. Pay code 1 additional $2500, pay code 2 additional $2000, pay code 3 additional $1500, and pay code 4 additional $1000. The user will be prompted to enter the salesperson’s name, sales, and code.

Create a class to calculate the bonus using an if statement to determine the bonus; a Switch statement to determine the additional bonus; and the override ToString() method with string.format to return the results. Create a Boolean data type for bad data. In class If sales are <= to 0 or a code other than 1,2,3,4 is entered, return “Bad Data”. Create Properties to receive data from class. Use curly braces for all if statements and follow C# Coding Standards. First if statement, check for sales >0. Do not need to display heading or instructions.

Homework Answers

Answer #1

// C# program to create an application to determine the bonus of a sales person.

using System;

// class to hold salesperson data
class Salesperson
{
   // properties
private string name;
private double sales;
private int code;
private bool badData;
  
   // constructor to create initailize the values for the attributes
public Salesperson(string name, double sales, int code)
{
badData = false;
this.name = name;
this.sales = sales;
if(sales <= 0) // invalid sales
badData = true;
this.code = code;
if(code < 1 || code > 4) // invalid code
badData = true;
}
  
   // return the name
public string getName()
{
return name;
}
  
   // return the sales
public double getSales()
{
return sales;
}
  
   // return the code
public int getCode()
{
return code;
}
  
   // method to calculate and return the bonus for the salesperson
public double calculateBonus()
{
double bonus = 0;
if(badData) // if invalid data, return 0
           return 0;
          
       if(sales >= 1000000) // if sales >= 1,000,000 bonus on sales is 5%
bonus = sales*0.05;
else    // else bonus on sales is 4%
bonus = sales*0.04;
  
       // additional bonus on code  
switch(code)
{
case 1:
bonus += 2500;
break;
  
case 2:
bonus += 2000;
break;
  
case 3:
bonus += 1500;
break;
  
case 4:
bonus += 1000;
break;
}
  
return bonus;
}
  
// return string representation of the object
public override string ToString()
{
if(badData) // invalid data
return "Bad Data";
else
return "Name: "+name+"\nSales: "+sales.ToString("0.00")+"\nCode: "+code+"\nBonus: "+calculateBonus().ToString("0.00");
}
} //end Salesperson class

class Salesperson_Bonus {

static void Main() {

   string name;
double sales;
int code;
// input the salesperson name, sales and code
   Console.Write("Enter salesperson name: ");
name = Console.ReadLine();
Console.Write("Enter salesperson sales: ");
sales = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter salesperson code: ");
code = Convert.ToInt32(Console.ReadLine());
// create an object of Salesperson class
Salesperson person = new Salesperson(name, sales, code);
// display the details of the salesperson
   Console.WriteLine(person.ToString());
}
}

//end of program

Output:

Know the answer?
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
Similar Questions
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
QUESTION 1 1. Brianna is trying to increase her chances of being promoted to vice president...
QUESTION 1 1. Brianna is trying to increase her chances of being promoted to vice president by working to build good work relationships with other managers outside her own department. Brianna's behavior should be viewed as dysfunctional politics. functional politics. coercive power. functional influence. 2 points QUESTION 2 1. The Gingerbread Factory has a separate unit that makes their chocolate crunch cookies and another unit that is completely responsible for all operations in producing their ginger snap cookies. The Gingerbread...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT