我可以';我没有利用我的第二堂课,真的不知道该怎么解决
本文关键字:真的不知道 解决 我的 我可以 | 更新日期: 2023-09-27 18:24:28
当我运行它时,我所能做的就是写员工姓名和销售额,但它不使用第二个类并使用这些信息。有人能帮帮我吗?我已经在这上面挣扎了一段时间了!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace consoleapplication9
{
public class takehomepay
{
static void Main(String[] args)
{
const decimal commission = 0.7M; // Commision rate
const decimal federaltax = 0.18M; // federal tax rate
const decimal retirement = 0.10M; // retirement rate
const decimal socialsecurity = 0.06M; // social security rate
string employeeName;
decimal commcost = 0; // commision cost
decimal fedtaxcost = 0; // federal tax cost
decimal retirecost = 0; // retirement cost
decimal socseccost = 0; // social security cost
decimal totalwithholdingcost = 0; // total withholding
decimal takehomepay = 0; // amount taken home
decimal totalSales = 0;
Console.Write("'nEnter employees name: ");
employeeName = Console.ReadLine();
Console.Write("Enter the total sales amount for the week:");
totalSales = Convert.ToDecimal(Console.ReadLine());
//Calculations
commcost = commission * totalSales;
fedtaxcost = federaltax * commcost;
retirecost = retirement * commcost;
socseccost = socialsecurity * commcost;
totalwithholdingcost = federaltax + retirement + socialsecurity;
takehomepay = commcost - totalwithholdingcost;
}
}
public class Employee
{
private string employeeName;
private decimal totalSales;
public Employee()
{
}
public Employee ( string Name)
{
employeeName = Name;
}
public Employee( string Name, decimal Sales)
{
employeeName = Name;
totalSales = Sales;
}
public string EmployeeName
{
get
{
return employeeName;
}
set
{
employeeName = value;
}
}
public decimal TotalSales
{
get
{
return totalSales;
}
set
{
totalSales = value;
}
}
public override string ToString()
{
return "Employee: " + employeeName +
"'nTotal Sales: " + totalSales;
Console.Read();
}
}
}
您需要通过新建对象(Employee)来调用类的构造函数
Console.Write("'nEnter employees name: ");
employeeName = Console.ReadLine();
Console.Write("Enter the total sales amount for the week:");
totalSales = Convert.ToDecimal(Console.ReadLine());
//Create an instance of your second class...
var employee = new Employee(employeeName,totalSales);
Console.Write(employee);
如果您需要任何变量的输出,您需要将它们写入控制台:
Console.WriteLine(takehomepay);
而不是
employeeName = Console.ReadLine();
尝试
Employee employee = new Employee();// this creates an instance of the employee class
employee.EmloyeeName = Console.ReadLine();// this is how you use that instance