Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>I'm assuming that the variable <strong>biggest</strong> is the variable that is holding the total width.</em></p> <p>You are doing a few things wrong with your code, and you'll have to fix these first</p> <ol> <li><p>You are reusing the nPictsInAlbum multiple times for different types of variables. You shouldn't do that. I'm not a java programmer but it is at least a bad practice in other languages because it causes confusion. You use that variable in the <code>addPicture</code> method to track the latest index. But in the <code>explore</code> method, you use it to temporarily store an individual picture that you're accessing.</p></li> <li><p>In the <code>explore</code> method, you are not accessing the properties\fields of the picture object. Without knowing what properties\fields a picture object has, we cannot correct your code entirely. </p></li> </ol> <p>If you fix those two problems, then the logic errors you have in the <code>explore</code> method are</p> <ol> <li><p>(assuming that the variable <code>biggest</code> is the total width, if so you should rename it to be more descriptive) You are only setting the total width when you have figured out that the height of the current picture you have is bigger in height than a previously stored picture. You need to always set total width when you loop each picture regardless.</p></li> <li><p>When you set the total width of the picture, you are replacing the total, not adding it. in your example <code>biggest = value</code> would not add it. You would want <code>biggest = biggest + value</code> to do that</p></li> </ol> <hr> <p>You want to make sure to take your time when you make the methods. Tactfully think about what is it going to do, what variables will you need, what other variables will you access, and what will you do with them. For example, if the point of <code>explore</code> is to determine the max height and total width you would think like this:</p> <ol> <li>I need a reusable piece of code that will determine the maximum height out of all pictures. It will also get a total width of all pictures.</li> <li>Therefore I will need two variables: maxHeight and totalWidth.</li> <li>From this code I need iterate over an array of pictures.</li> <li>In that loop, I need to check to see if the picture's height is greater then maxHeight. If so, I need to set maxHeight to the picture's height</li> <li>To access the picture's height, I would need to use the (I don't know what the picture's object structure is so I'm guessing) picture.height property.</li> <li>Regardless of the height of the picture, I need to add the width of the picture to a running total. So I would use <code>totalWidth = totalWidth + picture.width</code></li> </ol> <p>Hope this helps you to get your code cleaned up and working better.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload