View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Questions on Spring 2003 M1 Milestone

Got questions on Spring 2003 M1 Milestone? Enter them here.

When you buy shares, you can't buy a fraction of a share. But:
r buy: 135.25
r balance "This should return 1 (we bought 1 share)"
r buy: 4000.00
r balance "This should return 30.5748"

Balance seems to a fractional number over here. whats up?

Bob says: Not my brain. OK I corrected this to be whole number. See new sample page.

Also, since we seem to have sellShares, shouldn't we also have an accompanying buyShares? I think thats the way shares are mostly bought.
'gimme 100 of microsoft at xyz price.'

Bob says: M1 is mainly a chance to use smalltalk on a small part of the big problem you will work on as teams. I purposely tried to simplify it somewhat over the "real" team assignment. I recognize that through automatic reinvestment programs you can buy partial shares and you have to worry over capital gains and dividends. (and whether they are reinvested or payed to a third party) For M1 do not worry about this. For M3-7 you will have to worry over this)


s withdrawal: 245.50
s balance "this should return 3000.06"

well it should be 3100.06

Bob says: Man it would help if I could use a calculator. OK cleaned that up to 3100.06.


s rate "this should return 5.25%"

Is this with the '%' symbol or not?

Bob says: No percent sign, should return 5.25. Corrected that in sample code.

I think Mutual Funds and Equity Stocks also generate money. They don't just sit there and become more/less expensive. This is to point out that the EquityStock class also needs the creditInterest method.

Bob says: See above comments about limited scope of M1. Good point though and glad to see you are thinking about the domain.

please answer these questions, TA's where are you???

Bob says: It is not the TA's fault. It's my fault. I wrote M1 and was supposed to be watching this page. I didn't realize that people would be working on it to this degree already. Sorry. If you don't get answers in a resonable time on the project, email me directly and I will make sure that I respond.

I've seen your post but need to talk to the professor about this. I actually recognized the same problem when I reformatted the Milestone's page, so you'll have to wait a bit until I can clear it up. I'll try and repost a better answer on Tuesday. For now, just do it the way it says in the milestone, ok? Chris Verges

I still see things in the example code that I think are typos...

1) s balance. "this should still be 3100.06"
2) s creditInterest: #year. "should return 162.75"
3) s balance. "this should return 3262.81"
4) s balance. "should return 4228.81"

Bob says: Cascading errors. Thanks, after correcting one error, I failed to check for downstream effects. Thanks. I've corrected the sample code.
The last s balance above is actually incorrect, I just noticed the creditInterest message immmediately preceding the balance message is month not year, thus the interest is not 966, but 80.5 (966/12). I have updated the sample code to reflect the correct totals. Final balance should be 3343.31.

I think I'm missing something important, but because variables are untyped, how can we put an instance of some Currency class within the different account classes? Like... how can I tell squeak that balance is Currency rather than Float or something else?

Also, I have had no luck finding a class of this nature online or in Squeak... Any push in the right direction would be greatly appreciated.
Kyle Mahan

Bob says: Kyle, currency is tracked using decimal fixed arithmetic. Money (at least american money) is just decimal fixed where the precision is 2 decimal places. Any decimal arithmetic package will probably suffice.

I have been told that some currency routines exist if you install Squeakmap (do a search on google), but I am yet to be convinced from the project that this is necessary. Also, installing Squeakmap looks like it requires you to get a newer version of the squeak image than we are supporting for this class, so you may want to explore other alternatives (like writing some of the routines yourself, sorry...). If anyone has better information about Squeakmap or other alternatives, please feal free to correct me on this...
Jonathan D'Andries

P.S. Please sign all your posts... Otherwise, we don't know who we are talking too.

actually... while it is *nice* to know who you're talking to, we have always had a policy in this class of not requiring people to sign their posts. we respect that some people may feel more comfortable asking questions in an anonyous way. see the Statement on Privacy for a longer explanation :) -ellie harmon

I would like to ammend my previous post. There is a lot of good information on Squeakmap as You can get it to run with v3.2.1 of Squeak and I recommend doing this (rather than upgrading to v3.4a). Note, I have not found the currency classes yet, but I have been told they are in a package somewhere.
Jonathan D'Andries

