/ Published in: Java
A basic database made in Java. It resembles a mobile phone contacts activity in which user is prompted to introduce some data of new contacts.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package com.santi; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Date; public class Main { //declaration of arraylist-type variables ArrayList<String> names=new ArrayList<String>(); ArrayList<String> last_names=new ArrayList<String>(); ArrayList<String> phones=new ArrayList<String>(); ArrayList<String> emails=new ArrayList<String>(); //declaration of a Date-type variable //rest of auxiliary variables int cont=0; boolean a =true; //end of variable declarations //main while loop while (a==true){ if(names.size()==0 && last_names.size()==0 && phones.size()==0 && emails.size()==0) System.out.flush(); "2. Show contacts." + "3. Remove contact. 0. Exit program. : "); switch (opt) { case 1: names.add(getInput("Name: ")); last_names.add(getInput("Last name: ")); phones.add(getInput("Phone number: ")); emails.add(getInput("Email: ")); break; case 2: if (names.isEmpty() && last_names.isEmpty() && phones.isEmpty() && emails.isEmpty()) { } else { for (int i = 0; i < names.size(); i++) { } } break; case 3: if (names.isEmpty() && last_names.isEmpty() && phones.isEmpty() && emails.isEmpty()) { } else if(names.size()==1){ names.clear(); last_names.clear(); phones.clear(); emails.clear(); break; } else { cont=0; switch (option3){ case 1: if (chc.equals(name)) { //remove all fields of data in that position names.remove(chc); last_names.remove(chc); phones.remove(chc); emails.remove(chc); break; }cont++; } if (cont==names.size()) { System.out.println("WARNING: No matches between provided name and stored names. Remember: this program is case-sensitive!"); } break; case 2: names.clear(); last_names.clear(); phones.clear(); emails.clear(); break; } break; } break; case 0: a=false; break; } } } try { return stdin.readLine(); return "Error: " + e.getMessage(); } } }
URL: http://programmingeiger824.blogspot.com