Ask about java

Ads
 

Ask about java

Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case.

View Answers

July 29, 2011 at 5:38 PM

import java.util.ArrayList;
import java.util.Scanner;

class Person{
        String name;
        String address;
        String email;
        int contactNo;

        Person(String name,String address,String email,int contactNo){
        this.name=name;
        this.address=address;
        this.email=email;
        this.contactNo=contactNo;
        }
        public String getName(){
                return name;
        }

        public String getAddress() {
                return address;
        }

        public String getEmail() {
                return email;
        }

        public int getContactNo() {
                return contactNo;
        }
       }

public class ArrayListEx {
  public static void main(String[] a) {
      Scanner input=new Scanner(System.in);
                ArrayList<Person> list = new ArrayList<Person>();
                list.add(new Person("A","Delhi","[email protected]",11111));
                list.add(new Person("B","Mumbai","[email protected]",22222));
                list.add(new Person("C","Chennai","[email protected]",33333));
                list.add(new Person("D","Kolkata","[email protected]",44444));
                boolean exit=false;
                for(Person data: list){
                System.out.println(data.getName()+"\t "+data.getAddress()+"\t "+data.getEmail()+"\t "+data.getContactNo());
                }
                do{
                System.out.println("1 Add Details");
                System.out.println("2 Exit");
                System.out.print("Enter your choice: ");
                int choice=input.nextInt();
                switch(choice){
                case 1:
                  System.out.print("Enter name: ");
                  String name=input.next();

                  System.out.print("Enter address: ");
                  String address=input.next();

                  System.out.print("Enter email: ");
                  String email=input.next();

                  System.out.print("Enter contactNo: ");
                  int contactNo=input.nextInt();

                  list.add(new Person(name,address,email,contactNo));

                  for(Person data: list){
                     System.out.println(data.getName()+"\t "+data.getAddress()+"\t "+data.getEmail()+"\t "+data.getContactNo());
                  }
                  break;

                  case 2 :
                     exit=true;
                     System.exit(0);
                     break;
                 default: 
                     System.out.println("Invalid Selection!");
                }
                }
                while(!exit);
        }
}

August 1, 2011 at 8:40 AM

Very Thanks. It is useful to me. Thanks for ur reply.

Ads









Related Tutorials/Questions & Answers:
Ask about java
Ask about java  Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case
Ask about looping in database
Ask about looping in database  Good afternoon, I want to ask...=True,A2=True : code is the same data Rule and Heritage. I want to ask that how to read looping in field rights(if A1=false and A2 = True), use from java. i
Advertisements
Ask java count
Ask java count  Good morning, I have a case where there are tables... | Java 1 | 10 | | b002 | beginner java | 5 | | b003 | advanced java book | 26 | | b004 | MySQL 1
About Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at http://www.roseindia.net/java. Thanks
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
about c and java
about c and java   i need java and c language interview and objective questions with answers for the fresher.please provide to me   Please visit the following links: http://www.roseindia.net/java/ http
Ask Java Questions Online
Ask Java Questions Online       Now, it’s time to rejoice for the Java... Developer Company has just begun a new service ‘ask question online&rsquo
Questions about Java's String pool
Questions about Java's String pool  Questions about Java's String pool
about array in java
about array in java  speed of a vehicle is measured using the total time and the distance by using the equation given bellow speed(km/hour)=distance... Vehicle 02 = 5 hours Write a JAVA class to represent the Vehicle. The program should
About inheritanance in JAVA
About inheritanance in JAVA  What is need foe the Inheritance in though we can access any method of any class declared publicly in simple class calling
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java thats on swings,and using the dbase as MSSQL. what i want to know is i had created a name ,textfield ,calender(for DObirth selection), this is displayed in GUI
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java thats on swings,and using the dbase as MSSQL. what i want to know is i had created a name ,textfield ,calender(for DObirth selection), this is displayed in GUI
Java Example projects about STRUTS
Java Example projects about STRUTS  Hai... I completed MCA but i have no job in my hands. But i do some small projects about STRUTS. Please send me some example projects about STRUTS.   Please visit the following link
About Java
About Java This article is discussing about Java, which is a programming language developed by James Gosling at Sun Microsystems. Java now part of Oracle... about Java is listed below : Around 1.1 billions desktop runs Java. Every
Ask make graph from i report and view to java Language Programming
Ask make graph from i report and view to java Language Programming  Dear sir, Please help me, i want to make a graph from mysql to i report and view to java. Please help me, give me example source code please. thank you
about java swing - Java Beginners
about java swing   How to upload the pictures and photo on the panel in java swing ,plz help thank a lot.  Hi Friend, Try the following code: import java.awt.*; import java.io.*; import javax.swing.*; import
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
How do beginners learn about Java?
How do beginners learn about Java?  Hi, I am beginner in Java and want to Java very fast. Is it possible to learn java fast? How do beginners learn about Java? Thanks   Hi, Beginners can start learning Java
Ask Servlet questions online
Ask Servlet questions online       Feel free to ask any question about servlets... kicked off a new service ‘ask questions’ to resolve your query
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle datebase to java.when i compile the program it is ok. but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java  **Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have its methods and for each method to get its parameters. I'm trying to do
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line...://www.roseindia.net/java/java-get-example/get-command-arguments.shtml http://www.roseindia.net
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line arguments are the arguments which are sent to the program being called. You can
question about mixing two strings
question about mixing two strings  using java script we need to ask two strig and combine them like.. str1= helo str2= worl combined string= hweolrol
About Java Programming Language
About Java Programming Language       Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very powerful general-purpose programming
ModuleNotFoundError: No module named 'ask'
ModuleNotFoundError: No module named 'ask'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ask' How to remove the ModuleNotFoundError: No module named 'ask' error
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  Hi , I am trying to replace contents of ms.word document in .doc or .docx... any one tell me how could I replace them using java

Ads