All of the work in this project is my own! I have not left copies of my code in public folders on university computers. I have not given any of this project to others. I will not give any portion of this project to others taking this class. I realize that the penalty for turning in work that is not my own can range from an "F" in the class to dismissal from Trinity University.
Print Name __________________________ Time Required = ______.____ Hrs.
Signature __________________________ (pledged)
1] Create program DLList.java.
2] Use your documented Athlete Class. Add Class Book
/**
* The Book class is a container for Books. The functions include
* <ul>
* <li>Book Constructors
* <li>Set
* <li>Get
* <li>Displays
* <li>toString
* </ul>
* <p>
*
* The Book private data includes
* <ul>
* <li>title
* <li>no
* <li>barCode
* </ul>
* <p>
* @author Dr. Thomas E. Hicks
* @version 1.0
*/
import javax.swing.JOptionPane;
public class Book implements Comparable <Book>
{
private String title;
private int no;
private int barCode;
/**
* Enable sorting and organizational algorithms to compare two Book objects using
* the title as the primary key. For this compareTo, there is no secondary keys in the
* event that two objects have the same exact title. The toUpperCase is used to make the
* title comparison non-case sensitive.
*
* @param Book Book with which to compare the title.
*
*/
public int compareToStr( Book book )
{
int c = title.toUpperCase().compareTo(book.title.toUpperCase());
return c;
}
/**
* Enable sorting and organizational algorithms to compare two Book objects using
* the no as the primary key. For this compareTo, there is no secondary keys in the
* event that two objects have the same exact no.
*
* @param Book Book with which to compare the no.
* @return -1 if less than, 0 if equal, and 1 if greater than
*
*/public int compareTo( Book book )
{
int c = 1;
if ( no < book.no )
c = -1;
else if ( no > book.no )
c = 1;
else
c = 0;
return c;
}
/**
* Constructor which initializes an empty Book object
*
*/
public Book ()
{
title = "";
no = 0;
barCode = 0;
}
/**
* Constructor which fills an Book object
*
* @param newName The new title
* @param newNo The new Book number
* @param newBarCode The new bar code number
*/
public Book (String newName, int newNo, int newBarCode)
{
Set(newName, newNo, newBarCode);
}
/**
* Set method provides a public interface to alter the Book object
* private data.
*
* @param newName The new title
* @param newNo The new Book number
* @param newBarCode The new bar code number
*/
public void Set (String newName, int newNo, int newSportNo)
{
title = newName;
no = newNo;
barCode = newSportNo;
}
/**
* Display the Book object private data.
*
*/
public void Display()
{
System.out.println("Title ...: " + title);
System.out.println("No.......: " + no);
System.out.println("Bar Code : " + barCode + "\n");
}
/**
* Display the message followed by the Book object private data.
*
* @param message The message to be displayed
*/
public void Display(String message)
{
System.out.println(message);
Display();
}
/**
* Crude first attempt at filling an Book object with three separate
* jOptionPane calls. Failure to enter a title aborts the process and returns false.
* Once the user enters the title, he/she must enter a numeric No and a numeric barCode
*
* @return true if the user changes the Book; otherwise false
*/
public boolean Get()
{
String newTitle = JOptionPane.showInputDialog("Enter Book title <Cancel Return To Exit> ");
if (newTitle == null)
return false;
title = newTitle;
boolean valid = true;
do
{
String newNo = JOptionPane.showInputDialog("Enter Book No ");
try
{
no = Integer.parseInt(newNo);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a Book No");
valid = false;
}
}
while (!valid);
do
{
String newNo = JOptionPane.showInputDialog("Enter Bar Code No ");
try
{
barCode = Integer.parseInt(newNo);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a Bar Code No");
valid = false;
}
}
while (!valid);
return true;
}
/**
* Provide a 50 character string which represents the most important information
* in the Book object.
*/
public String toString()
{
String outString = String.format("%-25s : %6d : %13d",title, no, barCode);
return (outString);
}
/**
* Provide a 50 character string which represents the most important information
* in the Book object.
*/
public static void TestBook()
{
System.out.println("------------- Test Book -----------");
Book Text1 = new Book();
Text1.Set("Text1 The Great", 1111, 12);
Book Doc = new Book("Dr. Hicks", 1234, 14);
Text1.Display("This is Text1");
Doc.Display();
Book Tom = new Book();
if (Tom.Get())
Tom.Display();
else
System.out.println("You Did Not Change Tom");
System.out.println("------------- End Test Book -----------");
}
public static void main(String[] args)
{
TestBook();
}
}
Make sure your Athlete Class has a comprable compareTo function. Make sure it implements Comparable <Athlete>
3] Add Class Parts
/**
* The Part class is a container for Parts. The functions include
* <ul>
* <li>Part Constructors
* <li>Set
* <li>Get
* <li>Displays
* <li>toString
* </ul>
* <p>
*
* The Part private data includes
* <ul>
* <li>name
* <li>no
* <li>quantityInStock
* <li>wholeSaleCost
* <li>retailCost
* </ul>
* <p>
* @author Dr. Thomas E. Hicks
* @version 1.0
*/
import javax.swing.JOptionPane;
public class Part implements Comparable <Part>
{
private String name;
private int no;
private int quantityInStock;
private double wholeSaleCost;
private double retailCost;
/**
* Enable sorting and organizational algorithms to compare two Part objects using
* the name as the primary key. For this compareTo, there is no secondary keys in the
* event that two objects have the same exact name. The toUpperCase is used to make the
* name comparison non-case sensitive.
*
* @param part Part with which to compare the name.
*
*/
public int compareTo( Part part )
{
int c = name.toUpperCase().compareTo(part.name.toUpperCase());
return c;
}
/**
* Enable sorting and organizational algorithms to compare two Part objects using
* the no as the primary key. For this compareTo, there is no secondary keys in the
* event that two objects have the same exact no.
*
* @param part Part with which to compare the no.
* @return -1 if less than, 0 if equal, and 1 if greater than
*
*/public int compareToInt( Part part )
{
int c = 1;
if ( no < part.no )
c = -1;
else if ( no > part.no )
c = 1;
else
c = 0;
return c;
}
/**
* Constructor which initializes an empty Part object
*
*/
public Part ()
{
name = "";
no = 0;
quantityInStock = 0;
wholeSaleCost = 0.0;
retailCost = 0.0;
}
/**
* Constructor which fills an Part object
*
* @param newName The new name
* @param newNo The new Part number
* @param newQuantityInStock The new sport number
* @param newWholeSaleCost The new sport number
* @param newRetailCost The new sport number
*/
public Part (String newName, int newNo, int newQuantityInStock,
double newWholeSaleCost, double newRetailCost)
{
Set(newName, newNo, newQuantityInStock, newWholeSaleCost, newRetailCost);
}
/**
* Set method provides a public interface to alter the Part object
* private data.
*
* @param newName The new name
* @param newNo The new Part number
* @param newQuantityInStock The new sport number
* @param newWholeSaleCost The new sport number
* @param newRetailCost The new sport number
*/
public void Set (String newName, int newNo, int newQuantityInStock,
double newWholeSaleCost, double newRetailCost)
{
name = newName;
no = newNo;
quantityInStock = newQuantityInStock;
wholeSaleCost = newWholeSaleCost;
retailCost = newRetailCost;
}
/**
* Display the Part object private data.
*
*/
public void Display()
{
System.out.println("Part Name ........: " + name);
System.out.println("Part No...........: " + no);
System.out.println("Quantity In Stock : " + quantityInStock);
System.out.printf ("Wholesale Cost....: %.2f\n", wholeSaleCost);
System.out.printf ("Retail Cost.......: %.2f\n\n", retailCost);
}
/**
* Display the message followed by the Part object private data.
*
* @param message The message to be displayed
*/
public void Display(String message)
{
System.out.println(message);
Display();
}
/**
* Crude first attempt at filling an Part object with three separate
* jOptionPane calls. Failure to enter a name aborts the process and returns false.
* Once the user enters the name, he/she must enter a numeric no, a numeric quantityInStock
* a wholesale cost, and a numeric retail cost
*
* @return true if the user changes the Part; otherwise false
*/
public boolean Get()
{
String newName = JOptionPane.showInputDialog("Enter Part Name <Cancel Return To Exit> ");
if (newName == null)
return false;
name = newName;
boolean valid = true;
do
{
String newNo = JOptionPane.showInputDialog("Enter Part No ");
try
{
no = Integer.parseInt(newNo);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a No");
valid = false;
}
}
while (!valid);
do
{
String newQuantityInStock = JOptionPane.showInputDialog("Enter Quantity In Stock ");
try
{
quantityInStock = Integer.parseInt(newQuantityInStock);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a Quantity In Stock");
valid = false;
}
}
while (!valid);
do
{
String newWholeSaleCost = JOptionPane.showInputDialog("Enter Wholesale Cost ");
try
{
wholeSaleCost = Double.parseDouble(newWholeSaleCost);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a Wholesale Cost");
valid = false;
}
}
while (!valid);
do
{
String newRetailSaleCost = JOptionPane.showInputDialog("Enter Retail Cost ");
try
{
retailCost = Double.parseDouble(newRetailSaleCost);
valid = true;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Numeric - You must enter a Retail Cost");
valid = false;
}
}
while (!valid);
return true;
}
/**
* Provide a 50 character string which represents the most important information
* in the Part object.
*/
public String toString()
{
String outString = String.format("%-17s : %6d : %3d : 6.2f : 6.2f",
name, no, quantityInStock, wholeSaleCost, retailCost);
return (outString);
}
/**
* Provide a 50 character string which represents the most important information
* in the Part object.
*/
public static void TestPart()
{
System.out.println("------------- Test Part -----------");
Part Football = new Part();
Football.Set("Nike Football", 1111, 12, 22.50, 121.00);
Part Basketball = new Part("Wilson Basketball", 1234, 14, 12.12, 33.33);
Football.Display("This is The Football");
Basketball.Display();
Part Golfball = new Part();
if (Golfball.Get())
Golfball.Display();
else
System.out.println("You Did Not Change Golfball");
System.out.println("------------- End Test Part -----------");
}
public static void main(String[] args)
{
// TestPart();
}
}
4] Add Class Int3
public class Int3 implements Comparable <Int3>
{
/**
* Enable sorting and organizational algorithms to compare two Part objects using
* the no as the primary key. For this compareTo, there is no secondary keys in the
* event that two objects have the same exact no.
*
* @param part Part with which to compare the no.
* @return -1 if less than, 0 if equal, and 1 if greater than
*
*/public int compareTo( Int3 int3 )
{
int c = 1;
if ( value < int3.value )
c = -1;
else if ( value > int3.value )
c = 1;
else
c = 0;
return c;
}
public int value;
public Int3 (Integer newValue)
{
value = newValue;
}
public Int3 ()
{
value = 0;
}
public Int3 (int newValue)
{
value = newValue;
}
public void Set (int newValue)
{
value = newValue;
}
public String toString()
{
String outString = String.format("%50d",value);
return (outString);
}
public String toDigit3()
{
String outString;
if (value < 10)
outString = String.format("00%d",value);
else
if (value < 100)
outString = String.format("0%d",value);
else
outString = String.format("%d",value);
return (outString);
}
public String toDigit3(char sign)
{
String outString;
outString = String.format("%c%d",sign,value);
return (outString);
}
public static void main(String[] args)
{
Int3 N = new Int3(1);
N.Set(12);
System.out.println(N.toDigit3());
System.out.println(N.toDigit3('-'));
System.out.println("Testing Int1");
}
}
5] Add Class DLNode
public class DLNode <T>
{
protected T info;
protected DLNode<T> left;
protected DLNode<T> right;
public DLNode()
{
left = null;
right = null;
info = null;
}
public DLNode(T newInfo)
{
left = null;
right = null;
info = newInfo;
}
public void Display(String message, DLNode<T> ptr, boolean DisplayTitles,
boolean DisplayTopLine, boolean DisplayBottomLine)
{
String leftStr, rightStr, ptrStr, infoStr;
if (ptr == null)
{
ptrStr = new String(" null ");
leftStr = new String(" null ");
rightStr = new String(" null ");
infoStr = new String(" null ");
}
else
{
infoStr = ptr.info.toString();
ptrStr = ptr.toString().toString().substring(7,ptr.toString().length());;
if (ptr.left == null)
leftStr = new String(" null ");
else
leftStr = ptr.left.toString().substring(7,ptr.left.toString().length());
if (ptr.right == null)
rightStr = new String(" null ");
else
rightStr = ptr.right.toString().substring(7,ptr.right.toString().length());
}
if (message.length() > 0)
System.out.println(message);
if (DisplayTitles == true)
System.out.println(" Left Info Right ");
if (DisplayTopLine == true)
System.out.println(" |------------|----------------------------------------------------|------------|");
System.out.printf("%10s | %10s | %50s | %10s |\n",ptrStr, leftStr, infoStr, rightStr);
if (DisplayBottomLine == true)
System.out.println(" |------------|----------------------------------------------------|------------|");
}
public static void main(String[] args)
{
Athlete Tom = new Athlete("Tom", 123, 4);
Athlete Dick = new Athlete("Dick", 234, 4);
Int3 No4 = new Int3 (12);
Int3 No5 = new Int3 (345);
Int3 No6 = new Int3 (678);
Int3 No7 = new Int3 (901);
Int3 No8 = new Int3 (002);
DLNode<Integer> Node1 = new DLNode <Integer> (33);
Node1.Display("Node1", null, true, true, true);
DLNode<Athlete> Node2 = new DLNode <Athlete> ();
Node1.Display("Node2", null, true, true, true);
DLNode<Athlete> Node3 = new DLNode <Athlete> (Dick);
Node2.info = Tom;
Node2.Display("Node2 - Null Ptrs", Node2, true, true, true);
Node3.Display("Node3 - Null Ptrs", Node2, true, true, true);
DLNode<Athlete> Ptr1;
Node2.right = Node3;
Node3.left = Node2;
Ptr1 = Node2;
Ptr1.Display("\n=====>Ptr1====Node2", Ptr1, true, true, true);
Ptr1 = Ptr1.right;
Ptr1.Display("=====>Ptr1====Node3", Ptr1, true, true, true);
DLNode<Int3> Node4 = new DLNode <Int3> (No4);
DLNode<Int3> Node5 = new DLNode <Int3> (No5);
DLNode<Int3> Node6 = new DLNode <Int3> (No6);
DLNode<Int3> Node7 = new DLNode <Int3> (No7);
DLNode<Int3> Node8 = new DLNode <Int3> (No8);
DLNode<Int3> Ptr2;
Ptr2 = Node4;
Node4.right = Node5;
Node5.left = Node4;
Node5.right = Node6;
Node6.left = Node5;
Node6.right = Node7;
Node7.left = Node6;
Node7.right = Node8;
Node8.left = Node7;
System.out.println("\n\nBrief Node Listing Of Nodes Pointed To By List Ptr2\n");
while (Ptr2 != null)
{
Ptr2.Display("", Ptr2, false, true, false);
Ptr2 = Ptr2.right;
}
System.out.println("\n\nLet Us Display The Number Pointed To By List Ptr2\n");
Ptr2 = Node4;
System.out.print(Ptr2.info.toDigit3('+') + ",");
Ptr2 = Ptr2.right;
while (Ptr2 != null)
{
System.out.print(Ptr2.info.toDigit3() + ",");
Ptr2 = Ptr2.right;
}
System.out.println("\n\nYes, I realize there is an extra comma at the end!");
System.out.println("You will fix later");
}
}
6] Add DLList Class
import java.util.Comparator;
import java.util.Random;
/**
* DLList is the double linked list class that includes both the front and rear
* in the header. This set of tools includes
* <ul>
* <li>Push
* <li>Pop
* <li>Empty
* <li>Insert
* <li>Remove
* <li>InsertAfter
* <li>Inplace
* <li>DisplayHeader
* <li>DisplayNodes
* <li>Display
* <li>TestDLList
* </ul>
* <p>
*
* The extends Comparable<T> means that each and every generic element T must be a
* class that includes implements Comparable in the class definition. See Book below:
*
* class Book implements Comparable <Book> {
*
* Further more, the Book class must have an appropriate compareTo method such as:
* public int compareToStr( Book book )
* {
* int c = title.toUpperCase().compareTo(book.title.toUpperCase());
* return c;
* }
* The book compare to method, above, enables books to be sorted, searched, or organized
* by a non-case sensitive title.
*
* @author Dr. Thomas E. Hicks
* @version 1.0
*/
public class DLList <T extends Comparable <T>>
{
protected DLNode<T> front;
protected DLNode<T> rear;
protected T tempInfo;
private static int DIAGNOSTIC_LEVEL = 7;
/**
* Does all that is necessary to create an new empty list. The front and rear
* are set to null.
*/
public DLList()
{
front = null;
rear = null;
}
/**
* Explicitly return true if list is empty; otherwise false.
*
* @return True if list is empty; otherwise false.
*/
public boolean Empty()
{
return (false);
}
/**
* Explicitly return true if able to push the newInfo to a node at the front
* of the double linked list.
*
* @param newInfo Generic/Templated newInfo
* @return True able to create memory and push node; otherwise false.
*/
public boolean Push(T newInfo)
{
return (true);
}
/**
* Explicitly return true if able to place the front info into container tempInfo
* and remove the front node from the list.
*
* @return True able if not empty and able to place front info into tempInfo;
* otherwise false.
*/
public boolean Pop()
{
return (true);
}
/**
* Explicitly return true if able to insert the newInfo to a node at the rear
* of the double linked list.
*
* @param newInfo Generic/Templated newInfo
* @return True able to create memory and insert node; otherwise false.
*/
public boolean Insert(T newInfo)
{
return (true);
}
/**
* Explicitly return true if able to place the front info into container tempInfo
* and remove the front node from the list.
*
* @return True able if not empty and able to place front info into tempInfo;
* otherwise false.
*/
public boolean Remove()
{
return (true);
}
/**
* Explicitly return true if able to insert the newInfo to node at the rright of
* the left brother within the double linked list.
*
* @param newInfo Generic/Templated newInfo
* @param leftBrother ptr in the list that is to the left of the new insert after
* location.
* @return True able to create memory and insertAfter node; otherwise false.
*/
public boolean InsertAfter(T newInfo, DLNode<T> leftBrother)
{
return (true);
}
/**
* Explicitly return true if able to insert the newInfo inplace in accordance
* with the compareTo of the T object.
*
* @param newInfo Generic/Templated newInfo
* location.
* @return True able to create memory and inplace node; otherwise false.
*/
public boolean Inplace (T newInfo)
{
return (true);
}
/**
* Graphically display the header components. These include the front, rear, and any
* items specifically unique to this list.
*
* @param message Display Message
* @param ptr The reference to the DLList object
* @param DisplayTitles Option to display the header title information
* @param DisplayTopLine Option to display the top line
* @param DisplayBottomLine Option to display the bottom line
*/
public void DisplayHeader(String message, DLList<T> ptr, boolean DisplayTitles,
boolean DisplayTopLine, boolean DisplayBottomLine)
{
String frontStr, rearStr, ptrStr;
if (ptr == null)
{
ptrStr = new String(" null ");
frontStr = new String(" null ");
rearStr = new String(" null ");
}
else
{
ptrStr = ptr.toString().toString().substring(7,ptr.toString().length());;
if (ptr.front == null)
frontStr = new String(" null ");
else
frontStr = ptr.front.toString().substring(7,ptr.front.toString().length());
if (ptr.rear == null)
rearStr = new String(" null ");
else
rearStr = ptr.rear.toString().substring(7,ptr.rear.toString().length());
}
if (message.length() > 0)
System.out.println(message);
if (DisplayTitles == true)
System.out.println(" front rear ");
if (DisplayTopLine == true)
System.out.println(" |---------------------------------------------------|-------------|------------|");
System.out.printf("%10s | %49s | %10s | %10s |\n",ptrStr,"", frontStr, rearStr);
if (DisplayBottomLine == true)
System.out.println(" |---------------------------------------------------|-------------|------------|");
}
/**
* Graphically display the nodes associated with this list from front to rear (if any).
*
* @param message Display Message
* @param CompactDisplay Option to display the lines between nodes.
*/
public void DisplayNodes(String message, boolean CompactDisplay)
{
DLNode<T> ptr;
if (message.length() > 0)
System.out.println(message);
if (! Empty())
{
ptr = front;
ptr.Display("",ptr,true,true,false);
ptr = ptr.right;
while (ptr != null)
{
if (CompactDisplay)
ptr.Display("",ptr,false,true,false);
else
ptr.Display("",ptr,false,false,false);
ptr = ptr.right;
}
System.out.println(" |------------|----------------------------------------------------|------------|");
}
}
/**
* Graphically display the header and nodes associated with this list.
*
* @param message Display Message
* @param CompactDisplay Option to display the lines between nodes.
*/
public void Display(String message, boolean CompactDisplay, DLList<T> ptr)
{
DisplayHeader(message, ptr, true, true, true );
DisplayNodes("", CompactDisplay);
}
public static void main(String[] args)
{
TestDLList();
}
/**
* Test function for DLList class. This test function requires the Athlete and Part
* classes.
*
* @param message Display Message
* @param CompactDisplay Option to display the lines between nodes.
*/
public static void TestDLList()
{
System.out.println("================================================================================");
System.out.println("======================== Start Of TestDLList ===================================");
System.out.println("================================================================================\n");
Part [] Inventory = new Part[11];
Inventory[ 1]= new Part ("Football", 100, 2, 10.50, 25.00);
Inventory[ 2]= new Part ("Softball", 105, 10, 3.00, 5.00);
Inventory[ 3]= new Part ("Tennis Ball", 102, 20, 2.00, 3.50);
Inventory[ 4]= new Part ("Basketball", 101, 10, 20.00, 50.00);
Inventory[ 5]= new Part ("Golf Ball", 104, 5, 8.00, 30.50);
Inventory[ 6]= new Part ("Baseball", 107, 10, 3.00, 6.50);
Inventory[ 7]= new Part ("Soccer Ball", 106, 10, 22.00, 48.00);
Inventory[ 8]= new Part ("Teather Ball", 109, 1, 14.00, 18.50);
Inventory[ 9]= new Part ("Kick Ball", 108, 4, 12.00, 18.00);
Inventory[10]= new Part ("Racquetball", 110, 20, 5.00, 9.00);
Athlete [] Player = new Athlete[11];
Player[ 1]= new Athlete ("Sammi", 100, 10);
Player[ 2]= new Athlete ("Alex", 105, 10);
Player[ 3]= new Athlete ("Sarah", 102, 11);
Player[ 4]= new Athlete ("Ken", 101, 10);
Player[ 5]= new Athlete ("Bill", 104, 11);
Player[ 6]= new Athlete ("Alex", 107, 10);
Player[ 7]= new Athlete ("Tom", 106, 10);
Player[ 8]= new Athlete ("Shea", 109, 12);
Player[ 9]= new Athlete ("Shery", 108, 11);
Player[10]= new Athlete ("Rita", 110, 14);
/*
if (DIAGNOSTIC_LEVEL <= 1)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("------------------------ DIAGNOSTIC_LEVEL = 1 ----------------------------------");
System.out.println("----------------- Test Constructor & DisplayHeader -----------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> no1 = new DLList <Integer>();
no1.DisplayHeader("Empty List No1", no1, true, true, true);
DLList<Athlete> football = new DLList <Athlete>();
football.DisplayHeader("Football",football, true, true, true);
DLList<Part> sportingGoods = new DLList <Part>();
sportingGoods.DisplayHeader("Sporting Goods",sportingGoods, true, true, true);
}
if (DIAGNOSTIC_LEVEL <= 2)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 2 -------------------------------");
System.out.println("----------- Test Push & DisplayHeader & DisplayNodes & Display ----------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No1 = new DLList <Integer> ();
No1.DisplayHeader("Testing DisplayHeader With Empty List No1", No1, true, true, true);
No1.Push(123);
No1.DisplayHeader("\nTesting DisplayHeader With No1", No1, true, true, true);
No1.DisplayNodes("\nTesting DisplayNodes With Display No1", true);
No1.Display("\nTesting No1.Display With 123", true, No1);
No1.Push(234);
No1.Display("\nTesting No1.Display With 234 123", true, No1);
No1.Push(345);
No1.Display("\nTesting No1.Display With 345 234 123", true, No1);
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No2 = new DLList <Integer> ();
for (int Counter = 1; Counter <= 5; Counter ++)
if (No2.Push(Counter))
No2.Display("\n------------ No2 ------------ NewInfo = " + Counter,true,No2);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Part> SportingGoods = new DLList <Part> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (SportingGoods.Push(Inventory[Counter]))
SportingGoods.Display("\n------- Sporting Goods ------- NewInfo = " + Inventory[Counter].toString(),
true,SportingGoods);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Athlete> Team = new DLList <Athlete> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (Team.Push(Player[Counter]))
Team.Display("\n------- Sporting Goods ------- NewInfo = " + Player[Counter].toString(),
true,Team);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
}
if (DIAGNOSTIC_LEVEL <= 3)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 3 -------------------------------");
System.out.println("-------------------------------- Test Pop -------------------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No2 = new DLList <Integer> ();
for (int Counter = 1; Counter <= 5; Counter ++)
if (!No2.Push(Counter))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
No2.Display("\n------------ No2 ------------ NewInfo = ",true,No2);
while (!No2.Empty())
{
if (No2.Pop())
No2.Display("\n------- Sporting Goods ------- Popped was " + No2.tempInfo.toString(),
true, No2);
else
System.out.println("\n\n\n\n\nUnsuccessful Popping Object\n\n\n\n\n\n");
}
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Part> SportingGoods = new DLList <Part> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!SportingGoods.Push(Inventory[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
SportingGoods.Display("\n------- Sporting Goods ------- ", true,SportingGoods);
System.out.println("--------------------------------------------------------------------------------\n");
while (!SportingGoods.Empty())
{
if (SportingGoods.Pop())
SportingGoods.Display("\n------- Sporting Goods ------- Popped was " + SportingGoods.tempInfo.toString(),
true, SportingGoods);
else
System.out.println("\nUnsuccessful Popping Object \n");
}
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Athlete> Team = new DLList <Athlete> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!Team.Push(Player[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
Team.Display("\n------- Team ------- ", true,Team);
for (int Counter = 1; Counter <= 13; Counter ++)
{
if (Team.Pop())
Team.Display("\n------- Sporting Goods ------- Popped was " + SportingGoods.tempInfo.toString(),
true, Team);
else
System.out.println("\nUnsuccessful Popping Object\n");
}
}
if (DIAGNOSTIC_LEVEL <= 4)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 4 -------------------------------");
System.out.println("-------------------------------- Test Insert ----------------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No2 = new DLList <Integer> ();
for (int Counter = 1; Counter <= 5; Counter ++)
if (No2.Insert(Counter))
No2.Display("\n------------ No2 ------------ NewInfo = " + Counter,true,No2);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Part> SportingGoods = new DLList <Part> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (SportingGoods.Insert(Inventory[Counter]))
SportingGoods.Display("\n------- Sporting Goods ------- NewInfo = " + Inventory[Counter].toString(),
true,SportingGoods);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Athlete> Team = new DLList <Athlete> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (Team.Insert(Player[Counter]))
Team.Display("\n------- Sporting Goods ------- NewInfo = " + Player[Counter].toString(),
true,Team);
else
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
}
if (DIAGNOSTIC_LEVEL <= 5)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 5 -------------------------------");
System.out.println("-------------------------------- Test Remove -------------------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No2 = new DLList <Integer> ();
for (int Counter = 1; Counter <= 5; Counter ++)
if (!No2.Insert(Counter))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
No2.Display("\n------------ No2 ------------ NewInfo = ",true,No2);
while (!No2.Empty())
{
if (No2.Remove())
No2.Display("\n------- Sporting Goods ------- Popped was " + No2.tempInfo.toString(),
true, No2);
else
System.out.println("\n\n\n\n\nUnsuccessful Popping Object\n\n\n\n\n\n");
}
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Part> SportingGoods = new DLList <Part> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!SportingGoods.Insert(Inventory[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
SportingGoods.Display("\n------- Sporting Goods ------- ", true,SportingGoods);
System.out.println("--------------------------------------------------------------------------------\n");
while (!SportingGoods.Empty())
{
if (SportingGoods.Remove())
SportingGoods.Display("\n------- Sporting Goods ------- Popped was " + SportingGoods.tempInfo.toString(),
true, SportingGoods);
else
System.out.println("\nUnsuccessful Popping Object \n");
}
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Athlete> Team = new DLList <Athlete> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!Team.Insert(Player[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
Team.Display("\n------- Team ------- ", true,Team);
for (int Counter = 1; Counter <= 13; Counter ++)
{
if (Team.Remove())
Team.Display("\n------- Sporting Goods ------- Popped was " + SportingGoods.tempInfo.toString(),
true, Team);
else
System.out.println("\nUnsuccessful Popping Object\n");
}
}
if (DIAGNOSTIC_LEVEL <= 6)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 6 -------------------------------");
System.out.println("---------------------------- Test InsertAfter ---------------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
DLList<Integer> No2 = new DLList <Integer> ();
DLNode<Integer> ptr1, ptr2, ptr3;
No2.Insert(2);
ptr1 = No2.rear; // ptr1 points to the node containing 2
No2.Insert(4);
ptr2 = No2.rear; // ptr2 points to the node containing 4
No2.Insert(6);
ptr3 = No2.rear; // ptr3 points to the node containing 6
No2.Display("\n------------ No2 ------------ List contains 2, 4, 6 ",true,No2);
No2.InsertAfter(3, ptr1);
No2.Display("\n------------ No2 ------------ List contains 2, 3, 4, 6 ",true,No2);
No2.InsertAfter(5, ptr2);
No2.Display("\n------------ No2 ------------ List contains 2, 3, 4, 6 ",true,No2);
No2.InsertAfter(7, ptr3);
No2.Display("\n------------ No2 ------------ List contains 2, 3, 4, 6 ",true,No2);
}
if (DIAGNOSTIC_LEVEL <= 7)
{
System.out.println("\n--------------------------------------------------------------------------------");
System.out.println("--------------------------- DIAGNOSTIC_LEVEL = 7 -------------------------------");
System.out.println("------------------------------ Test Inplace -----------------------------------");
System.out.println("--------------------------------------------------------------------------------\n");
int max = 20, pos1, pos2, temp;
DLList<Integer> No1 = new DLList <Integer> ();
int [] data = new int [max+1];
// Fill data cells 1, 2, 3, ..., max with values 1, 2, 3, ... , max
for (int pos = 0; pos <= max; pos ++)
data[pos] = pos;
Random r = new Random();
// Randomly mix up valuse 1, 2, 3, ... , max
for (int pos = 1; pos <= max * 2; pos ++)
{
pos1 = r.nextInt(max)+1;
pos2 = r.nextInt(max)+1;
temp = data[pos1];
data[pos1] = data[pos2];
data[pos2] = temp;
}
for (int pos = 1; pos <= max; pos ++)
if ( No1.Inplace(data[pos]))
No1.Display("-------- No1 ------ Inplace Value = " + data[pos], false, No1);
else
System.out.println("Unable To Inplace Value");
DLList<Part> SportingGoods = new DLList <Part> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!SportingGoods.Inplace(Inventory[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
SportingGoods.Display("\n------- Sporting Goods ------- ", true,SportingGoods);
DLList<Athlete> Team = new DLList <Athlete> ();
for (int Counter = 1; Counter <= 10; Counter ++)
if (!Team.Inplace(Player[Counter]))
System.out.println("\n\n\n\n\nUnsuccessful Pushing Object\n\n\n\n\n\n");
Team.Display("\n------- Team ------- ", true,Team);
}
*/
System.out.println("\n================================================================================");
System.out.println("========================= End Of TestDLList ====================================");
System.out.println("================================================================================");
}
}
7] Create the missing components. Incorporate the testing as you go. Continue to increase the the DIAGNOSTIC_LEVEL as you go.
8] Explain the power provided by the generics in this program.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
9] Assume that you were to create a new class, called Auto, that included information about cars. Assume that you also wish to use it with your DLList class. Complete the first line of the class definition for this class:
public class Auto ______________________________________________________________
10] Assume that the auto class had a private string data member, called Description, that shall contain things like Corvette Sting Ray, Mercedes Benz, etc. This is to be a non-case sensitive primary key to be used when comparing two Auto objects. Write the code for an appropriate compareTo method for this class.
public int compareTo(
11] Create a function called FillNumericList(String prompt) which will (1) use the JOptionPane to display a prompt and provide the user with the opportunity to read the numeric value. Use your Int3 class. No modifications of DLList class are necessary! You may alter Int3 if you need.
FillNumericList(No1, "Enter Big N1...................................................................."); shall