Ok, I never answered your first question about using "currency" within an account. The easiest thing I can think to do is to create a new currency class from within the accessor/modifier so that the end user just deals with numbers while you take care of all the currency conversions under the covers. The downside of no-typing in Smalltalk is that the programmer has to figure out what kind of object they are dealing with, but the upside is that "balance" does not care if you assign it a number or a currency. Does this make any sense? If not, just post a follow-up question and I will try to clarify.
Jonathan D'Andries

To be very pedantic, Jonathan meant "create a new Currency instance", not "a new currency class". I read this wrong a couple of times before getting it. -Lex Spoon

Do we have to check if combination of account number and name is unique and how many decimals currancy input has?

Fei Chen

Bob says: For M1, you do not HAVE to check that these are unique. For the full project M3-M7, you will need to do more input validation to ensure the user doesn't try to create the same account twice and thus get a corrupted financial application. If you want to check that now, it just makes your code more reusable for the later part of the project.

What should be the output for statement like "s type"? A String or printout from Transcript?

Bob says: The output should be a string. When you design the full-up system (M3-7) you can then use this information to display in your GUI or on your reports. If you want to print it to the Transcript, you would use Transcript show: 'Type of account: '; show: s type; cr.

What should be the augument for method creditInterest? An integer represneting number of years or something else?

Bob says: The requirements say that interest is credited either by day, month or year and gives the appropriate numeric adjustments. It is a design decision about how you do it. In the sample code for M1 I show the method taking a symbol (#day, #month or #year) which represents the interest period to be computed. To me this is more self-documenting than passing .00274, .08333, or 1. Either way will get the same result. We will talk about design tradeoffs pretty soon, but this is obviously a tradeoff between maintainability and efficiency. It takes more internal logic, thus more code, thus longer execution time, to take in the symbols rather than direct numbers – but that faster time is at the cost of some poor maintainer 10 years from now who is trying to figure out what .00274 is supposed to be!

Can I just add a method to class Number instead of making a new Currency class? My method will take an argument and check if it is a negative number. If it is, Transcript will display an error message.
If it's not, this method will convert it into a currency format number with only 2 decimal point.

If you modify the Number class, then if you merge your code with one of your teammates in the future, you guys will have different pieces of code in fundamental classes... That s not advisable. It is then better to subclass the Number class and add your own modifications in the subclass. Maybe that subclass could be Currency or something like that. Christophe Levand (TA)

is it okay to post a link to a decimal class that i found? i can't remember what was said in class about this...
Kyle Mahan

i think that would be helpful to other students. we certainly would not want you to post code/answers, but i think that links to helpful resources would be acceptable, and appreciated :) also, remember anything on the Cases page is fair game for help with this semester's milestones -ellie harmon

I know it says that partial shares cannot be bought, but does this also apply to sellAmount? In the example code, sellAmount sells the exact amount passed in, not an integer number. That also brings up the question of should we sell as much as we can without going over the passed in amount or as close to the passed in amount as possible (ie sellAmount 1000 where shares cost $28, should we sell $980 worth or $1008 worth)?

Bob says: you may end up selling partial shares based upon the amount. For instance in the sample code, sellAmount:1000 would sell 1000/135.25 or 7.4 shares. I know this is not exactly realistic, but I am trying to keep M1 at least reasonable within its goal of getting you familiar with smalltalk and sunit. Clearly for the full project (M3-M7) there will be more sophisticated rules that will have to be followed.

Jeffrey Boyles

Can anyone explain where 25.5748 and 18.0134 come from? Thanks.
Bob says: 25.5748 is a mistake. It should be 1+29-5=25. 18.0134 is a mistake. It should be 17.6 (25-(1000/135.25)).

The balance of an EquityStock account only has one decimal point, right?
Bob says: For M1, you can have it to 1 decimal place. I looked over my stock records, and they appear to keep it to 4 places, so M3-7 will probably require increased precision.

Kyle, please post the link for the decimal class.. I'm sure it's ok since Bob said "Any decimal arithmetic package will probably suffice."
Bob says: If you do a search on squeak and decimal fixed you find the DecimalFixed.cs changeset you can bring in. It is possible, as someone pointed out, to do the problem without decimal math by some other manipulation mechanisms. If you can do this correctly, then that is also OK. The main thing about proper reuse is to use the smalltalk classes that already exist effectively.

