1

I got an assignment in which I have to make a phone book using a link list.

In this list I got to be able to add an entry. The entry must have a person first name,last name and phone number.

I have to be able to delete the first,last, and phone number of the entries.

How can I do this I am think of creating a class named entry with string for first,last,and phone number.

And when the user decides to create a new Record put a new Object entry with these fields. Into the link list.

The problem is how can I create a new Object and name it when the user want to put it on the list.

I cannot keep using the same name for an object over and over or can I?

james Chol
  • 53
  • 2
  • 9
  • 1
    Show us the code you have so far. StackOverflow can help you answer specific questions, but not how to implement something from scratch. Also, a more descriptive title will get you a lot more help. – Surreal Dreams Mar 03 '15 at 18:13
  • I am thinking of trying something but I have that obstacles of the Object in my path. But I will put up some code I think I have an idea of how to do this. – james Chol Mar 03 '15 at 18:18

2 Answers2

1

You can't.

Suppose you have a class, Person, with properties as you suggested. directory is an object of type LinkedList<Person>. The correct way to do what you are trying to do is to make Person immutable. Every time you want to add a Person, you write statements such as directory.add(new Person("George", "Washington", "1776")) (the constructor initializes final Strings.

You must make new objects because LinkedList only stores references to objects, not copies of them.

Really, though, you can instead of Person use an associative array, for example mapping enum types for properties to strings.

Simon Kuang
  • 3,870
  • 4
  • 27
  • 53
0

Make a list of some kind (array, ArrayList, whatever floats your boat) and store it there using new Record(...).

Making a class for keeping the data is a good way to solve the problem.

thekiwi5000
  • 137
  • 7
  • So I can insert a new Entry(string name, string phone, string lastName) into each part of the array list without having to name my Object. Entry being the name of my object. – james Chol Mar 03 '15 at 18:17
  • 1
    Yes, same like you can create an array of `ints` without having to name each other – thekiwi5000 Mar 03 '15 at 18:18