當我運行它時,我所能做的就是編寫員工姓名和銷售額,但它不使用第二類,並使用它信息。有人能幫助我嗎?我一直在爲此苦苦掙扎!我不能使用我的第二課,真的不確定如何解決它
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();
}
}
}
你或許應該某處創建第二類的實例.. – 2014-09-26 03:12:33
二等細節不是你的代碼,你可以怎麼過創建第二類的對象,然後訪問屬性中提到。 – Prabhakantha 2014-09-26 03:19:14