Chapter11 使用类
- 格式:docx
- 大小:21.97 KB
- 文档页数:8
Chapter 1110. Metrobank offers one-year loans with a 9 percent stated or base rate, charges a 0.25 percentloan origination fee, imposes a 10 percent compensating balance requirement, and must pay a 6 percent reserve requirement to the Federal Reserve. The loans typically are repaid at maturity.a. If the risk premium for a given customer is 2.5 percent, what is the simple promisedinterest return on the loan?The simple promised interest return on the loan is BR + m = 0.09 + 0.025 = 0.115 or 11.5 percent.b. What is the contractually promised gross return on the loan per dollar lent?percentRR b m BR f k 97.121906.01175.011)]06.01(1.0[1)025.009.0(0025.011)]1([1)(1=-+=---+++=---+++=σc. Which of the fee items has the greatest impact on the gross return?The compensating balance has the strongest effect on the gross return on the loan.Without the compensating balance, the gross return would equal 11.75 percent, a reduction of 1.22 percent. Without the origination fee, the gross return would be 12.69 percent, a reduction of only 0.28 percent. Eliminating the reserve requirement would cause the gross return to increase to 13.06 percent, an increase of 0.09 percent.24. Assume a one-year T-Bill is currently yielding 5.5 percent, and a AAA-rated discount bond with similar maturity is yielding 8.5 percent.a. If the expected recovery from collateral in the event of default is 50 percent of principaland interest, what is the probability of repayment of the AAA-rated bond? What is the probability of default?p(1 + k) + γ (1 - p)(1 + k) = 1+I. Solve for the probability of repayment (p):percent or k i p 47.949447.05.015.0085.1055.1111=--=--++=γγTherefore the probability of default is 1.0 - .9447 = 0.0553 or 5.53 percent.b. What is the probability of repayment of the AAA-rated bond if the expected recoveryfrom collateral in the case of default is 94.47 percent of principal and interest? What is the probability of default?percent or k i p 00.505000.09447.019447.0085.1055.1111=--=--++=γγTherefore the probability of default is 1.0 – 0.5000 = 0.5000 or 50.00 percent.c. What is the relationship between the probability of default and the proportion of principal and interest that may be recovered in the case of default on the loan?The proportion of the loan’s principal and interest that is collectible on default is a perfect substitute for the probability of repayment should such defaults occur.32. A bank is planning to make a loan of $5,000,000 to a firm in the steel industry. It expectsto charge a servicing fee of 50 basis points. The loan has a maturity of 8 years and a duration of 7.5 years. The cost of funds (the RAROC benchmark) for the bank is 10 percent. Assume the bank has estimated the maximum change in the risk premium on the steel manufacturing sector to be approximately 4.2 percent, based on two years of historical data. The current market interest rate for loans in this sector is 12 percent.a. Using the RAROC model, determine whether the bank should make the loan?RAROC = Fees and interest earned on loan/ Loan or capital riskLoan risk, or ∆LN = -D LN *LN *(∆R/(1 + R) = = -7.5 * $5m * (.042/1.12) = -$1,406,250 Expected interest = 0.12 x $5,000,000 = $600,000Servicing fees = 0.0050 x $5,000,000 = $25,000Less cost of funds = 0.10 x $5,000,000 = -$500,000Net interest and fee income = $125,000RAROC = $125,000/1,406,250 = 8.89 percent. Since RAROC is lower than the cost of funds to the bank, the bank should not make the loan.b. What should be the duration in order for this loan to be approved?For RAROC to be 10 percent, loan risk should be:$125,000/∆LN = 0.10 ⇒ ∆LN = 125,000 / 0.10 = $1,250,000⇒ -D LN * LN * (∆R/(1 + R)) = 1,250,000D LN= 1,250,000/(5,000,000 * (0.042/1.12)) = 6.67 years.Thus, this loan can be made if the duration is reduced to 6.67 years from 7.5 years. The duration can be reduced.c. Assuming that duration cannot be changed, how much additional interest and feeincome would be necessary to make the loan acceptable?Necessary RAROC = Income/Risk ⇒ Income = RAROC * Risk= $1,406,250 *0.10 = $140,625Therefore, additional income = $140,625 - $125,000 = $15,625.d. Given the proposed income stream and the negotiated duration, what adjustment in therisk premium would be necessary to make the loan acceptable?$125,000/0.10 = $1,250,000 ⇒-$1,250,000 = -7.5*$5,000,000*(∆R/1.12)Thus ∆R = 1.12(-$1,250,000)/(-7.5*$5,000,000) = 0.0373。
第11课最近,我刚刚结束了魁北克五日之行,那是一座位于圣劳伦斯河畔古色古香、风景如画的小镇,今后,它将以“世界催泪瓦斯之都”载入史册。
我此行的目的是为了打入反全球化、反自由贸易运动的头脑人物内部,但问题是,那里根本没有“头脑”可寻。
我所看到的只是心绪的漫天宣泄,我面前是一派悲天悯人的景象。
显而易见,这里的稀缺之物是清醒的思考。
我来魁北克有个堂而皇之的理由,那便是采访美洲高峰会,这是一次跨越西半球三十四位国家首脑的聚会,会议最重要的议题是通过谈判,努力建立起美洲自由贸易区–一个地域跨越阿拉斯加至阿根廷的无贸易壁垒区域。
其实,我来魁北克是为了“人民的峰会”,那才是真正的亮点。
这一应运而生、有组织的活动看起来是要反映“人民的观点”,还会是别的吗?(我曾想,那些参加峰会、经选举产生的领导人是为此目的而来,但我有什么资格向“那些人民”提出质疑呢?)半球社会联盟由不同的社会团体组成,他们有着共同的思想意识和经济利益,他们共同反对贸易自由化。
该联盟这次邀请参加“反资本主义狂欢节”的都是激进团体,从极左到更极左,“狂欢节”在沿河畔搭建的硕大白色帐篷内举行。
加拿大政府好事做过了头,不仅资助了这项活动(其实是加拿大纳税人提供的资助),而且还为拉丁美洲的激进分子付费参加活动。
“反资本主义狂欢节”丝毫无愧于它的名称,有小丑、木偶表演、拉拉队长的呐喊、舞者和演员的表演,还有“愤怒的奶奶们”(一群不算太老辱骂大公司的妇女),甚至还有一个悬在空中、上面写着“实施安全贸易!”的巨大绿色安全套。
或许我最喜欢的是那些身着蓝色服装、面对由纸浆制成的女水神像歌唱并参拜的演员们。
除了此道风景,别无其他实质性内容,无论是在街面上,还是在各类有组织的“讲道论坛”中,情况均如此。
看一看下面的对话,这是我同一个保养得极好的年轻激进分子之间的谈话(当然喽,此人穿的是进口的牛崽裤和运动鞋)。
她向我挥动着拳头,肌肉松弛,毫无力量。
她的一位同志把我们之间的对话用一架日本摄象机拍了下来,摄象机的价值起码要比拉丁美洲人一年的平均工资还要多。
Java题库——Chapter11继承和多态1)Analyze the following code:public class Test {public static void main(String[ ] args) {B b = new B();b.m(5);System.out.println("i is " + b.i);}}class A {int i;public void m(int i) {this.i = i;}}class B extends A {public void m(String s) {}}A)The program has a compilation error, because m is overridden with a different signature in B.B)The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.C)The program has a runtime error on b.i, because i is not accessible from b.D)The program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B. B中没有重写⽅法m。
B继承了A中的⽅法m,并在B中定义了⼀个重载的⽅法m。
2)Analyze the following code.// Program 1public class Test {public static void main(String[ ] args) {Object a1 = new A();Object a2 = new A();System.out.println(((A)a1).equals((A)a2));}}class A {int x;public boolean equals(A a) {return this.x == a.x;}}// Program 2public class Test {public static void main(String[ ] args) {A a1 = new A();A a2 = new A();System.out.println(a1.equals(a2));}}class A {int x;public boolean equals(A a) {return this.x == a.x;}}A)Program 1 displays true and Program 2 displays trueB)Program 1 displays false and Program 2 displays trueC)Program 1 displays false and Program 2 displays falseD)Program 1 displays true and Program 2 displays false3)Invoking ________ removes all elements in an ArrayList x. 3) _______A)x.clear() B)x.delete() C)x.remove() D)x.empty() E)x.clean()4)Analyze the following code:Cylinder cy = new Cylinder(1, 1);Circle c = cy; 4) _______A)The code has a runtime error. B)The code has a compile error. C)The code is fine.5)Which of the following statements are true? (Choose all that apply.) 5) _______A)Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them.B)A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated.C)It is a compilation error if two methods differ only in return type in the same class.D)A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.E)To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass.1、重载⼀个⽅法是提供多个具有相同名称但具有不同签名的⽅法来区分它们。
I.运算符重载1.运算符重载简介●定义:运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型。
●性质:一种形式的C++多态●作用:允许将标准C++运算符作用于类对象(注释:C++中的运算符已经被重载过,如:“*”——用于地址得到存储与该地址中的值——用于两个数字表示乘积)●举例:数组相加不重载(逐个相加):for(inti = 0; i<= 20; i++)evening[i] = sam[i] +janet[i];重载(相加):evening = sam + janet;●格式:operator op( argument-list)✧Time示例◆Time源代码求和功能:sum函数Time Time::Sum(const Time & t) const{Time sum;sum.minutes = minutes + t.minutes;sum.hours = hours + t.hours + sum.minutes / 60;sum.minutes %= 60;return sum;}Main函数中:Total = coding.Sum(fixing);◆添加加法运算符在类中添加:Timeoperator+(const Time & t) const;在函数的实现中添加:Time Time::operator+(const Time & t) const//返回类型为Time类{Time sum;//定义一个Time类型的对象sum.minutes = minutes + t.minutes;sum.hours = hours + t.hours + sum.minutes / 60;sum.minutes %= 60;return sum;}在主函数中:两Time类相加由原来的调用sum函数变为直接使用“+”运算符total = coding + fixing;◆重载限制可重载的运算符:重载的限制1)重载后的运算符至少有一个操作数是用户定义的类型,而不是标准C++中已有的运算符功能e.g.不能将“-”重载为预算两数之和2)运算符重载后需符合原句法规则e.g.不能将“%”只作用于一个操作数;不能改变运算符的优先级3)不能创建新的运算符4)不能重载的运算符✗Sizeof✗. :成员运算符✗.* :成员指针运算符✗:::作用域解析运算符✗?::条件运算符✗typeid✗const_cast✗dynamic_cast✗reinterpret_cast✗static_cast5)能通过成员函数重载的运算符✓=✓()✓[]✓->◆其他重载运算符在类中:Time operator-(const Time & t) constTime operator*(double n) const在函数实现中:Time Time::operator+(const Time & t) const{Time diff;int tot1, tot2;tot1 = t.minutes + 60 * t.hours;tot2 = minutes + 60 * hours;diff.minutes = (tot2 – tot1) % 60;diff.hours = (tot2 – tot1) / 60;return diff;}Time Time::operator*(double mult) const{Time result;long totalminutes = hours * mult * 60 + minutes * mult;result.hours = totalminutes / 60;result.minutes = totalminutes % 60;return diff;}在main函数中:直接使用重载后的运算符II.友元函数1.友元函数的定义●指某些虽然不是类成员却能够访问类的所有成员的函数。
类授予它的友元特别的访问权。
2.友元函数的性质●与类成员有相同的访问权限3.创建友元●第一步:将函数原型放在类的声明中,并在之前加上friendfriend Time operator*(double m, const Time & t);●第二步:编写函数定义不是成员函数,所以不使用Time::限定符定义中不使用关键字friendTime operator*(double m, const Time & t){Time result;long totalminutes = t.hours * mult * 60 + t.minutes * minutes * mult;result.hours = totalminutes / 60;result.minutes = totalminutes % 60;return result;}●第三部:调用过程A = 2.75 * B; // allowedA = operator*(2.75, B);4.常用的友元:重载<<运算符✶<<可被重载:a)最初,<<是C和C++中的位运算符,将值中的位置左移b)ostream类重载后,转化为输出工具,cout为ostream对象,可识别所有C++基本类型c)对于上述C++每种基本类型,ostream类都包含相应重载的operator<<();eg. 对于int,double,等等●<<的第一种重载版本void operator<<(ostream&os, const Time & t)⏹注释:cout<< trip中,cout 是一个ostream类,trip是一个Time类,所以在重载的函数中参数分别是一个ostream对象和一个Time对象。
{os<<t.hours<< “ hours , ” <<t.minutes<< “ minutes, ”;}●<<的第二种重载版本✶出现问题:eg. cout<< “Trip time: ” << trip << “ (Tuseday)\n”;//不能执行即不能连续输出。
✶解决原理:使用cout<< x要求<<左侧为一个ostream对象,上操作满足要求,若cout<< x << y,则要求输出语句也为一个ostream对象,所以将ostream类中operator<<()函数实现返回为一个指向ostream对象的引用。
ostream operator<<(ostreamos, const Time & t){os<<t.hours<< “ hours , ” <<t.minutes<< “ minutes, ”;return os;}⏹注释:以cout<< “Trip time: ” << trip << “ (Tuseday)\n”; 为例,将这条语句分成多步:a)cout<< “Trip time: ” 将显示字符串,但其返回值为cout,即原语句等价于cout<<trip << “ (Tuseday)\n”;b)cout<<trip 程序使用<<的Time声明显示trip值,再次返回coutc)cout<<“ (Tuseday)\n”; 显示字符串结束运行III.成员函数&非成员函数1.成员函数/非成员函数的定义●成员函数:是程序算法的实现部分,类的成员函数描述的是类的行为,是对封装的数据进行操作的方法。
类的成员函数的原型要写在类体中,原型说明了函数的参数表和返回值类型。
而函数的定义一般在类外面,也可以直接在类内部定义。
●非成员函数:非成员函数就是没有在类里定义的函数多用于面向过程2.重载运算符的说明●很多运算符可以选择使用成员函数或非成员函数进行重载,一般而言,非成员函数应是友元函数eg. 可以在类中声明:Time operator+(const Time & t) cosnt;也可以使用如下原型:friend Time operator+(const Time &t1, const Time & t2);⏹注释:若上述两种原型都声明,则对于T1 = T2 + T3,将任意转化为:T1 = T2.operator+(T3);T1 = operator+(T2, T3);IV.矢量类1.矢量类的定义2.Vector示例3.使用状态成员4.为Vector类重载算术运算符5.对实现的说明6.使用vector类模拟随机漫步V.类的自动转换&强制类型转换1.转换函数2.转换函数和友元函数。