The arguement 'numberShares' in method sellShares also can have one decimal point, right? And in EquityBond class, argument 'numberBonds' in methods 'buy' and 'sell' is an integer or they can have one decimal point? In method 'buy' of EquityStock, should 'numberShares' should aCurrency?

Bob says: For M1, you can just buy/sell whole shares. For the full up system (M3-7) you will need to be able to handle partial share manipulation.

How do I retrieve the work I submit to make sure everythiny is right?
Bob says: I will defer here to a TA, but I believe they use email, so it is not the problem that you may have experienced in other classes using webwork or workon.
Lex Spoon: Actually, we normally use a turnin swiki. You cannot download your submission. The only thing you can do to check it is to press "attachments" and see if the file size is approximately correct. The benefits are that this is simple to operate and that students don't have to keep track of yet another password. Hardly ever does a submission get messed up, and if one does, the TA's are extremely forgiving.

For anything that requires a fixed decimal point.

Does it make a difference if we store the value to 2 decimal points
Storing to infinite and just returning a value to 2?
Bob says: Not for this milestone. In M3-M7 you will need to design the system so that proper precision is maintained, but how you do this is a design decision. We won't mandate a particular algorithm or technique.

I'm still a little confused on how to use the SUnit testings. I know the format and everything, but how are we supposed to test, for example, the balance, deposite ... etc. I know how to test name and number and rate, that's all I know! little help please?? Thanks


Bob Says: Think about how you would know that deposit works and what tests you would do to test all the different input partitions. We could start with a known balance, then do a deposit and check that the new balance is correct. We could try to do an invalid deposit and check that the proper action is taken. adds a Decimal subclass to Fraction I believe. I tried for a long time to find some way to do balance := Decimal new, but that kept giving me errors... I ended up just using the asDecimal message in the modifier, which works pretty well. Hope it helps....
Kyle Mahan

I don't know if I got the whole picture right, but can I write a class called Account with three subclasses and implement some tasks in Account that all subclasses share? Or do you want us to have three completely different classes?
Arash Mirdamadi
Bob says: I mean that's the whole power of subclasses right? We want to factor common behavior and data into super classes. If you find yourself doing a lot of cut and pasting or repetitous coding in an OO language, that should be a warning that maybe something is wrong. We will talk more about this on Thursday when we start design.

So what's the answer to the original question? Are we supposed to have the three classes as sub classes or are they all supposed to be separate classes? It seems that if we were to go about making a master super class we would end up having to override, or create most of the methods anyway (except for name, name:, number, number:) so it seems like more extra work in this case.
Bob says, well I think I did answer your question. This is a design class. I am not going to tell you how to design your application. I am going to give you some information about how the program should function. Its up to you to decide the "best" way within the design principles for OO programming.
Are we given complete freedom of design, or is there a certain "correct" design as far as the grading goes and we just have to figure out the proposed "correct" design on our own?
Bob says: Within the constraints of good OO design, you are free to design anyway you want. We recognize there are multiple acceptable answers, not just the one we came up with. On the other hand there are also really bad OO designs (like everything in one class) which are penalized.

Do we have the ability to test messages with no parameters by using SUNIT?

Bob says: yes. Any method will somehow modify the state of the object or report on the state. It should be possible to check that the state changed to what you expect. This will be more of a problem once you have GUI's involved. One design constraint you have to deal with is making you application testable.

What should we do if balance: aCurrency is called with a negative parameter? Should we just do self: error and stop the whole program or should we attempt to continue as normal as in the buy: aCurrency "insufficient share error messages"?

Bob says: This is a design decision about how you want your program to operate. Do want it to stop working, or do you want it to print an error message, set the balance to either zero or the current value if it is not nil, etc. Anything not specifically required is left up to you?

The milestones page says that we need to include two lines of comments for every non accessor method. However I have a modifier method like this:

name: aString

Are we supposed to include two lines of comment for such a method also? I mean the amount of comments will exceed the amount of actual code... Also what is the maximum allowable length for a "line"?

