Radford University, ITEC 224 – Fall 2003

 

Programming Assignment #2

Due date: Midnight, Monday, November 3, 2003

 

 

Problem Specification (100 points)

 

  • You should not use the LinkedList class provided in java.util.* package in JSDK. Instead, you must implement a class named ListPkg and write all the methods as shown in the following UML, except addToFront method, recursively.

 

  • If necessary, you can add more methods or instance data.

 

 

ListPkg

- count: int

- current: ListNode

- head: ListNode

+ addToFront(String name, String tel, String email, String dob): void

+ addToBack(String name, String tel, String email, String dob): void

+ print(): void

+ reversePrint(): void

+ reverse(): ListPkg

+ sizeOf(): int

+ phoneNumberByName(String name): String

+ emailByName(String name): String

+ dobByName(String name): String

+ nameByPhoneNumber(String tel): String

+ isInList(String name): boolean

 

    • In phoneNumberByName, emailByName, dobByName, nameByPhoneNumber methods,
      • if there is no matching data, it should return -1.
      • duplicated data in the list will not be considered. If there are more than one matching data, the first one will be returned.

 

 

  • You should write class ListNode which represents an element of the single linked list. The following code is an example.

 

Public class ListPkg

{

/** The following class represents an element of a single linked list. It is a nested private class.

*/

private class ListNode
{ 
 private String name;  
 private String tel;    // Telephone number
 private String dob;    // Date of birth
 private ListNode next; // Pointer to the next node
 
   private ListNode(String name, String tel, String dob)
 { 
    this.name = name;
    this.tel = tel;
    this.dob = dob;
   } // end of the constructor
 
 public String getName() { return name; }
 public String getTel() ( return tel; )
 public String getDob() { return dob; }
 
 public void setName(String name) { this.name = name; }
   public void setTel(String tel) { this.tel = tel; }
   public void setdob(String dob) { this.dob = dob; }
 
   public ListNode getNext() { return next; }
 
   public void setNext(ListNode link) { next = link; }
} // end of class ListNode
 
//====================================
// you can implement your code here

            //====================================

 

       } // end of class ListPkg

 

 

  • Driver Program
    • You also must write a driver program to make sure that all the recursive functions work properly. The driver program should be interactive. In other words, it should receive input from the keyboard.
      • You need to have the following options and input the required data for the chosen option.

 

af  => addToFront(String name, String tel, String email, String dob): void

ab => addToBack(String name, String tel, String email, String dob): void

p =>   print(): void

rp =>  reversePrint(): void

r =>    reverse(): ListPkg

s =>    sizeOf(): int

pn =>  phoneNumberByName(String name): String

en =>  emailByName(String name): String

dn => dobByName(String name): String

np => nameByPhoneNumber(String tel): String

is => isInList(String name): boolean

 

    • The driver program should ask whether you want to continue to execute more options or not. (Hint: use while statement in the driver program)
    • Note that a different driver program will be used when your assignment is graded.

 

  • Extra points
    • Save the record to a file not to loose your data in the linked list. Read the file and restore the data when you execute your driver program. (Hint: classes for file operation are in the java.io.* package) => 10 points
    • Add GUI interface to choose the options and input data => 20 points

 

 

What to submit

 

Source code

  • Softcopy – Do not submit the printed version.

 

Java documentation

  • Softcopy – Do not submit the printed version.

 

All the softcopy should be submitted at

 \\neelix\dropbox\ITEC\ITEC224\hlee3\Submissions\ITEC224-02-fall\<your_RU_id>\RU02

 

Reference

A partial idea of this assignment comes from ECE 242 course at University of Massachusetts.