package arrays;
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class Arrays
{

public void one()
{ String[] names = new String[30];
// The size of an array is fixed
int numElements = 0;
// Use numElements to keep track of how many positions
// in 'names' actually are being used
names[0] = "Itai Geller"; numElements++;
names[1] = "Annabella Russo"; numElements++;
names[2] = "Raghav Potdar"; numElements++;
names[3] = "Asadullah Saad"; numElements++;
names[4] = "Evan Djeu" ; numElements++;
names[5] = "Noza Bahridinova"; numElements++;
names[6] = "Kaitlin Iong"; numElements++;
names[7] = "Andrew Schugel"; numElements++;
names[8] = "Nicholas Mills"; numElements++;
names[9] = "Andrew Martin"; numElements++;
names[10] = "Sebastian Pata"; numElements++;
names[11] = "Khushi Parikh"; numElements++;
names[12] = "Charles Acosta"; numElements++;
names[13] = "Marcus Iong"; numElements++;
names[14] = "Matt Perez"; numElements++;
names[15] = "Aaron Kass"; numElements++;
names[16] = "Antoni Zanicki"; numElements++;
names[17] = "Steven Clendenny"; numElements++;
names[18] = "Zizhong Liu"; numElements++;
names[19] = "Luke Rivera"; numElements++;
names[20] = "Siddharth Paul"; numElements++;
names[21] = "Donald Trump"; numElements++;
names[22] = "Nancy Pelosi"; numElements++;
names[23] = "Chuck Schumer"; numElements++;
names[23] = null; numElements--;
names[22] = null; numElements--;
names[21] = null; numElements--;

for (String name : names)
System.out.println(name);
}

public void two()
{ // an alternative way of creating an array
int[] squares = { 1, 4, 9, 16, 25, 36 };
String[] names = { "Mary", "Jose", "Susan" };
}

public void ArrayListIntro()
{ ArrayList names = new ArrayList();
names.add("Donald Trump");
names.add("Nancy Pelosi");
names.add("Chuck Schumer");
JOptionPane.showMessageDialog(null, names);
names.add(0, "Mike Pence");
JOptionPane.showMessageDialog(null, names);
names.set(0, "Mike Pompeo");
JOptionPane.showMessageDialog(null, names);
names.remove("Mike Pompeo") ;
JOptionPane.showMessageDialog(null, names);
names.remove(1);
JOptionPane.showMessageDialog(null, names);
JOptionPane.showMessageDialog(null, "size: " + names.size());
}

public void three()
{ int[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
// find the sum of these numbers:
int k, total = 0;
for (k = 0; k < numbers.length; k++)
{ total = total + numbers[k];
}
JOptionPane.showMessageDialog(null, total);
// an example of a FOR - EACH loop
total = 0;
for (int num : numbers)
{ total = total + num;
}
JOptionPane.showMessageDialog(null, total);
}

public static void main(String[] args)
{ Arrays a = new Arrays();
a.one();
//a.two();
//a.ArrayListIntro();
//a.three();
}
}