using java help me create these two classes ArrayLists Creat
using java help me create these two classes
(ArrayLists) Create a Class to practice with ArrayLists. Call your class “PresidentsAA”, and store it in a file called“PresidentsAA.java”. In this class include just a no-args constructor.Have main start things out by instantiating the class and calling the no-args constructor. In the no-args constructor, first Create an ArrayList for Strings. Fill this list with the names of the first 10 presidents of the U.S. Then ask the user for input. Ask the User which number president that they want to see. If they enter a 3, that means they want to see the name of the 3rd U.S. president. Your code should print out “Thomas Jefferson”.
(Vectors) Create a Class to practice with Vectors. Call your class “PresidentsVec”, and store it in a file called “PresidentsVec.java”.Do the same as #1 above, but this time use a Vector instead of an ArrayList.
Solution
// file PresidentsAA.java
import java.util.*;
public class PresidentsAA{
ArrayList<String> presidents = new ArrayList<String>();
public PresidentsAA(){
// add eleemnt to arraylist
presidents.add(\"George Washington\");
presidents.add(\"John Adams\");
presidents.add(\"Thomas Jefferson\");
presidents.add(\"James Madison\");
presidents.add(\"James Monroe\");
presidents.add(\"John Quincy Adams\");
presidents.add(\"Andrew Jackson\");
presidents.add(\"Martin\");
presidents.add(\"William H. Harrison\");
presidents.add(\"John Tyler\");
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int p = sc.nextInt();
// get element from array list
PresidentsAA pa = new PresidentsAA();
System.out.println(pa.presidents.get(p));
}
}
// PresidentsVec.java file
import java.util.*;
public class PresidentsVec{
Vector<String> presidents = new Vector<String>();
public PresidentsVec(){
// add elements to vector
presidents.add(\"George Washington\");
presidents.add(\"John Adams\");
presidents.add(\"Thomas Jefferson\");
presidents.add(\"James Madison\");
presidents.add(\"James Monroe\");
presidents.add(\"John Quincy Adams\");
presidents.add(\"Andrew Jackson\");
presidents.add(\"Martin\");
presidents.add(\"William H. Harrison\");
presidents.add(\"John Tyler\");
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int p = sc.nextInt();
PresidentsVec pa = new PresidentsVec();
// get element from vector
System.out.println(pa.presidents.get(p));
}
}