A single line will do for accessor/modifiers. Chris Verges

Also do we have to have comments in the SUnit test classes?

Yes. Chris Verges

Do we have to test each and every single method with SUnit, or is there any methods that we don't have to test?
Also if we were to infact test every single method, what would we name the test version of the method name, and how would that name be different from the name of the test version of the method name: aString? Also is it a good idea to have one test method that test multiple methods of the original class?

I think accessors and modifiers may be passed over for testing. But if those accessors and modifies do anything other than saving/returning, they must be tested. So if your code say tests the input for nil or if the param is a kind of class, then you MUST test it. And now that the question has been posed, we will check for this. :-) Chris Verges

When a test method of an SUnit class fails, how do we know which assertion made in the method failed?

Lex Spoon When you run Sunit, it will show a list of methods that had an error. You can even debug into them if you select them from the list

Are then any restriction on the number of decimal places on the rates?

Eh, not really, but we won't pass in more than 2 or 3. Chris Verges

Lex Spoon: Incidentally, if it was a real financial program, it would have to do its computations in decimal. "10.142" is not the same in Squeak (and most computer languages) as "10142 / 1000". Cobol does it "right" for financial apps, and uses true decimal arithmetic

If we installed the Decimal change set, do we include this change set in the files we send to our TA for grading? I assume we do, but just wanted to make sure. Jay Parker

Take a blank image. File in your code. Test it. Does it work? Import whatever else you need. Does it work now? Recurse as necessary. Now take whatever you had to file in and send that to your TA. Chris Verges

In Equality stock, what is mean we can sell or buy partial stock?
Is that mean we can only buy or sell stock as integer such as 1, 2, 100?? In "18.0134 should be 17.6", 17.6 is still not integer number.
Also, r buy:4000.00 then 4000 // 135.25 = 29 and 4000\\135.25 = 0.57 that mean 57cents left after buy 29 stocks. then should we lose this 57cents or do we have to keep left money and add later to buy more stock???

Bob says: If you look at the sample code for M1, you will see that I modified the 4000 after an earlier post so that it came out to an even number of shares. If you sell by shares, it has to be an integer amount, if you sell to get a specific amount of money, that is where the balance of the account may become a non-integer value (like the 17.6). Again I tried to make M1 easy so you get a feel for smalltalk. Later milestones will deal with a more realistic view of the purchase of stocks.

Should we print an error message if the number of bonds on a sale is negative?

Bob says: You can. In the next milestone, we will introduce transaction histories for each account. In that case, the more error handling you detect now, the less you have to do later.

In general what should a method return if there was an error?

If you've sent a self error: call, you don't have to return anything. Otherwise, return whatever your code needs to handle the error properly. This is a design course, so we try not to place restrictions on how to do things. Chris Verges

The last three lines of the example code:
b sell: 5. "should return 5000"

b creditInterest: #month. "returns 80.5"
s balance. "should return 3343.31"

Should "sell:" and "creditInterest" of EquityBond class really have return values? Do not they just modify instance variables?
Their main job is to perform operations, but returning a value may be useful for future extension of the application. Christophe Levand

Do we have to comment all our test classes as well?

Yes. Chris Verges

can we make sellShare to sell whole share rather than partial share?(since it eventually have to be in that manner... eventually)

Bob says: If I understand your question, Yes.

Is there a way to initialize values when a class is made so that...lets say an accessor isn't called on an item before it has been set to anything. Can we override the "new" method by writing our own and just initialize our variables and just call ^super new. at the end? -Jay Parker

Bob says: Yes. Take a look at page 71 of the required text. It involves the creation of an initialization method.

Is OK if we test multiple method in SUnit class with only one test method? As example, we test creditInterestTo: and creditInterest: both with testCreditInterest?

Bob says: Yes, as long as they are logically related. You would not want to test selling and buying in the same method, but setting/getting are often done together since they are so closely related.

Where do we include our name and gt number in the project?

How do we get a hardcopy of all our source code for turn in?

Do we lose points if we don't comment accessor methods? The milestone page seems to imply that we in fact do not have to comment accessors (although if you were excessively pedantic you could point out it only says we don't have to comment atleast two lines). However a TA has said that we do need to comment everything. So could someone straighten this out?

