我对编程主题非常陌生。从我学习主题的两篇文章来看。我正在尝试做这个程序但我有一些错误。可以任何人帮助我解决这个问题。 [英] I Am Very New To Programming Subject .Past From 2 Fews I M Learning The Subject. I Am Trying To Do This Program But I Got Some Error .Could Anyone Help Me To Slove This One .

查看:66
本文介绍了我对编程主题非常陌生。从我学习主题的两篇文章来看。我正在尝试做这个程序但我有一些错误。可以任何人帮助我解决这个问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一个类来编写程序,该类可以获取有关员工名单,姓名,地址,密码,电话号码,总薪水和pf的信息。显示净工资(即毛减去pf)并根据净工资计算等级。成绩是

等级''A'sal> 10000

等级-'B'sal> 5000

等级''C'sal< 5000

我的代码:

Write a program using a class that get information about employee rollno, name, address, pin code, phone number, gross salary and pf. Display the net salary (ie gross less pf) and calculate grade base on net salary. The grades are
Grade-‘A’ sal>10000
Grade-‘B’ sal>5000
Grade-‘C’ sal<5000
My code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmployeeClass
{
    class EmployeeClass
    {
        private int _EmployeeID;
        private double _GrossPay;
        private double _PF;
        private int _Pincode;
        private double _PhoneNumber;
        private string _EmployeeName;
        private double _EmployeeAdress;


        public int employeeId
        {
            get
            {
                return _EmployeeID;
            }
            set
            {
                _EmployeeID = value;
            }

        }


        public double grosspay
        {
            get
            {
                return _GrossPay;
            }
            set
            {
                _GrossPay = value;
            }

        }

        public double pf
        {
            get
            {
                return _PF;
            }
            set
            {
                _PF = value;
            }

        }

        public int pincode
        {
            get
            {
                return _Pincode;
            }
            set
            {
                _Pincode = value;
            }

        }
        public double phonenumber
        {
            get
            {
                return _PhoneNumber;
            }
            set
            {
                _PhoneNumber = value;
            }

        }

        public string employeename
        {
            get
            {
                return _EmployeeName;
            }
            set
            {
                _EmployeeName = value;
            }

        }

        public double employeeaddress
        {
            get
            {
                return _EmployeeAdress;
            }
            set
            {
                _EmployeeAdress = value;
            }

        }
        public EmployeeClass(string EName, int EId, int Pincode, int phoneN,double Address, double pf, double grosspay)
        {
            this._EmployeeName = EName;
            this._EmployeeID = EId;
            this._Pincode = Pincode;
            this._PhoneNumber = phoneN;
            this._EmployeeAdress = Address;
            this._PF = pf;
            this._GrossPay = grosspay;
        }

        public double CalculateSalary()
        {
            double netsalary = (this._GrossPay - this._PF);
            return netsalary;
        }
        public void CalculateGrade(string grade, double netsalary)
        {


            if (netsalary > 1000)
            {
                grade = "A";
            }
            else if (netsalary > 5000)
            {
                grade = "B";
            }
            else if (netsalary < 5000)
            {
                grade = "C";
            }

        }








   static void Main(string[] args)
        {
            EmployeeClass em = new EmployeeClass("Pavan", 123, 48858, 81516615, 303, 1000, 20000);
            em.CalculateSalary();
       Console.WriteLine("The Net Salary of an Employee is {0}",em.CalculateSalary());
          Console.WriteLine("The grade of an Employee is {0}",em.CalculateGrade("A",em.CalculateSalary());

        }
    }
}

推荐答案

你错过了0.

You are missing a 0.
if (netsalary > 10000)
          {
              grade = "A";
          }
          else if (netsalary >= 5000)
          {
              grade = "B";
          }
          else if (netsalary < 5000)
          {
              grade = "C";
          }


您的方法存在一些问题 CalculateGrade()



  • 第一个条件(等级A的检查)应该使用10000而不是1000。
  • 该方法应该返回计算等级 - 即使返回类型字符串,而不是 void 并且不需要
  • 该方法实际上不需要任何参数,因为可以使用您的类的现有方法计算净工资。
  • 确保如果A级和B级条件不匹配,您的方法将返回一个值。
There are some problems with your method CalculateGrade():

  • The first condition (the check for grade "A") should use 10000, not 1000.
  • The method should return the computed grade - i.e. make the return type string, not void and don't require a grade argument.
  • The method actually doesn't require any arguments, since the net salary can be computed using your class' existing method.
  • Make sure your method returns a value if the grade A and grade B conditions don't match.


这篇关于我对编程主题非常陌生。从我学习主题的两篇文章来看。我正在尝试做这个程序但我有一些错误。可以任何人帮助我解决这个问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