Take the number and place it into the linked list in sets of three digits each. The number above would require 7 nodes. The data must be broken down into the following format:
F
R
|-----|--|
|-----|--|
|-----|--|
|-----|--|
|-----|--|
|-----|--|
|-----|---|
| 12 | -|-> | 345 | -|-> | 678 | -|-> | 901 | -|-> | 234 | -|-> | 567 |
-|-> | 890 | / |
|-----|--| |-----|--|
|-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
Your display should
look something like:
|---------------------------------------------------|-------------|------------|
17172ea | | 9fbe93 | 12f6684 |
|---------------------------------------------------|-------------|------------|
Left Info Right
|------------|----------------------------------------------------|------------|
9fbe93 | null | 12 | a39137 |
|------------|----------------------------------------------------|------------|
a39137 | 9fbe93 | 345 | e39a3e |
|------------|----------------------------------------------------|------------|
e39a3e | a39137 | 678 | 169e11 |
|------------|----------------------------------------------------|------------|
169e11 | e39a3e | 901 | 1855af5 |
|------------|----------------------------------------------------|------------|
1855af5 | 169e11 | 234 | ae000d |
|------------|----------------------------------------------------|------------|
ae000d | 1855af5 | 567 | 12f6684 |
|------------|----------------------------------------------------|------------|
12f6684 | ae000d | 890 | null |
|------------|----------------------------------------------------|------------|
You might create a Main program for testing. Alter Diagnostic Level 8 - your program with the following inputs:
fill and display list No1 with 1234567 Create and fill and display list No2 with 12345678 Create and fill and display list No3 with 123456789 Create and fill and display list No4 with -1234567 Create and fill and display list No5 with -12345678 Create and fill and display list No6 with -123456789 Create and fill and display list No7 with 123456780123456780123456780123456780 Create and fill and display list No8 with 1 Create and fill and display list No9 with 12 Create and fill and display list No10 with 123 Create and fill and display list No11 with -1 Create and fill and display list No12 with -12 Create and fill and display list No13 with -123
12] Create a function
called DisplayNumericList(String Message) which will display the list above
in the following format:
DisplayNumericList( No1,
"No1 = "); shall display
No1 =
12,345,678,901,234,567,890
Add Diagnostic Level 9 for testing!
13] Create a function called AddNumericLists which will
Assume that NoList1 =
F
R
|-----|--| |-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
| 12 | -|-> | 345 | -|-> | 578 | -|-> | 901 | -|-> | 234 | -|-> | 567 |
-|-> | 890 | / |
|-----|--| |-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
And NoList2 =
F
R
|-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
|
5 | -|-> | 421 | -|-> | 098 | -|-> | 765 | -|-> | 432 | -|-> | 110 | / |
|-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
AddNumericLists(NoList1, NoList2, NoList3); shall add List1, and List2 and place the sum in List3
Assume that NoList3 =
F
R
|-----|--| |-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
| 12 | -|-> | 351 | -|-> | 000 | -|-> | 000 | -|-> | 000 | -|-> | 000 |
-|-> | 000 | / |
|-----|--| |-----|--| |-----|--|
|-----|--| |-----|--| |-----|--|
|-----|---|
Add Diagnostic Level 10 for testing!
11] I will mail you an appropriate block of code for DIAGNOSTIC_LEVEL 20 final testing. You are welcome to add any additional testing that you like. Include the test code and set the DIAGNOSTIC_LEVEL = 20 at the top of your program.
if (DIAGNOSTIC_LEVEL <= 20) { ... }
1] Spot Check!
2] Print and complete this assignment sheet.
3] Print all DLList.java using New Courier Font [8 pt].
4] Produce and print the javadocs for DLLis
5] Mail me your solution in a message whose Subject is CSCI 1321 - DLList1
6] Make sure you have at least two aditional
backup copies of all projects. Maybe store one on your Y drive and one on your
hard drive.
7] Those Labs labeled "Individual Assignment" are to
be done separately by each individual. Using a pen, each individual is to
print his/her name at the top of this document in the space provided and
sign it. Those Labs labeled "Team Assignment" may be done as a team or
individually. Using a pen, each individual on the team is to print print
his/her name at the top of this document in the space provided and sign it.
Submit only one copy of team assignments!