本文介绍了类和对象真的很难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该作品摘自乔伊斯·法雷尔(Joyce Farrell)写的书.所以她真的没有知识,不是我的老师

[EDIT-代码转储已从OP的注释移至SA-

The work was from the book written by Joyce Farrell. So she doesn''t really have knowledge, not my teacher



using System;

class TaxPayer : IComparable<TaxPayer>
{
   private string ssn;
   private double grossIncome;
   private double taxOwed;

   public string SSN
   {
     get { return ssn; }
     set { ssn = value; }
   }

   public double GrossIncome
   {
     get { return grossIncome; }
     set
     {
        grossIncome = value;
        if (grossIncome < 30000)
           taxOwed = 0.15 * grossIncome;
        else
           taxOwed = 0.28 * grossIncome;
     }
  }

  public double TaxOwed
  {
     get{ return taxOwed; }
  }

  public TaxPayer(string ssn, double grossIncome)
  {
     this.ssn = ssn;
     GrossIncome = grossIncome; // need to set the property here, not the field directly
  }

  public override string ToString()
  {
     return String.Format("SSN = {0}, Income = {1,11:C}, Tax Owed = {2,10:C}", ssn, grossIncome, taxOwed);
  }

  public int CompareTo(TaxPayer other)
  {
     return this.taxOwed.CompareTo(other.taxOwed);
  }

}

class TaxPayerDemo
{
  static void Main()
  {
     TaxPayer[] taxPayers = new TaxPayer[10];
     string ssn;
     double grossIncome;
     Console.WriteLine("Please enter details for 10 taxpayers\n");

     for(int i = 0; i < 10; i++)
     {
        Console.WriteLine("Details for taxpayer #{0}", i + 1);
        Console.Write("   Enter Social Security Number : ");
        ssn = Console.ReadLine().Replace("-", ""); // get rid of any dashes
        Console.Write("   Enter Yearly Gross Income    : ");
        grossIncome = Convert.ToDouble(Console.ReadLine());
        taxPayers[i] = new TaxPayer(ssn, grossIncome);
        Console.WriteLine();
     }

     Console.WriteLine("The taxpayers and their details are\n");
     for(int i = 0; i < 10; i++) Console.WriteLine(taxPayers[i]);
     Array.Sort(taxPayers); // sorts the taxpayers in order of tax owed
     Console.WriteLine();
     Console.WriteLine("The taxpayers in order of tax owed are\n");
     for(int i = 0; i < 10; i++) Console.WriteLine(taxPayers[i]);

     Console.ReadKey();
  }
}

推荐答案


DaSasha写道:
DaSasha wrote:

您将还我的财政援助如果我放弃那门课程?我不这么认为,如果您不愿意的话,无需张贴[拼写和语法引文-SA]

you gonna pay my financial aid back if I drop that course? I don''t think so, if u not gonna help no need to post [Spelling and grammar quotes as is — SA]



尊敬的达萨沙,

首先,我坚持认为,我们将需要他的职位的决定留给SteveAdey.我谨希望您也能授予我类似的特权.

只需更彻底地考虑您的财务状况即可:

您不会免费获得经济援助.我很确定您将面临以下其中一种情况:1)需要全额偿还您的援助金,2)需要偿还这笔钱的一部分,而其余的钱将由政府或其他机构支付资金; 3)更有可能需要全额偿还您的援助金以及一些利息.

这笔钱或多或少地动摇了学生的假设,即他们能够完成学业,获得必要的经验,并以此方式获得一定的地位和声誉,这可以帮助他们获得合理的收入,足以维持生活并偿还生活费.债务.

让我们看看你的情况.您刚刚起步,只是获得了非常基础的知识.您不仅没有对最基本的任务有足够的信心(这根本不是问题,迟早会出现),您也没有表现出对激动人心的计算领域初学者非常典型的热情,恰恰相反,您表现出缺乏独立的行为,除了获胜",我不能称呼其他任何东西.大多数感兴趣的学生过高地估计了他们的能力,最好的学生充分地估计了他们的能力,但是谁抱怨说这项工作真的很辛苦"?我几乎从来没有观察到这种行为.也许这只是您真诚的沟通方式,但实际上对我来说这似乎是一个极端的弱点.

