Sorry, I'm having a very busy week and won't be able to give feedback on lab submissions prior to the labtest. However, here are solutions to Lab 5 and Lab 5a; hopefully this will help you out.
Just to bring to your attention once again, there seems to be a problem (as you mentioned) with the name of the tester file being Tester.java, here is what happens in that case --
http://i55.tinypic.com/1znohnq.jpg
Could you please help us on that? I am even more interested in this because the error that comes up is pretty weird.
yea... especially considering it seems to be a simple .java file, and clearly the output is not consistent with the file itself. What is generating this output (I got the exact same output)?
In lab 5, under the bankAccount copy constructor, why don't you deep copy the Person object in your solution. If I change the person object of the original bank account, I change it in the copy.
The Tester error is due to having the Type API installed (back from CSE1020), which comes with a class called Tester. Because Java looks for classes there first, it takes priority over your own class.
If you delete the jar file from the jre/ext folder it should work fine.
The reason he didn't bother to copy the Person object is because a copy will be made anyway in the other constructor he called (line 14).
Although I would argue it would be safer to make a copy in the constructor as well instead of relying on the other constructor to do so (and it doesn't hurt).
It was a bit difficult but it was doable and as the prof said that it's going to get difficult from now on so expect everything tough now. Wait till you get a real taste of Link List
I thought it test was fairly easy. I've the docs needed to specify the the constructor, throw an exception if the employee created has wage less than minimum wage, however.
Wow, I must've had a brain aneurysm when I wrote that last comment. The last post in (better) English: I thought the test was fairly easy. According to logic: the API documentation for the Employee class should have specified for the constructor to throw an exception if the employee created has wage less than minimum wage, however.
The labtest was fair. Either you didn't practice enough (Practice labs were pretty much the same as the labtest) or you made one of those silly mistakes.
Sir, THANK YOU VERY MUCH for these solutions. REALLY REALLY help full to study for the lab test. really appreciate it, please do so for the upcoming labs as well. THANK YOU :)
@dennis: I don't think so. "this.wage" is only declared, but doesn't have a value assigned to it. If you use the setWage method, the variable will never have a value if you pass a wage less than the MINIMUM_WAGE in the constructor. setWage method doesn't throw error exceptions either... it just changes the value if the wage is greater than MINIMUM_WAGE.
@Y: That's what i was thinking. You don't want to initialize your constructor with a negative wage right? Oh well, I guess I'll find out if I got it wrong when we get our lab test back
About the wage being less than the minimum wage in the constructor, I think that it doesn't really matter if you covered that case because it's not mentioned in the API. It's only mentioned in the setWage() method so that is the only place you need to handle it.
We are not responsible for the logic of the programs outside of the API. We have to assume the creator of the API knew what they were doing regardless of how weird it seems (At least in this course). As far as I'm concerned, if it's not in the API then I am not responsible and in fact it could even be a negative thing to go off and assume you know what the creator of the API wanted.
1) When you wrote the getName() in the Person class, why does the method return name and not this.name?
2) When you wrote the toString() in the Person class, you first define the String s = this.getClass().getName(). I have experimented with this line of code and I am rather confused by the results. I see that this.getClass() will not produce the expected output, while I see that including .getName() does produce the desired output. I cannot figure out why .getName() produces the desired output. Would it be possible to explain the logic behind this particular choice of syntax?
I think the class was generally confused by your lecture on the singleton class. You gave an extremely simple example of how to implement a singleton class, but you never explained what the purpose of a singleton class is, nor did you give examples of a situation in which a singleton class would be used.
quick question about the test: will it cover recursion?
ReplyDeleteJust to bring to your attention once again, there seems to be a problem (as you mentioned) with the name of the tester file being Tester.java, here is what happens in that case --
ReplyDeletehttp://i55.tinypic.com/1znohnq.jpg
Could you please help us on that? I am even more interested in this because the error that comes up is pretty weird.
yea... especially considering it seems to be a simple .java file, and clearly the output is not consistent with the file itself. What is generating this output (I got the exact same output)?
ReplyDeleteIn lab 5, under the bankAccount copy constructor, why don't you deep copy the Person object in your solution. If I change the person object of the original bank account, I change it in the copy.
ReplyDeleteThe Tester error is due to having the Type API installed (back from CSE1020), which comes with a class called Tester. Because Java looks for classes there first, it takes priority over your own class.
ReplyDeleteIf you delete the jar file from the jre/ext folder it should work fine.
@5:44.
ReplyDeleteThe reason he didn't bother to copy the Person object is because a copy will be made anyway in the other constructor he called (line 14).
Although I would argue it would be safer to make a copy in the constructor as well instead of relying on the other constructor to do so (and it doesn't hurt).
Or, you could just rename the file to something else(Tester2.java; change the class name in the code as well) and it should work fine.
ReplyDeleteJonathan is right.
ReplyDeleteI don't have the Type API on my computer and I don't get any error when running a class called "Tester".
Today was a tough test :'( I don't know if I only felt it or was it for every one. Mine didn't even compile
ReplyDelete@ 3:01 PM
ReplyDeleteUh Oh.
@ 3:01PM
ReplyDeleteIt was a bit difficult but it was doable and as the prof said that it's going to get difficult from now on so expect everything tough now. Wait till you get a real taste of Link List
Really? I thought it was fair. Of course I would think that.
ReplyDeleteI thought it test was fairly easy. I've the docs needed to specify the the constructor, throw an exception if the employee created has wage less than minimum wage, however.
ReplyDeleteWow, I must've had a brain aneurysm when I wrote that last comment.
ReplyDeleteThe last post in (better) English:
I thought the test was fairly easy. According to logic: the API documentation for the Employee class should have specified for the constructor to throw an exception if the employee created has wage less than minimum wage, however.
Couldn't you have just used .setWage(double wage) method?
ReplyDeleteI found it pretty easy as well.
ReplyDeleteI would say it was a bit easier than the labs, which themselves weren't that hard.
@3:01
ReplyDeleteThe labtest was fair. Either you didn't practice enough (Practice labs were pretty much the same as the labtest) or you made one of those silly mistakes.
Sir, THANK YOU VERY MUCH for these solutions. REALLY REALLY help full to study for the lab test. really appreciate it, please do so for the upcoming labs as well.
ReplyDeleteTHANK YOU :)
We didn't cover Chapter 9 in class.
ReplyDelete@dennis: I don't think so. "this.wage" is only declared, but doesn't have a value assigned to it. If you use the setWage method, the variable will never have a value if you pass a wage less than the MINIMUM_WAGE in the constructor. setWage method doesn't throw error exceptions either... it just changes the value if the wage is greater than MINIMUM_WAGE.
ReplyDeleteThe labtest that we did today was short...or maybe I was missing something.
ReplyDeleteWe just had to add the areas of Circle or Square in the interface type array.
@Y: That's what i was thinking. You don't want to initialize your constructor with a negative wage right? Oh well, I guess I'll find out if I got it wrong when we get our lab test back
ReplyDeleteAbout the wage being less than the minimum wage in the constructor, I think that it doesn't really matter if you covered that case because it's not mentioned in the API. It's only mentioned in the setWage() method so that is the only place you need to handle it.
ReplyDeleteWe are not responsible for the logic of the programs outside of the API. We have to assume the creator of the API knew what they were doing regardless of how weird it seems (At least in this course). As far as I'm concerned, if it's not in the API then I am not responsible and in fact it could even be a negative thing to go off and assume you know what the creator of the API wanted.
@ Woody 8:06 PM
ReplyDeleteyes, i think that was it.
A few questions about your solution to lab 5:
ReplyDelete1) When you wrote the getName() in the Person class, why does the method return name and not this.name?
2) When you wrote the toString() in the Person class, you first define the String s = this.getClass().getName(). I have experimented with this line of code and I am rather confused by the results. I see that this.getClass() will not produce the expected output, while I see that including .getName() does produce the desired output. I cannot figure out why .getName() produces the desired output. Would it be possible to explain the logic behind this particular choice of syntax?
I think the class was generally confused by your lecture on the singleton class. You gave an extremely simple example of how to implement a singleton class, but you never explained what the purpose of a singleton class is, nor did you give examples of a situation in which a singleton class would be used.
ReplyDelete@ 4:25 PM
ReplyDelete"return name" is the same as "return this.name;"
I think "this.getClass().getName()"
is the same as "this.getName" and "this.name"