Showing that matter has an atomic nature using Java program

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
s3a
Messages
828
Reaction score
8

Homework Statement


http://pastebin.com/aS3vTR2V

Homework Equations


N/A

The Attempt at a Solution


I'm confused about what I need to do for the BlobFinder constructor. Someone told me that I should “initialize the ArrayList blobs”, then “create a 2D array of booleans called marked, having the same dimensions as picture.” then “enumerate the pixels of picture, and for each pixel (i, j): 1. Create a Blob object called blob., 2. Call findBead() with the right arguments. and 3. Add blob to blobs if it has a non-zero mass.”,

but I'm confused as to why that is what I need to do. Don't I only need to do the following for the BlobFinder contructor?:

Java:
for(int i = 0; i < picture.height(); i++) {

    for(int j = 0; j < picture.width(); j++) {

       Blob blob = new Blob();
       blob.add(i, j);
       blobs.add(blob);
    }
}

I don't even need someone to write Java code for me, but if someone could just explain to me in words and/or pseudocode what I need to do, it would help a lot.

Any help would be greatly appreciated!
 
Last edited by a moderator:
Physics news on Phys.org
With respect to ArrayList objects, yes you need to initialize them before you add something to them

Java:
    ArrayList blobs = new ArrayList();

If you don't do that then you'll get a NullPointerException thrown when you try to execute the blobs.add(blob) in your "for" loop.
 
According to the instructions, the constructor looks like this:

Code:
// find all blobs in the picture using the luminance threshold tau
public BlobFinder(Picture picture, double tau)

So the constructor accepts the picture, and the constant ##\tau##, which is used to classify the pixels as background or foreground. You will classify each pixel as it is read from the picture as background or foreground inside the constructor itself.

You also know a polystyrene bead (a blob) is represented by a disc-like shape, which is composed of 25 connected foreground pixels.

Once you have found 25 connected foreground pixels, you have found a blob. A new field: ArrayList<Blob> blobs, should be used to hold onto the blobs once you've found them.
 
Thanks for the replies.

I thought that a blob was one pixel and a bead was 25+ blobs, but I misread the instructions; 1 blob = 1 bead.

I'm currently confused as to what the purpose of the array pointed to by the variable named "marked" (in the BlobFinder class) is for.

Should the findBead method (in the BlobFinder class) have a return type of Blob?

Also, are the int i and int j parameters of the findBead method (in the BlobFinder class) supposed to be the horizontal and vertical coordinates of the center of mass of a Blob, or can it be any point and not have to be a center of mass?
 
Thanks for the replies.

I thought that a blob was one pixel and a bead was 25+ blobs, but I misread the instructions; 1 blob = 1 bead.

I'm currently confused as to what the purpose of the array pointed to by the marked variable is for.

Should the findBead method (in the BlobFinder class) have a return type of Blob?

There is no findBead() method.

If you tried to understand the instructions more carefully, you would see you were given an API for the BlobFinder class:

Code:
Next, write a data type BlobFinder that has the following API. Use depth-first search to efficiently identify the blobs.

public class BlobFinder
------------------------------------------------------------------------------------------------
// find all blobs in the picture using the luminance threshold tau
public BlobFinder(Picture picture, double tau)

// return the number of beads with >= P pixels
public int countBeads(int P)

// return all beads with >= P pixels
public Blob[] getBeads(int P)

The details about the BlobFinder constructor were mentioned in post #3. Make it so the constructor initializes the ArrayList<Blob> blobs field. Use depth-first-search to efficiently identify the blobs.

This field will be useful in the following methods.

Using a for each construct, or an iterator if you prefer, count the number of beads with ##\geq P## pixels and return the result. Remember ##P## is a command line argument.

Using the loop of your choice, return a reference to a Blob[] array containing all the blobs with ##\geq P## pixels and return the result.