0% found this document useful (0 votes)
28 views2 pages

Rhenz List

The document describes a Java class called SanPedro_List that implements methods for adding, editing, deleting, searching, and displaying items in an ArrayList. The main method uses a switch statement to allow the user to select these options in a menu-driven program.

Uploaded by

Rhenz San Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Rhenz List

The document describes a Java class called SanPedro_List that implements methods for adding, editing, deleting, searching, and displaying items in an ArrayList. The main method uses a switch statement to allow the user to select these options in a menu-driven program.

Uploaded by

Rhenz San Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

}

package Package1; }
}
import java.io.*; public void display() throws IOException{
import java.util.*; System.out.println(ar);
}
public class SanPedro_List { public void exit() throws IOException{
BufferedReader inp= new System.out.println("GOODBYE");
BufferedReader(new System.exit(0);
InputStreamReader(System.in)); }
int index; Object k; public static void main(String[] args) throws
List ar= new ArrayList(index); IOException {
int i, o=0;
public void index() throws IOException{ SanPedro_List ok=new SanPedro_List();
System.out.print("How many index do you do{
want? "); System.out.println("1. Add");
index = Integer.parseInt(inp.readLine()); System.out.println("2. Edit");
} System.out.println("3. Delete");
public void add() throws IOException{ System.out.println("4. Search");
System.out.println("Enter you want to add: System.out.println("5. Display");
"); System.out.println("6. Exit");
for(int i=0;i<index;i++) System.out.print("Enter your choice: ");
k=inp.readLine(); i=Integer.parseInt(ok.inp.readLine());
ar.add(k);
} switch(i){
public void edit() throws IOException{ case 1:{
int newInd=0; Object in1,in2; ok.index();
System.out.print("Enter you want to edit: ok.add();
"); break;
in1=inp.readLine(); }
System.out.print("enter new item: "); case 2:{
in2 = inp.readLine(); ok.edit();
for (int j = 0; j < ar.size(); j++) { break;
ar.get(j).equals(in1); }
case 3:{
ar.set(newInd, in1); ok.delete();
} break;
} }
case 4:{
public void delete() throws IOException{ ok.search();
System.out.println("Enter item"); break;
Object some = inp.readLine(); }
for (int ctr = 0; ctr < ar.size(); ctr++) { case 5:{
if (ar.get(ctr).equals(some)) { ok.display();
ar.remove(ctr); break;
} }
} case 6:{
} ok.exit();
public void search() throws IOException{ break;
System.out.println("Enter item"); }
Object s = inp.readLine(); }
if (ar.contains(s)) { }while(o==0);
for (int ctr = 0; ctr < ar.size(); ctr++) { }
if (ar.get(ctr).equals(s)) {
System.out.println(s + " is at index " + ctr); }

You might also like