Bob says: I know it seems over the top, but in general everything should be commented. Sometimes an accessor does more than just return an instance variable. Often it has to process collections or perform other calculations or adjustments. Comments make it clear exactly what is happening. Plus as we used to say in pilot training – It develops positive habit transferrence.

For the Equity Bond. Do you want us to deduct money from the FixedSavings account instance? For example when you buy: 1 share of the 1000 faceValue, do you want us to reduce the instance's balance by 1000? (the example code doesn't, but it would make sense to).
Bob Says: For future milestones, you will have to worry about where the cash comes from (i.e. trading accounts). For M1, you can assume the money comes from an inexhaustible supply somewhere.

What exactly is the buy: numberShares method supposed to be doing. The M1 Description says that this method is supposed to "Increase the balance by: Purchase amount / Bond Face Value" yet the Example Code says that the balance is increased when buy: 1 is performed even though the faceValue is 1000. So it buy: taking in the numberOfShares or aCurrency?

I get how you calculate creditInterest in fixed savings, rate of interest FixedSavings balance, but in the example how did it turn out to be 162.75? is it something wrong i'm doing ??

Bob Says: It is the balance 3100.06 times the interest rate .0525 (5.25%)

Everytime I try to upgrade to SqueakMap specifically the SM Package Loader, it has a bunch of problems resolving a host and then once it finds one, it trys downloading and just stops. It always stops on the line - Load updates with logging time 2ms. It just freezes there for at least half an hour and it never completes. Any suggestions on how I can get the upgrades to the TestRunner?

Bob says: If you can find a classmate who has successfully installed squeakmap, it puts the .st and .cs files into the image directory, so you should be able to get these files and manually files them in.

When testing type of the parameter (ie string or number) or seeing if the number is negative. Do we have to be specific about the error. If its the wrong time or a negative number can I say that the input was an error or do I have to be specific on why the input was an error.
Janet Abdul-Karim

It is considered better style to give as much information in the error message as possible. Just to put it into perspective, I was using a certain microsoft product the other day and suddenly got a message box saying something like "Critical Error, quitting now." When I pushed ok, the whole machine went into blue screen of death. At that point, I would have appreciated a more explicit error message...
Jonathan D'Andries|

Can someone explain to me why I get 356.65 - 345.56 = 11.08999999999997 instead of 11.09?

Bob says: Because you are subtracting two Float numbers. If you downloaded the decimal class try (365.65 asDecimal:2) - (345.56 asDecimal:2)

Would someone explain to me why...

temp _ 0.0.
temp _ ( 9.54 ).
temp _ temp 100.00.
temp asInteger. = 953 instead of 954?

Thank you.
Bob says: tried this and there appears to be a bug in the asInteger method. I can do 9.54100 and get 954, but if I do the asInteger I get the incorrect answer. I will have to look into this more. You won't be penalized for errors caused by the environment. I need to check more and be sure I fully understand what asInteger is doing.

I still have some confusion around the specifics of a few points:

1. How many decimal places should 'rate' have?
Banks normally use 2 after the main percent. 1.07, 2.35, etc.
2. Does FixedSavings creditInterest have to return the interest or does it just have to add it to the balance.
For future expandibility, returning the calculated amount will make future requirements easier
3. How many decimal places does the balance in EquityStock supposed to have?
For M1 it doesn't matter 1-4 would be OK. For future applications the standard is 4 decimal places.
4. Is FS balance allowed to be zero?
5. Is EB balance allowed to be zero?
6. Is ES balance allowed to be zero?
Yes to all, Clearly you can zero dollars in an account and still be legal.
7. Is buying in EB buying a whole integer share or is it purchasing amount / bond face value as indicated in the .nfo.
8. ES - Can we buy partial shares?
Bob says: For M1, we only require purchase of whole shares.
9. ES - Can we sell partial shares?
Bob says: For M1, there are 2 ways to sell shares: if we sell shares directly then we only sell whole shares. If we sell to achieve a specific dollar amount, we may have to sell partial shares
10. If we are going to initialize values like price, what is a good initial value? Or can we just assume that the price will be entered before computations like value are going to be performed?
Bob says: For M1, you can makeup prices, In the real application we will get stock price from the internet via information feeds
11. Can someone point me in the right direction about how to do something like 'isEquityBond'? I have the part in EB ^true, but how do I get everything else to return false?
Bob says: I am not sure you actually want to do it this way. Look at Chris Verges discussion of isKindOf: message on class newsgroup. Basically smalltalk allows you to test the class of an object with the isKindOf: message. This is more powerfull because you check for whether it is an Account class in general (isKindOf: Account) or a more specific type (isKindOf: EquityBond).