我对您的老师有进一步的担忧.如果要求使用字符串作为类型,但不要在数字中使用破折号"来自一位老师,则表明该老师对编程,质量,维护等方面几乎一无所知.这样的固定格式结构(如SSN),除了使用由数字成员组成的结构的某种适当的整数类型外,什么都不用,这是愚蠢的.即使目标是简化您的任务,也不会简化任何事情.你看,有一种我称之为教育欺诈"的东西.一切都是完全合法的,只有您为虚假的知识付钱,而您可能不够独立,无法感受到虚假的教育服务或自己学习.我不知道,也许您的老师只是软弱无力,但可能是假的.如果您无法抗拒和自己学习(这通常是学习的主要方式),则可以获得假知识和假经验.您认为您可以从中获得足够的钱吗?

那么,会发生什么呢?如果您改变职业道路,可以放一些钱,但是您有机会在其他一些活动中赚钱.如果您不这样做,则可以节省您的援助金,但是只能保留一段时间,因为无论如何您都必须偿还这笔款项.作为交换,您冒着浪费相当多的时间而感到沮丧的风险,并失去了赚钱的机会.您可能会陷入偿还债务的巨大麻烦,而不仅仅是提供生活.我知道,生活可能真的很艰难.实际上,这很难.

但是,我永远不知道.我不知道多少钱,我不知道您的真正风险.你决定.负责.

我最大的愿望是做错事.是的,我希望看到我做错了,您可以应对和改变事物,并在计算机领域取得辉煌的职业.我真的很希望你.我只会尝试帮助您了解其中涉及的内容.

请原谅我这个离题的帖子.我会看看是否能为您添加到帖子中的代码提供帮助.

最好的祝福,

—SA



Dear Da Sasha,

First of all, I insist that we leave the the decisions on the need for his posts to SteveAdey along. I would modestly hope that you would grant similar privilege to me as well.

Just think about your financial situation more thoroughly:

You don''t get financial aid for free. I''m pretty sure you will face one of the following: 1) a need to repay your aid money in full, 2) a need to re-pay part of this money while the rest of it will be covered by government or other funds; 3) more likely, a need to repay your aid money in full plus some interest.

The money is funded to the student in more or less shaky assumption that they are able to complete education, gain essential experience and in this way achieve some status and reputation which could help them to get reasonable earnings, sufficient for making for living and repay of the debt.

Let''s look at your situation. You are at the very beginning, just getting very basic knowledge. Not only you are not confident enough in the most elementary tasks (this is not a problem at all, it will come sooner or later) you don''t demonstrate the passion which is very typical for the beginners in the exciting field of computing, just the opposite, you demonstrate lack of independent behavior and something that I cannot call anything but "wining". Most interested students are over-estimate their capability, best students estimate them adequately, but who complains that the job is "really hard"? I almost never observe such behavior. Maybe this is just your sincere style of communication, but in fact it looks like an extreme weakness to me.

I have further concerns about your teacher. If the requirement "use a string for the type, but do not use dashes within the number" comes from a teacher, this is a strong indication that this teacher has very little idea about programming, its quality, maintenance, etc. The presentation of such a fixed-format structure as SSN using anything but some adequate integer type of a structure made of numeric members is plain stupid. Even if the goal would be to simplify your assignment — it does not simplify anything. You see, there is such thing which I call "education fraud". Everything is perfectly legal, only you pay your money for the fake knowledge while you might be not independent enough to feel the fake education services or learn by yourself. I don''t know, maybe your teacher is just weak, but may be a fake. If you cannot resist and learn by yourself (which is normally the main way of learning), you can get fake knowledge and fake experience. Do you think you would be able to get enough money with that?

So, what can happen? If you change your career path, you can loose some money, but you can get a chance to earn some money in some other activity. If you don''t, you can save your aid money, but only for some period of time as you will have to repay it anyway. In exchange, you risk wasting considerable time of your life to just frustration and loose you chance to earn money. You can potentially get into a great trouble of re-paying the debt, not just providing for living. I know, life can be really hard. It is hard, in fact.

However, I never know exactly. I don''t know how much money, I don''t know your real risks. You decide. Be responsible.

My best desire here is to be wrong. Yes, I wish to see that I was wrong and you can cope and change things and make a great career in computing. I really wish you that. I only try to help you to realize what''s involved.

Please forgive me this off-topic post. I''ll see if I can help you with the code you''ve added to your post.

Best wishes,

—SA


这篇关于类和对象真的很难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:02