Jess Ericsson wrote:.. but the second constructor where I'm supposed to create an object with an array as parameter doesn't work. I get an object "m" but it's always empty.
Jess Ericsson wrote:*...I've been given a sheet with rules for coding and I am going to make sure I follow all of them before I submit but my main focus right now is finishing the code.
*I'm probably not allowed to use .clone or anything else since I'm supposed to write basic code.
Junilu Lacar wrote:this article...
https://www.industriallogic.com/xp/refactoring/composeMethod.html
Jess Ericsson wrote:I'm taking my first Java course ever and can not seem to finish this week's assignment on my own. I've created a class called Measurements
in which values are stored in an array connected to an object. I've created a lot of methods doing all kinds of stuff with the array that works just fine but
the second constructor where I'm supposed to create an object with an array as parameter doesn't work. I get an object "m" but it's always empty.
Tried to paste the lines of code that I think are relevant. Any help will be much appreciated.
sohail hussain wrote:
Jess Ericsson wrote:I'm taking my first Java course ever and can not seem to finish this week's assignment on my own. I've created a class called Measurements
in which values are stored in an array connected to an object. I've created a lot of methods doing all kinds of stuff with the array that works just fine but
the second constructor where I'm supposed to create an object with an array as parameter doesn't work. I get an object "m" but it's always empty.
Tried to paste the lines of code that I think are relevant. Any help will be much appreciated.[/quot
i tried it and got this result
public ara2(double[] b)
{
for(double d:b)
{
System.out.println(d);
}
}
public static void main(String[] args)
{
double[] a= {2,3,5};
ara2 c= new ara2(a);
sohail hussain wrote:
in the second constructor you had used formal parameter as double array, you are sending reference of array which stores values not the array so remove the [] in the second constructor as only only double and compile it
All things are lawful, but not all things are profitable.
sohail hussain wrote:
i tried it and got this result
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |