If anyone still having trouble on submitting their files, here's a tutorial with pictures. It explains how to locate your file (if using eclipse), some basic linux command, and how the submit command works
Yes, that's the way you should do it, because you're also supposed to increment the static numberOfAccounts in your main constructor. So you wouldn't have to repeat it again.
@3:13 PM You are not answering his question, incrementing the bank account number could be done in his first way too.
@2:12 PM Yes you are doing it right. Although I would like some clarification as well. Through my testing, you are doing it the correct way, but I keep thinking that I am passing references the way you and I have done it, not values. Perhaps the professor can shed some light on this confusion.
With all due respect, I am having a lot of difficulty assessing my progress throughout this course like I was able to in 1020. We were regularly assigned problems, the labs were a lot more helpful, and we regularly received individual feedback. May I request that you assign problems that you would recommend to be useful from the book, and perhaps for the labs provide tester classes to test our implementations? At least that way we know that we are on the right track.
7:51: Like Woody said, there are problems in the back of each chapter. Would you like me to specify some of those problems? Best to do as many of them as possible.
Woody: A couple of lectures ago, I added a mutator to Circle -- i.e., setRadius -- as an example to show why a copy constructor is needed. Thereafter, I removed setRadius from Circle and added it to MutableCircle, which is mutable. Without setRadius, Circle is immutable.
that would be extremely helpful if you could specify some problems that you feel will allow us to best practice the skills we have been covering in class. With all other courses, it is nearly impossible to go through each problem in the text, and with your guidance, we can study as effectively as possible
How do we direct course material related questions for which there is no blog topic. Last semester we used a forum format in which students could create their own topics to address questions and concerns about the course. Right now, I feel as though I just have to post questions irrelevant to the blog topic, and other students who may have the same question/ may be able to answer my question, will simply miss it.
with respect to naming variables and naming conventions. If we wanted to define an acronym such as ID or DVD... do we caps the first letter, or all letters of the acronym?
I think that you should always follow the naming conventions that Professor Eckford taught us. If ID and DVD are variables then they should be written as id and dvd respectively. If there was a dvd player method or something like that, then you would write it as dvdPlayer()
Slightly off topic, and also old... but nevertheless, still quite funny. Check out Google's view on recursion : http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=recursion
My program tells me that this(name, balance, month, day, year); is wrong because they are not static, but when i make them static, those same variables should be accessed in a static way. ie BankAccount2.name.
public BankAccount2(String name, double balance, String month, int day, int year) { this.name = name; this.balance = balance; this.month = month; this.day = day; BankAccount2.year = year; } ignore eclipse? or should i do something else differently?
I'm having a bit of trouble with my getDate method in my BankAccount2 which is supposed to return the date. Don't really know how to do it. Can someone please help me? Thank you.
if you are talking about chapter 5 question 2, you dont need to find the LCD... check it out.
take two fractions a/b and c/d... ad = cb if the two fractions are equal, but in different terms. Therefor, just define 2 int values, and check their equality based upon the above relationship.
what i did for the bankaccount2 was: public BankAccount2(String name, double balance, String month, int day, int year) { this(name, new Date(month, day, year); }
that way for get date, you can just send a copy of the reference DATE. also: I didn't create any private variables such as month, day , etc but just a date object in the beginning. but I'm not sure if its correct :D
Thanks anonymous 7:04 @professor Eckford: If theres no private variables for the date then you would be doing everything through the Date class. Then for the first BankAccount(String name, double balance, String month, int day, int year), you should just send month day year automatically to a date object that you can call when you want to get date. Is that how you wanted it to be done?
I meant that there would be no private variable for the date in my BankAccount2 class.They would though exist in the Date class. Anonymous 7:04 said he just created a date object. //how i tried to do it BankAccount(String name, double balance, String month, int day, int year){ this.name = name; this.balance = balance; Date date = new Date(month, day, year); }
@ Mohammad It would be better if you call the other constructor through this one as in u create a private object: private Date date; then create your constructor public BankAccount2(String name, double balance, String month, int day, int year) { this(name, new Date(month, day, year); }
you r actually calling this constructor each time: public BankAccount2(String name, Date date) { this.name = name; this.date = new Date(date); }
got a quick question. In lab 3. when accessing the date -> public Date getDate() { return new Date(date); or new Date(this.date); } does it make a diff or its for BEST practice?
If anyone still having trouble on submitting their files, here's a tutorial with pictures. It explains how to locate your file (if using eclipse), some basic linux command, and how the submit command works
ReplyDeletehttp://www.cse.yorku.ca/~joanna/SubmitCommand.pdf
Hi everyone,
ReplyDeleteI have short question about the way I wrote my copy constructor for the BankAccount2 class. Given that I wrote my first constructor this way:
public BankAccount2(String name, double balance, Date date)
{
this.name = name;
this.balance = balance;
this.date = new Date(date);
}
I then wrote my copy constructor the following way:
public BankAccount2(BankAccount2 otherBankAccount)
{
this(otherBankAccount.name, otherBankAccount.balance, otherBankAccount.date);
}
This copy constructor passed the compiler, but what I was wondering was if it's correct or ok to pass otherBankAccount.date.
Yes, that's the way you should do it, because you're also supposed to increment the static numberOfAccounts in your main constructor. So you wouldn't have to repeat it again.
ReplyDelete@3:13 PM You are not answering his question, incrementing the bank account number could be done in his first way too.
ReplyDelete@2:12 PM Yes you are doing it right. Although I would like some clarification as well. Through my testing, you are doing it the correct way, but I keep thinking that I am passing references the way you and I have done it, not values. Perhaps the professor can shed some light on this confusion.
Regards,
4:55 PM
2:12 did it right. The copy only needs to be made once, which happens correctly in the 3-parameter constructor.
ReplyDeleteIf you wanted to be (unnecessarily) paranoid, you could instead write
public BankAccount2(BankAccount2 otherBankAccount)
{
this(otherBankAccount.name, otherBankAccount.balance, new Date(otherBankAccount.date));
}
but since a copy is already being made, this extra copy is just a waste of memory.
Hello Professor,
ReplyDeleteWith all due respect, I am having a lot of difficulty assessing my progress throughout this course like I was able to in 1020. We were regularly assigned problems, the labs were a lot more helpful, and we regularly received individual feedback. May I request that you assign problems that you would recommend to be useful from the book, and perhaps for the labs provide tester classes to test our implementations? At least that way we know that we are on the right track.
Thank you very much.
Kind Regards
@ 7:51 PM
ReplyDeleteAfter each subsection of the textbook, there is an exercise. The solution to those exercises are at the end of each Chapter. Try those one.
Why is
ReplyDeleteCircle c = new Circle();
Circle d = c;
immutable?
Why is
Circle c = new Circle();
Circle d = c;
d.setRadius(2);
mutable?
What's the professor's e-mail? I can't find it.
ReplyDelete7:51: Like Woody said, there are problems in the back of each chapter. Would you like me to specify some of those problems? Best to do as many of them as possible.
ReplyDeleteWoody: A couple of lectures ago, I added a mutator to Circle -- i.e., setRadius -- as an example to show why a copy constructor is needed. Thereafter, I removed setRadius from Circle and added it to MutableCircle, which is mutable. Without setRadius, Circle is immutable.
My contact info is here:
https://wiki.cse.yorku.ca/user/aeckford/contact
Professor Eckford,
ReplyDeletethat would be extremely helpful if you could specify some problems that you feel will allow us to best practice the skills we have been covering in class. With all other courses, it is nearly impossible to go through each problem in the text, and with your guidance, we can study as effectively as possible
Although note that the exercises in the book only ask to write up snippets of codes (or at most one function) and never full apps.
ReplyDeleteMight be more useful for the prof to recommend some of the Programming Projects that follow the exercises instead.
I second, fourth and fifth that, please assign us some problems, please sir. I feel I'm doing nothing in this class.
ReplyDeleteTotally agree! It would really help us practice for the test coming up.
ReplyDeleteSir,
ReplyDeleteHow do we direct course material related questions for which there is no blog topic. Last semester we used a forum format in which students could create their own topics to address questions and concerns about the course. Right now, I feel as though I just have to post questions irrelevant to the blog topic, and other students who may have the same question/ may be able to answer my question, will simply miss it.
Also,
ReplyDeletewith respect to naming variables and naming conventions. If we wanted to define an acronym such as ID or DVD... do we caps the first letter, or all letters of the acronym?
@January 29, 2011 12:16 PM
ReplyDeleteI think that you should always follow the naming conventions that Professor Eckford taught us. If ID and DVD are variables then they should be written as id and dvd respectively. If there was a dvd player method or something like that, then you would write it as dvdPlayer()
hi guys,
ReplyDeletedoes ny1 know abt finding the greatest common divisor as asked in ques 2 from the text book??
Hey, question 2 guy. There are many ways to do this. If my code doesnt cover all cases please tell me which one. :)
ReplyDeletepublic String toLowestTerm(Fraction fraction)
{
if(denominator/numerator == (double)denominator/numerator)
{
denominator = denominator/numerator;
numerator = numerator/numerator;
}else if((denominator/2 == (double)denominator/2)&&(numerator/2 == (double)numerator/2))
{
denominator = denominator / 2;
numerator = numerator / 2;
}
return (this.numerator + "/" + this.denominator);
}
You can just use the enclidean algorithm (check wikipedia):
ReplyDeletepublic int getGCD(int a, int b)
{
if (b == 0)
return a;
else return getGCD(b, a % b);
}
Slightly off topic, and also old... but nevertheless, still quite funny. Check out Google's view on recursion : http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=recursion
ReplyDeletelol^
ReplyDeleteDid you mean: recursion ....its recursive
alright im dropping out D=
No but seriously
public BankAccount2(BankAccount2 otherAccount)
{
this(name, balance, month, day, year);
numberOfAccounts = numberOfAccounts++;
}
My program tells me that this(name, balance, month, day, year); is wrong because they are not static, but when i make them static, those same variables should be accessed in a static way. ie BankAccount2.name.
public BankAccount2(String name, double balance, String month, int day, int year)
{
this.name = name;
this.balance = balance;
this.month = month;
this.day = day;
BankAccount2.year = year;
}
ignore eclipse? or should i do something else differently?
public BankAccount2(String name, double balance, Date date)
ReplyDelete{
this.name = name;
this.balance = balance;
numberOfAccounts = numberOfAccounts++;
}
BankAccount2 account = new BankAccount2("Mohammad", 1000000, new Date("January", 2, 1990));
regardless of whether or not it works, is this correct? Is this how the 2nd constructor should have been done?
I'm having a bit of trouble with my getDate method in my BankAccount2 which is supposed to return the date. Don't really know how to do it. Can someone please help me? Thank you.
ReplyDelete@ Anonymous January 31, 2011 3:28 PM
ReplyDelete@Mohammad
if you are talking about chapter 5 question 2, you dont need to find the LCD... check it out.
take two fractions a/b and c/d... ad = cb if the two fractions are equal, but in different terms. Therefor, just define 2 int values, and check their equality based upon the above relationship.
what i did for the bankaccount2 was:
ReplyDeletepublic BankAccount2(String name, double balance, String month, int day, int year)
{
this(name, new Date(month, day, year);
}
that way for get date, you can just send a copy of the reference DATE.
also:
I didn't create any private variables such as month, day , etc but just a date object in the beginning.
but I'm not sure if its correct :D
Mohammad: Anonymous 7:04 is right.
ReplyDeleteThanks anonymous 7:04
ReplyDelete@professor Eckford: If theres no private variables for the date then you would be doing everything through the Date class. Then for the first BankAccount(String name, double balance, String month, int day, int year), you should just send month day year automatically to a date object that you can call when you want to get date. Is that how you wanted it to be done?
Mohammad: What do you mean by "no private variables for the date"? The rest of your comment is correct though.
ReplyDeleteI meant that there would be no private variable for the date in my BankAccount2 class.They would though exist in the Date class. Anonymous 7:04 said he just created a date object.
ReplyDelete//how i tried to do it
BankAccount(String name, double balance, String month, int day, int year){
this.name = name;
this.balance = balance;
Date date = new Date(month, day, year);
}
@ Mohammad
ReplyDeleteIt would be better if you call the other constructor through this one
as in u create a private object:
private Date date;
then create your constructor
public BankAccount2(String name, double balance, String month, int day, int year)
{
this(name, new Date(month, day, year);
}
you r actually calling this constructor each time:
public BankAccount2(String name, Date date)
{
this.name = name;
this.date = new Date(date);
}
Which version of Eclipse should I download?
ReplyDeletehttp://www.eclipse.org/downloads/
got a quick question. In lab 3. when accessing the date ->
ReplyDeletepublic Date getDate()
{
return new Date(date);
or
new Date(this.date);
}
does it make a diff or its for BEST practice?
thnx in advance.