Question
Topic: Doubly List for Name card (Java) write a class NameCard.java which has Data fields: name (String), age(int), company(String) Methods: Public String getName(); Public int
Topic: Doubly List for Name card (Java)
write a class NameCard.java which has
Data fields: name (String), age(int), company(String)
Methods:
Public String getName();
Public int getAge();
Public String getCom();
Public void setName(String n);
Public void setAge(int a);
Public void setCom(String c);
toString(): \\ can be used to output information on this name card
--------------------------------------------------------------------------------------------------------------------------------------------
write a class DoublyNameCardList.java, which is a doubly linked list and each node of the list a name card.
In the DoublyNameCardList.java:
Data field: Reference data type: head, which always references the first node of the doubly linked list Reference data type: tail, which aways references the last node of the doubly linked list int count, which is used to record the number of name cards in the list Method: public DoublyNameCardList(); // A constructor which can initialize the list: public void addEnd(NameCard x); // A method that allows you to place a value at the end of the list public void addHead(NameCard x); // A method that allows you to place a value at the begin of the list
public void add(int index, NameCard x); //A method that allows you to place a name card after the given location
public NameCard get(int index); //A method that allows you to retrieve a name card from a given location
public int size(); // A method that allows you to return the number of elements that is currently in the list
public void delete (index n); //A method that will remove a name card at the given index
Public boolean exist(NameCard n); // test if there has a name card in the list which has same content with n
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now, write a driver program (the class with the public static void main(String[] args) method) name test.java to test the data structure you just created:
Fill in the list with 5 name card objects
print the list on the screen two times:
From head to tail
From tail to head
Call the method in the DoublyNameCardList class one by one, each method you called,
Print out a message to show what have you done
print out all the name cards in the list
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started