Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Welcome to Contact Management System
Enter Your Choice
1 Add Contact
1 Name
2 Contact No
2 Show selected contact
3 Show all contacts
4 Delete Any Contact
5 Exit

I am given this project , but i am having so many problems . I have to make these choices on Switch keyword (if-else). If i select 1 it goes on to sub categories . it will ask to enter name and then number(number can be in String class).
If i select 2 , i just can see only select contact , it will show me Name and contact no.
If i select 3, it will show all contact numbers
if i select 4 , it will delete my selected contact.
if i select 5 , it exists and terminate.

The problem is that i have to use arrays, can't use database, i do not need to store on data base for permanent basis .
SO much confused what to do.i don't know...
Solve these things . write this program in Java.
Thank You
Fahad Ahmed
Posted
Updated 27-Sep-15 10:04am
v6
Comments
[no name] 27-Sep-15 14:37pm    
What will you have learned if we do your homework for you? And perhaps you should take a look at your course material to find out how arrays work?
Wendelius 27-Sep-15 14:50pm    
To add to the previous question, think about the situation when you go in front of other students and they ask you questions about the code that you can't explain, simply because it's not your code. Probably not a situation where you want to be...

The best investment you can do is to invest in yourself by learning new things. Sometimes it takes more effort but I can promise, it's rewarding in the end.
Afzaal Ahmad Zeeshan 27-Sep-15 14:53pm    
Fahad, that is a very simple task that you are having right now.

The program is a simple console program that won't even need a third framework for GUI. You get the input, process it and present the user with some additional resources or options. What's hard in that?

Arrays or databases, they are just being used for the data source. What is difficult in that? For me, database would be much difficult because you have to make sure your JDBC works, and other stuff.
Patrice T 27-Sep-15 15:53pm    
Use Improve question to post your code.
Do not post code indented with tabs, use spaces instead.
Use "Encode" if your code contain > and < chars

your code is looking quite messy.

Your solution: Start working on the problem, using arrays is not that difficult.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
 
Share this answer
 
Use ArrayList<CustomClass> instead of simple array(s). It should be more powerful and flexible to manage data then arrays.

Java
import java.lang.Math; // header stuff MUST go above the first class
import java.util.ArrayList; 

// our main class becomes a file but the main method is still found
public class ManagementSystem
{
  public static void main(String[] args)
  {
    //create ArrayList of Contact
    ArrayList<Contact> contacts = new ArrayList<Contact>();
    //create new contact
    Contact c = new Contact("Maciej");
    c.setContactNumber(contacts.size()+1);
    System.out.print(c + "\n");
    //add contact to the array of contacts
    contacts.add(c);
    
    //create another contact
    c = new Contact("Raja");
    c.setContactNumber(contacts.size()+1);
    System.out.print(c + "\n");
    //add 
    contacts.add(c);
    //remove Raja's contact from list
    contacts.remove(c);
    System.out.print("Contact 'Raja' has been removed \n");
    System.out.print("List of Contacts contains: " + contacts.size() + " element(s)\n");

  }
}
// this will become its own file too (and these can be in any order)
public class Contact
{
  private String sName = "";
  private int iNumber = 0;

  public Contact(String _Name)
  {
    sName = _Name;
  }

  public void setContactNumber(int _Number){
      iNumber = _Number;
  }
  
  public String toString()
  {
    return iNumber + " - " + sName;
  }
}


Returns the following output:
1 - Maciej
2 - Raja
Contact 'Raja' has been removed 
List of Contacts contains: 1 element(s)


You can try above code on: http://www.compilejava.net/[^]

For further information, please see:
ArayList[^]
Classes[^]
 
Share this answer
 
v4
Comments
Raja Fahad 27-Sep-15 18:01pm    
ArrayList<contact> contacts = new ArrayList<contact>();
here it shows errors... saying create class contact in my eclipse
Maciej Los 27-Sep-15 18:08pm    
Have you added reference to java.util.ArrayList at the beginning of class module?
Raja Fahad 28-Sep-15 15:08pm    
ArrayList<contact> contacts = new ArrayList<contact>();
inside the ArrayList contact is written in capital or small..
because it gives me errors when i paste ur code then i make Captial C of contact then it does not give me error and
public class Contact
this class is written in below the whole code , make sure that it does not give me error.. it is also giving error.
Maciej Los 28-Sep-15 15:32pm    
Raja, i haven't got Eclipse installed. I tested above code on the page i had mentioned.
The proper statement is: ArrayList<Contact> contacts = new ArrayList<Contact>();
A bug was cleared.
Raja Fahad 28-Sep-15 15:39pm    
Now,My eclipse having error in class Contact ... ur above code is solved...
public class Contact
{
private String sName = "";
private int iNumber = 0;
.
.
.
.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900