Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Generics, Linked Lists, Stacks and Apps

mzmagar
mzmagar 


Create a runable application that uses a Queue Implement a Stack ADT Implement a Linked List and use it in a runnable aplication Set up a unit testing environment and run unit test which validate and verify program integrity Write java code that adheres to best practices (eg abstraction ) and OOP Analyze the efficiency of all non-test code using Big-O notation Attachments Tags Clarifications

Answers

Generics, Linked Lists, Stacks and Apps

felo
felo 



1.A supermarket simulation that uses a Queue class to model lines of customers in a supermarket
2.A simple generic implementation of a Stack ADT
3.A game simulation that is similar to duck-duck-goose
Find attached solution to the above problems

IF In Need of the othe projects of CS 249 please message me
Attachments
CS 249 - Project2..zip (61 K) Download












Preview
name="!?*.form" /> <entry name="!?*.class" /> <entry name="!?*.groovy" /> <entry name="!?*.scala" /> <entry name="!?*.flex" />

Preview
<settings

Preview
application that includes

Preview
version="1.0" encoding="UTF-8"?> <project

Preview
version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out"

Preview
<module fileurl="file://$PROJECT_DIR$/Project2.iml" filepath="$PROJECT_DIR$/Project2.iml"

Preview
<component name="DependencyValidationManager">

Preview
height="50" /> </default-constraints> </item> <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> <preferred-size width="150" height="50" /> </default-constraints> </item> <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach

Preview
<mapping directory="" vcs=""

Preview
/> <abbreviatePackageNames /> <autoscrollToSource /> <autoscrollFromSource /> <sortByType /> </navigator> <panes> <pane id="PackagesPane" /> <pane id="Scope" /> <pane id="ProjectPane"> <subPane> <PATH> <PATH_ELEMENT> <option name="myItemId" value="Project2" /> <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" /> </PATH_ELEMENT> </PATH> <PATH> <PATH_ELEMENT> <option name="myItemId" value="Project2" /> <option name="myItemType" val

Preview
[[[5] [2] [3]], [[5] [6]], [[3]]] [[[4] [2] [3]], [[4] [6]], [[2]]] [[[3] [2] [3]], [[3] [6]], [[1]]] [[[2] [2] [3]], [[2] [6]], [[0]]] [[[1] [2] [3]], [[1] [6]], [[0]]] [[[0] [2] [3]], [[0] [6]], [[0]]] [[[0] [1] [3]], [[0] [5]], [[0]]] [[[0] [0] [3]], [[0] [4]], [[0]]] [[[0] [0]

Preview
+(i+1) + ": "); clerkLines[i].display(); System.out.println("\n--------------------------------"); } } //====================================================== public void newPerson(int items){ lineSizeSmall = 0; for (int i = 0; i < sizeOfLines; i++) if (clerkLines[i].count < clerkLines[lineSizeSmall].count) lineSizeSmall = i; clerkLines[lineSizeSmall].insert(items); } //====================================================== public

Preview
public int count = 0; //====================================================== public clerkLine(int maxSize){ person = new int[maxSize]; size = maxSize; } //====================================================== public void insert(int newCustomer){ if (count > size) System.out.println("The line is full!"); else person[count++] = newCustomer; } //====================================================== public

Preview
public boolean isEmpty() { return (count==0); } //====================================================== public void display(){ for (int i = 0; i < maxSize; i++){ System.out.print("[" + person[i] + "]"); } } public int getCount() { return count; }

Preview
[5]], [[0]]] [[[0] [0] [3]], [[0] [4]], [[0]]] [[[0] [0] [2]], [[0] [3]], [[0]]] [[[0] [0] [1]], [[0] [2]], [[0]]] [[[0] [0] [0]], [[0] [1]], [[0]]] [[[0] [0] [0]], [[0] [0]], [[0]]] * Author: Nicholas Finch * CS 249 * 3/8/2015 * */

Preview
} //====================================================== public void insertLine(clerkLine newLine){ clerkLines[count] = newLine;//add lines when needed count++; } //====================================================== public void display(){ for (int i = 0; i < sizeOfLines; i++){ System.out.println("Line " +(i+1) + ": "); clerkLines[i].display(); System.out.println("\n--------------------------------"); } }