I know this is a hefty amount of questions, and I appreciate any answers.

Thank you,


In the last line of example code it says:
s balance. "should return 3343.31"

but the creditInterestTo method was called 9 lines before when interest should be $92. so shouldn't s balance equal 3354.81 instead of 3343.31?

Bob says: creditInterestTo: message doesn't trigger any money actions, it just tells the object what account should get the interest when it does get credited. The creditInterest message is the one that actually changes the balance.

From the example since we can have fraction of shares should that also be to the 2nd decimal place or just 1.

Janet AK

Bob says: For M1, it doesn't matter. If you are thinking ahead to the full application, shares are kept to 4 decimal place precision.

and another thing....
it would make more sense to name the argument to creditInterest "aTimePeriod" right? because if the interest was always calculated after a year, then we wouldn't need an argument. i might be wrong, but naming the argument "aYear" doesn't seem to make any sense with what bob had to say about fei chen's question a couple pages up.

andrew choi

Bob says: Yes, that is kind of a bad variable name. Your name is more accurate for its purpose. Even instructors pick bad names sometimes.

why doesn't buy return anything and sellAmount and sellShares do?
why does sellAmount just return the value that was passed to it?

Janet AK

Bob says: Return values may appear useless in M1, but they will become valuable for future expansion of these classes for the full application

Can you please give us an example on how to test a message without any parameters such as value?


Check if the return value of "value" is what you would expect it to be for a given situation.
Jonathan D'Andries|

I'm having some problems getting the initialize functions to work. I've written a new 'new' method which consisits of ^super new initialize, and then an initialize function that sets some values. However, its like the account is still receiving the old 'new' message instead of the new one. Even printing to the screen doesn't work as it appears that the message isn't even received. I've followed page 71 of the book, and would appreciate any help or thoughts as to why this might not be working.

Did you make sure that your new method is a class method and your initialize method is an instance method? Christophe Levand

Would someone explain why 9.54 asDecimal: 2 is equal to 9.53 instead of 9.54?

Bob says: There is something strange going on under certain conditions of values in smalltalk. For instance the asInteger method also incorrectly represents certain integer values. You will not be penalized for screwy behavior of the environment, only screwy behavior of your application.

i've been churning along this project, but i'm not understanding under requirements, that little table. what does it mean when it says something like "name: aString and name"?

- 'name: aString' takes aString as an input argument, whereas 'name' does not take any argument and returns the name in the instance Christophe Levand

In the Example code we have:
r balance: 0;
price: 135.25.
r buy:135.25.
r balance. "this should return 1 ( we bought 1 share)"

However the requirements say the buy method should be-
buy: numberShares
not buy: Amount.
Is this an error?

Thanks - Dol Kuk

Bob says: The example code is correct. For M1, you should give an amount and purchase that number of shares. It is also the case for M1 that we assume the amount is always an even number of shares. For later milestones you will need to support buying a certain number of shares (gimme 100 shares of Coke) or an arbitrary number of shares given money (gimme $1000 of Coke).

That little bit of test code is confusing me as well.

Bob says: Sorry, in trying to make M1 as easy as possible, I lopped off requirements from the full system you will need to build in M3-7. This resulted in a lot more inconsistencies than I had anticipated. I am beginning to think if I had not tried to make M1 easy, I would have in fact made it less difficult to understand!

Should this method credit interest to an Equity Stock or EquityBond
account as well? If so, how do we handle it - Divide the interest by the
price or faceValue respectively and add the result to the balance?

Above question refers to creditInterestTo method in EquityBond class.

Bob says: creditInterestTo method just tells the object where the intrest payment is supposed to go. creditInterest actually generates the interest. While in real life stocks generate dividends and captial gains, for M1 we are ignoring this

