Wednesday, January 26, 2011

Aggregation and Lab 3 open thread

Post your comments about this week's material and Lab 3 here.

33 comments:

  1. 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

    http://www.cse.yorku.ca/~joanna/SubmitCommand.pdf

    ReplyDelete
  2. Hi everyone,

    I 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.

    ReplyDelete
  3. 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
  4. @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.

    Regards,

    4:55 PM

    ReplyDelete
  5. 2:12 did it right. The copy only needs to be made once, which happens correctly in the 3-parameter constructor.

    If 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.

    ReplyDelete
  6. Hello Professor,

    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.

    Thank you very much.

    Kind Regards

    ReplyDelete
  7. @ 7:51 PM
    After each subsection of the textbook, there is an exercise. The solution to those exercises are at the end of each Chapter. Try those one.

    ReplyDelete
  8. Why is
    Circle c = new Circle();
    Circle d = c;
    immutable?

    Why is
    Circle c = new Circle();
    Circle d = c;
    d.setRadius(2);
    mutable?

    ReplyDelete
  9. What's the professor's e-mail? I can't find it.

    ReplyDelete
  10. 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.

    My contact info is here:

    https://wiki.cse.yorku.ca/user/aeckford/contact

    ReplyDelete
  11. Professor Eckford,

    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

    ReplyDelete
  12. 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.

    Might be more useful for the prof to recommend some of the Programming Projects that follow the exercises instead.

    ReplyDelete
  13. I second, fourth and fifth that, please assign us some problems, please sir. I feel I'm doing nothing in this class.

    ReplyDelete
  14. Totally agree! It would really help us practice for the test coming up.

    ReplyDelete
  15. Sir,

    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.

    ReplyDelete
  16. Also,

    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?

    ReplyDelete
  17. @January 29, 2011 12:16 PM

    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()

    ReplyDelete
  18. hi guys,
    does ny1 know abt finding the greatest common divisor as asked in ques 2 from the text book??

    ReplyDelete
  19. Hey, question 2 guy. There are many ways to do this. If my code doesnt cover all cases please tell me which one. :)

    public 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);
    }

    ReplyDelete
  20. You can just use the enclidean algorithm (check wikipedia):

    public int getGCD(int a, int b)
    {
    if (b == 0)
    return a;
    else return getGCD(b, a % b);
    }

    ReplyDelete
  21. 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

    ReplyDelete
  22. lol^
    Did 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?

    ReplyDelete
  23. public BankAccount2(String name, double balance, Date date)
    {
    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?

    ReplyDelete
  24. 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
  25. @ Anonymous January 31, 2011 3:28 PM
    @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.

    ReplyDelete
  26. 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

    ReplyDelete
  27. 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?

    ReplyDelete
  28. Mohammad: What do you mean by "no private variables for the date"? The rest of your comment is correct though.

    ReplyDelete
  29. 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);
    }

    ReplyDelete
  30. @ 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);
    }

    ReplyDelete
  31. Which version of Eclipse should I download?

    http://www.eclipse.org/downloads/

    ReplyDelete
  32. 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?

    thnx in advance.

    ReplyDelete