Preview
size --; return; } Person ptr = start; pos = pos - 1 ; for (int i = 1; i < size - 1; i++){ if (i == pos){ Person tmp = ptr.getNext(); tmp = tmp.getNext(); ptr.setNext(tmp); break;

Preview
by User on 3/12/2015. */ public class elimGameApp { public static void main(String[] args){ elimGame newElimGame = new elimGame(); System.out.print("How many players?"); int numPlayers = 5;//scan

Preview
public Person next; public Person(){ next = null; iData = ""; } public Person(String d, Person n){ next = n; iData = d;

Preview
current = current.next; } current = temp; } public void eliminate(int d) { for (int i = 0; i < d-1; i++) { current = current.next; } current.next = current.next.next; start = current.next; size--; } public

Preview
number: "); int priorityElim = Integer.parseInt(input.nextLine()); System.out.println("Eliminate every "+ priorityElim + " people."); System.out.println("Input the number to start at: "); int numStart = Integer.parseInt(input.nextLine()); System.out.println("Starting at "+ numStart); for (int i = 0; i < people; i++){ newElimGame.insertPerson(i); }

Preview
class Person { private int iData; public Person next; public Person(){ next = null; iData = 0; } public Person(int d, Person n){

Preview
to stack, it is full"); else elements[++top] = pushVal; } public E pop(){ //TODO pop off the stack //If it's empty error //return the data in the stack when popping. //it is a generic pop, thus we place E to allow

Preview
public static void main(String[] args){ genericStack<String> list1 = new genericStack<String>(10); genericStack<Socket> list2 = new genericStack<Socket>(10); genericStack<Double> list3 = new genericStack<Double>(10); list1.push("Hello World!"); list1.push("More Strings!"); list1.push("This string!"); list1.push("Is string!"); list1.push("Awesome

Preview
in the Group = "); Person ptr = start; if (size == 0){ System.out.print("empty\n"); return; } if (size == 1){ System.out.print("[" +start.getiData()+"] "); } if (size != 1){ if (start.getNext() == start){ System.out.print("["+start.getiData()+ "] ["+ptr.getiData()+ "]\n"); return; } System.out.print("["+start.getiData()+ "] "); ptr = start.getNext(); while (ptr.getNext() != start){ System.out.print("["+ptr.getiData()+ "]

Preview
3/12/2015. */ public class elimGameApp { public static void main(String[] args){ elimGame newElimGame = new elimGame(); System.out.print("How many players?"); int numPlayers =

Preview
} public Person(String d, Person n){ next = n; iData = d; } public void setNext(Person next){ this.next = next; }

Preview
!= temp) current = current.next; temp = current.next; current.next = null; current = temp; } //simply displays last person public void displayLastPlayer() { System.out.print("\n"+current.getiData()+" is the winner!\n"); } //checks if the pointer is == to null public boolean isNull(){ if (current.next == null) return true; return false; } //process of

Preview
new Scanner(System.in); elimGame newElimGame = new elimGame(); System.out.println("How many people (1-10 people): "); int people = Integer.parseInt(input.nextLine()); while (!(people <= 10)){ System.out.println("You must input a number between 1 and 10: "); people = Integer.parseInt(input.nextLine()); } System.out.println("There are " + people + " people."); System.out.println("Input the elimination number: ");

Preview
next; } public void setiData(int id){ iData = id; } public Person getNext(){ return next; } public int getiData(){ return iData; }

Preview
final int size; private int top; private E[] elements; public genericStack(int size){ this.size = size; top = -1; elements = (E[]) new Object[size]; //creating array } public void push(E pushVal){ //TODO push to the stack //if it's full error if (isFull()) System.out.println("Can't push to stack, it is full"); else elements[++top]

Preview
new genericStack<Socket>(10); genericStack<Double> list3 = new genericStack<Double>(10); list1.push("Hello World!"); list1.push("More Strings!"); list1.push("This string!"); list1.push("Is string!"); list1.push("Awesome string!"); list2.push(new Socket()); list2.push(new Socket()); list2.push(new Socket()); list2.push(new Socket());

Preview
first; while (current.next != null) current = current.next;// go to next link current.next = first; } public Link find(int key){ Link current = first; // start at 'first' while(current.iData != key){ if(current.next == null) // if end of list, return null; // didn't find it else // not end of

Preview
package com.company.Supermarket; /* * Author: Nicholas Finch * CS 249 * 10/17/14 * Collaborated with Doug */ public class clerkLine { private int[] person; private int maxSize; private int count = 0; //====================================================== public clerkLine(int maxSize){ person = new int[maxSize]; this.maxSize = maxSize; } //====================================================== public void insert(int newCustomer){ if (count >=

Preview
[0] [3]], [[0] [4]], [[0]]] [[[0] [0] [2]], [[0] [3]], [[0]]] [[[0] [0] [1]], [[0] [2]], [[0]]] [[[0] [0] [0]], [[0] [1]], [[0]]] [[[0] [0] [0]], [[0] [0]], [[0]]] * Author: Nicholas Finch * CS 249 * 3/8/2015 * */ public class StoreCheckOutApp{ public static void main(String[] args){ Random rand = new Random(); Scanner input

Preview
sizeOfLines = numCheckOuts; } //====================================================== public void insertLine(clerkLine newLine){ clerkLines[count] = newLine;//add lines when needed count++; } //====================================================== public void display(){ for (int i = 0; i < sizeOfLines; i++){ System.out.println("Line " +(i+1) + ": "); clerkLines[i].display(); System.out.println("\n--------------------------------"); } } //=========================================

project2.png (107 K) Download Preview

Screenshots
Screenshot
Purchase Answer