Important note about Decimals
It has been noted that 9.54 asDecimal: 2 returns 9.53. This is because 9.54 is a Float in Squeak and the asDecimal: message approximates it to a Decimal. To create an exact Decimal, use the String asDecimal message: '9.54' asDecimal returns 9.54 as expected (note the quotes around 9.54). -Brandon Stepler

I have some confusion for the credit interest for fixedsavings and equity bond are we suppose to check and see if the user input a valid month or year in both cases.

Bob says: For M1, assume the three valid entries are day, month or year for the interest period to be calculated. It is up to your design as to how you pass the parameter and what the parameters type is.

Where do we include our name and gt number in the project?

you turn your work in here: since everyone has their own turnin page, you don't need to include your gt number/name in the actual project anywhere :) -ellie harmon

How do we get a hardcopy of all our source code for in class turn in?

The best way is to use the printOut ability of squeak on your class category. In the system browser right click on the category that houses classes for m1. Then select "printOut". If your category was called "m1" then it will create a file in your squeak directory called m1.html. Print that html file out... it's the hardcopy of your source code. -T. Scott Saponas

In the sample code: when you sell the five shares, where does the $5000 go?

Mike Meisner

Bob says: For M1, the money just drifts away. We will worry about there the money goes in the later milestones.

For the second call to creditInterest from the sample M1 code (the creditInterest message that was called on an EquityBond object), it appears as if you used an algorithm that did: [(value * (1 + rate/12)^1) - value] rather than doing the more correct algorithm [(value * (1 + rate)^(1/12)) - value]. If we were to pass in 2 years as the parameter to creditInterest, using your algorithm we would then have interest of [(value * (1 + rate * 2)^1) - value], which seems wrong as we all learned that the formula for simple interest in such a case should be [(value (1 + rate)^2) - value]. Could you please clarify? Also, are we to assume that the units for the parameter passed into creditInterest are always in years, so that if (2/365) is passed in, this indicates 2 days? Any clarification is stellarly appreciated. Thanks. - Nish

Bob says: For later milestones we will worry about correct compounding interest calculations. For M1 assume interest is simple interest over either a day, a month or a year. How you pass the parameter to signal the appropriate interval is up to you.

I am really confused about the creditInterestTo and creditInterest in the Equity Bond.

I know that in creditInterestTo you have to make sure that its an Account.
I know that you have to take the creditInterest and deposit it into that Account (if its valid of course).
I really don't have a clue on how to implement it.
Janet Ak
Bob says: Think about how an object sends a message to another object. It needs a reference to that object. It then uses that reference to send the message. creditInterestTo: is going to give you the object you need to later reference. Instance variables are a way to save important information about data you will need later. If you save the object reference in an instance variable, then when you creditInterest you will know who to send a deposit message to.

I've spent quite some time trying to override the 'new' method.
Say there is this class A, subclass to Object and I want to override the 'new' method so that it'll print "wussup".

A compile:
Transcript show: ''wussup''.'.
classified: 'test'.

However, it seems as the new 'new' method never got called. Any ideas?
. Ji

Have a problem with the initialization as well. I tried to follow the example in the book and got

Example class
instanceVariableNames: ''

when I cut this out and put
^super new initialize

it asks me do I really want to change my Example class. Out of fear i say no.
Janet AK

If, for example, my method throws an error checking for some incorrect argument, does my testMethod also should pass in an incorrect argument to see whether the method fails or procudes an error?
Arash Mirdamadi

As Bob mentioned above, "We could start with a known balance, then do a deposit and check that the new balance is correct. We could try to do an invalid deposit and check that the proper action is taken." I can see how to check for valid data, but all my methods throws one or more errors when invalid argument is passed in and do self error:. How do I go about testing these methods?

Use "self should: [block] raise: Error" for this. There is also self shouldnt:raise: as well. Something like this should be appropriate: "self should: [ aFixedSavings balance: -50. ] raise: Error." Zachary Crowell

I was wondering the format for the testing methods in sUnit. I have gone back over the slides and they show three messages to use (assert, should, and deny.) do we need to implement all of these in our cases, or merely the assert message?

Links to this Page