Radford University, ITEC 224 – Fall 2003

 

Programming Assignment #2

Due date: Midnight, Monday, November 3, 2003

 

Problem Specification (100 points)

 

§         Implement the class represented by the UML diagram below.  In your implementation, all methods except addToFront and isEmpty must be recursive.

 

ListPkg

- 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

+ isEmpty(): Boolean

 

o        You should not use “counter” instance data in ListPkg class to keep the number of ListNodes and you also should not use “tail” instance data in ListPkg class to keep the last ListNode.

o        In phoneNumberByName, emailByName, dobByName, nameByPhoneNumber methods,

§         if there is no matching data, it should return “no matching data”.

§         duplicated data in the list will not be considered. If there are more than one matching data, the first one will be returned.

o        If necessary, you can add more methods or instance data to the class.

o        For some of the methods that you implement, you may need to write and call a recursive helper method. However, for reversePrint you should not simply call reverse and print.

o        You should not use the LinkedList class provided in java.util.* package in JSDK

 

§         You should write a class ListNode which represents an element of the single linked list. You may use all or part of the following code when you write this class.

 

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

o        You also must write a driver program that you can use to test your recursive functions. 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 => isEmpty(): Boolean

q => quit (ie quit the program)

 

§         Once the option has been chosen, the program should provide which parameters are required as follows:

 

af <enter>

Name? Radford University <enter>

Telephone Number? 000-000-0000 <enter>

Email Address? aaa@radford.edu <enter>

Date of Birth? 1/1/2003 <enter>

 

o        Note that an additional driver program will be used to test and grade your ListPkg class.

o        Your driver class should be named ListDriver.

 

§         Extra points

o        Save the data in the list in a file  in order to retain the data between runs of your program. The driver program can read this file, if it exists, and restore the data when the driver begins execution. You should name your data file driver.dat. (Hint: classes for file operation are in the java.io.* package) => 10 points

o        Add a GUI interface to choose the options and input the 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.