Sindhuja
Ask about java
2 Answer(s)      a year and 10 months ago
Posted in : Java Beginners

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","aa@roseindia.net",11111));
                list.add(new Person("B","Mumbai","bb@roseindia.net",22222));
                list.add(new Person("C","Chennai","cc@roseindia.net",33333));
                list.add(new Person("D","Kolkata","dd@roseindia.net",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.









Related Pages:
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
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
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
ask java - Date Calendar
but in java i found too but i can't to join in another frame. And i want to ask how...ask java  sory i'am wrong language. i want to ask to this forum how... information on Java visit to : http://www.roseindia.net Thanks  
ask - Java Beginners
ask   dear how to "print out" into a file ? regard suhadi  Hi friend, Please explain properly requirement. I am sending simple...://www.roseindia.net/java/ Thanks. Amardeep
Ask date difference
Ask date difference  Hello, I have a problem about how to calculate date, the result from this code is not complete , this is my code . please help me. thank you public void a(){ String date1 = jTextField33.getText(); String
Ask Questions
Ask Questions      ..., professions, students and learners, we have initiated a new service ‘Ask Question’. Using this new service, our visitors can ask any sort of question
about JAVA - Java Beginners
about JAVA  i have to create a program that will sort the given... ERROR and ask the user again to enter the number of inputs. i don't know how to do that. Also, after executing the program i want to ask the user if they want
Ask JEE Questions Online
Ask JEE Questions Online       Java Platform, Enterprise Edition or Java... in the Java programming language. It is hardware and operating system
Ask Hibernate Questions Online
programming questions. You can ask about the error's you are facing in your... Ask Hibernate Questions Online   ... performance open source Java package that allows the developers to express queries
about JVM - Java Beginners
about JVM  Hello Rose india.net team I want to ask that why JVM is platform dependent is it automatically installs whenever we install jdk or is it automatically installed whenever we install operating system on our machine
Ask JSP questions online
Ask JSP questions online       Facing problem in JSP? Ask to us, we... has just started a new problem solving service ‘ask question’. In our
Ask JavaFX Questions Online
Ask JavaFX Questions Online       Ask programming questions related to the JavaFX development. Ask if you have query about JavaFX. With the help
Ask Applet Questions Online
Ask Applet Questions Online   ... ‘Ask Questions’. Now, you can get the quick answers of your questions... service of ‘Ask Questions’ has given you the tool to resolve your
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
Ask Questions with Options
Ask Questions with Options using Java In this section, we are going to ask five questions one after the other with four options to test the user. For this, we have stored 5 questions, answers with four options into a list. The list
Ask PHP Questions
Ask PHP Questions       PHP Questions and Answers Ask PHP Questions and get answers from.... In your questions and answers section you can ask PHP questions and get
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
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 static import - Java Beginners
about static import  Hello Friend below program is not running when i compile A.java it is compiling and i have put A.class in mypackage1. but when... to ask that "static import" syntax is correct or not package mypackage1
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
Ask Programming Questions and Discuss your Problems
Ask Programming Questions and Discuss your Problems  ... and your love for Java and Java and Java related fields, Roseindia Technologies... all sorts of Java related problems round the clock. Believe it. Roseindia has
about interview ques. - Java Interview Questions
about interview ques.  i give a interview for java.. they ask me. what is System.out.println(); what is its write ans...  Hi Friend, It is the syntax of Java used to display a string on the console window
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
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable in java   Hi Friend, Try the following code: import java.io.*; import
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes  HI I have one problem I have fetched value from oracle database into grid... for more than One checkbox here is my code. <%@ page language="java" import
help me about to solve my qustion
help me about to solve my qustion   An employee receives 15 SR per hour for the first 8 hours of week. After 8 hours (overtime) his rate becomes 20 SR per hour . Write a java class that ask a user to enter the number of hours he
Software Questions and Answers
- Ask your questions about securing your applications. Java... online Discuss Software development questions, ask your questions and get answers... of answers to common programming problems. Ask Questions | Browse
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE
about java1
about java1  Sir, i want to know how we develop 3d button ,lable,textfield etc. in java . sir plz give one program as well Thank you
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
about jboss - Java Beginners
about jboss  can you please explain about jboss...how to deploy,where the temp and lock is there...total information about jboss to use in java message services(JMS
about java - Java Beginners
about java  hello, being a begineer in Java i would like know that as we read the value entered by user through cin>> in c++ how we did it with java.  Hi Friend, There are lot of ways to input data.You can use
about session
about session  hey i want to insert userid and username of the user who have currently loggedin in servlet using prepared statement   Please visit the following link: http://www.devmanuals.com/tutorials/java/servlet
About Constructor
About Constructor  How many objects are create when this code will execute... String string = new String("Java is best Lang."); tell me the number of object of string which will create . All are those are eligible for garbage
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
About basics - Java Beginners
About basics  Why we are typing java program in text editor? Why we are running the java program in command prompt
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE.  Hi Friend, Please visit the following link: http://www.roseindia.net/ Thanks
Ask iBatis Questions Online
Ask iBatis Questions Online   ... in Java, .NET, and Ruby on Rails. iBATIS is an additional layer of indirection... relating to programming, coding, implementing and using. Ask any iBatis
Ask VoIP Questions Online
international calls. Ask questions to know about VoIP, or if you are facing any problem in VoIP technology, ask to us freely. Our VoIP experts... Ask VoIP Questions Online   
Ask Spring Questions Online
Ask Spring Questions Online   ... Framework for Java platform and .NET Framework. The prime feature of Spring... to their applications. Due to its flexibility, it has become very powerful among the Java
Ask for latest version for hibernate
Ask for latest version for hibernate  any new version for hibernate after 3.0, if yes can u give some exmp for latest version of hibernate
Ask JDBC question online
written in the Java programming language. Ask questions and search answers...Ask JDBC question online   ...-answer service ‘Ask Question in JDBC’ for all our visitors. Now you
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 JUnit Questions Online
Ask JUnit Questions Online       JUnit is a free, open source Java framework that makes... Java codes easier in its framework. It was originally written by Erich Gamma
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir...: http://www.roseindia.net/java/example/java/swing/ Hope
about package - Java Beginners
about package  as i am programming a question based on creating own... in the root directory.In my system java is installed in c:\ibm\java142\bin how can i run...://www.roseindia.net/java/master-java/java-package.shtml Hope
about coding - Java Beginners
about coding  hello sir, I want to create session expair, when user is not enter anything in login page session wil expair after 10 min.if user enter its go to success page.plz send me full code about this. thanks
About MYSQL
About MYSQL  is it possible to upload the video on mysql database   1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.