Showing that matter has an atomic nature using Java program

In summary: Remember ##P## is a command line argument.The instructions tell you to initialize the fields in the constructor, but they leave out one very important detail: you need to call the ArrayList<Blob> blobs field's constructor.Since the field is not initialized, you will get a NullPointerException when you try to add something to blobs.The purpose of the marked field is not specified in the instructions, but it seems likely it is used for tracking which blobs have been found.The findBead method (in the BlobFinder class) has a return type of Blob, which means you can use it to find blobs in a picture.The int
  • #1
s3a
818
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
  • #2
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.
 
  • #3
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.
 
  • #4
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?
 
  • #5
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.
 

1. How can a Java program show that matter has an atomic nature?

A Java program can show that matter has an atomic nature by simulating the behavior of atoms and molecules using mathematical equations and algorithms. This can be done by creating objects to represent atoms and their properties such as mass, charge, and position, and then using these objects to model the interactions between atoms.

2. What are some examples of Java programs that demonstrate the atomic nature of matter?

Some examples of Java programs that demonstrate the atomic nature of matter include molecular dynamics simulations, Monte Carlo simulations, and quantum chemistry programs. These programs use different approaches to model the behavior of atoms and molecules, but they all rely on the principles of atomic theory and the laws of physics to accurately represent the behavior of matter.

3. How do Java programs handle the complexity of atomic interactions?

Java programs handle the complexity of atomic interactions by using computational techniques such as approximations, numerical methods, and parallel computing to efficiently calculate the interactions between a large number of atoms. These programs also incorporate physical models and theories to accurately simulate the behavior of matter at the atomic level.

4. Can a Java program accurately represent the behavior of all types of matter?

While Java programs can accurately represent the behavior of most types of matter, there are some limitations. For example, quantum mechanical effects such as tunneling and entanglement may be difficult to simulate accurately using classical Java programs. Additionally, extremely large or complex systems may require more advanced computational methods or specialized software to accurately represent their behavior.

5. What are the benefits of using a Java program to study the atomic nature of matter?

Using a Java program to study the atomic nature of matter allows for a more efficient and cost-effective method compared to conducting physical experiments. These programs also offer the ability to easily manipulate and control various parameters, making it easier to study the effects of different conditions on the behavior of matter. Additionally, Java programs allow for visualization of the atomic interactions, providing a better understanding of the complex nature of matter.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
2
Replies
58
Views
12K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Back
Top