d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Question About Array Comparison
Prev12
Add Reply New Topic New Poll
Member
Posts: 1,307
Joined: Apr 9 2007
Gold: 1,676.45
Nov 6 2014 07:06pm
Quote (Minkomonster @ Nov 6 2014 09:04pm)
Absolutely.

However, I feel this line is wrong:

double[] data2 = stat1.getData();

I feel like that should be

double[] data2 = stat2.getData();

Which would make more sense, and give false for data1=data2 while true for the others. It also better shows what I feel the assignment is aiming for.


Ok great, Thanks again! Yeah I thought that it was a typo and it should be stat2.getData as well, then it would return false, true, true. I was just making sure I wan't missing something with how it was written. Happy to see it wasn't just me

This post was edited by ice060788 on Nov 6 2014 07:08pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 6 2014 07:07pm
Quote (Minkomonster @ Nov 6 2014 08:04pm)
Absolutely.


You're no fun. Why can't you pull a killg0re and play devil's advocate? maybe i'll try that next time.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 6 2014 07:08pm
Quote (ice060788 @ Nov 6 2014 08:06pm)
Ok great, Thanks again!


Check my edit. And then recheck your code against the assignment.
Member
Posts: 1,307
Joined: Apr 9 2007
Gold: 1,676.45
Nov 6 2014 07:09pm
Quote (Minkomonster @ Nov 6 2014 09:08pm)
Check my edit. And then recheck your code against the assignment.


Yeah I did, I even emailed the instructor about it and waiting to here back from him. The code he provided has stat1.getData and not stat2.getData which is what I thought it should be
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 6 2014 07:11pm
Quote (ice060788 @ Nov 6 2014 08:09pm)
Yeah I did, I even emailed the instructor about it and waiting to here back from him. The code he provided has stat1.getData and not stat2.getData which is what I thought it should be


AH! See this is what happens when you don't read the instructions:

getData()—This is an accessor (get or getter) method used to retrieve the values of data. This
method should not return a reference to data.Instead, it should create a new array containing
exactly the values contained in data, and then return a reference to this new array
.

You aren't doing that. if you did that, then you would get the false, true, true you are looking for.


Also,

setData(double[] d) —This is a mutator (set or setter) method used to set the values of the
data array. The method should create a new array containing exactly the elements of d and assign to
data a reference to this new array (that is, the method should not simply assign d to data)
.

You aren't doing that either.

This post was edited by Minkomonster on Nov 6 2014 07:13pm
Member
Posts: 1,307
Joined: Apr 9 2007
Gold: 1,676.45
Nov 6 2014 07:15pm
Ahh, that makes sense. Don't know how I missed that. Thanks! That clears up my problem!
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll