Placeholder

CSIS 312 Assignment 8 SecureRandom

$19.00

Description

Write a program that inserts 25 random numbers from 0 to 99 (using SecureRandom) inclusive into a linked-list object in sorted order and then calls the linked-list object’s print() method.
The following files are provided for you and must be used for this exercise:
·      SortedList.java
o  Modify the insertSorted() method to create a sorted list. Feel free to use any ListNode or SortedList method. If you add any new methods they must be called either directly or indirectly from insertSorted().
o  Do not modify or change any other aspect of SortedList.java.
o  ListTest.java should not be changed except to enter your name in the place designated for it.
·      EmptyListException.java which is used by SortedList and ListTest and should not be changed or modified at all.
Note: If you do not use your modified insertSorted() method to sort your list as you build it, you will not get any credit for your work. Also, if you use Collections.sort() or Arrays.sort() or any pre-written sorting function to sort your list you will not get any credit for the assignment.
Make sure that your screen shot(s) show your program running and that your runtime display shows that your program does all that is required of it. You only get credit for what you demonstrate.
// Fig. 21.4: EmptyListException.java
// Class EmptyListException declaration.

public class EmptyListException extends RuntimeException
{
// constructor
public EmptyListException()
{
this("List"); // call other EmptyListException constructor
}

// constructor
public EmptyListException(String name)
{
super(name + " is empty"); // call superclass constructor
}
} // end class EmptyListException

// Based on Fig. 21.5: ListTest.java
// ListTest class to demonstrate SortedList capabilities.
import java.security.SecureRandom;

public class ListTest
{
public static void main(String[] args)
{
System.out.println("<Your name goes here — Lab #8n");

SortedList<Integer> list = new SortedList<>();
SecureRandom rNum = new SecureRandom();

// insert 25 random (between 0 and 99 inclusive) integers into the list
for (int i = 0; i < 25; i++)
//Your job is to modify insertSorted so that it creates a
//sorted list one element at a time.
list.insertSorted(rNum.nextInt(100));

list.print();
} // end class ListTest

// Based on Fig. 21.3: List.java
// ListNode and SortedList class declarations.

// class to represent one node in a list
class ListNode<T extends Comparable<T>>
{
// package access members; SortedList can access these directly
T data; // data for this node
ListNode<T> nextNode; // reference to the next node in the list

// constructor creates a ListNode that refers to object
ListNode(T object)
{
this(object, null);
}

// constructor creates ListNode that refers to the specified
// object and to the next ListNode
ListNode(T object, ListNode<T> node)
{
data = object;
nextNode = node;
}

// return reference to data in node
T getData()
{
return data;
}

// return reference to next node in list
ListNode<T> getNext()
{
return nextNode;
}
} // end class ListNode<T>

// class SortedList definition
public class SortedList<T extends Comparable<T>>
{
private ListNode<T> firstNode;
private ListNode<T> lastNode;
private String name; // string like "list" used in printing

// constructor creates empty SortedList with "list" as the name
public SortedList()
{
this("list");
}

// constructor creates an empty SortedList with a name
public SortedList(String listName)
{
name = listName;
firstNode = lastNode = null;
}

// insert "insertItem" into the proper position within the sorted list
public void insertSorted(T insertItem)
{
// Complete insertSorted() so that insertItem is added to the list
// in sorted order. Use the compareTo() method (part of the interface
// Comparable) to do lesser/greater than comparisons of type T objects.
// See Section 20.4 and Fig 21.15 for more information on compareTo and
// Examples of its use.

// Use insertAtFront(), insertAtBack(), and insert() as necessary to
// place insertItem in its proper place in the list.

// Do not change any of the class signatures nor any of the methods in
// this file.

// You may delete these comments, but be sure you follow the guidance
// provided.

// If you use Collections.sort() or Arrays.sort() or any similar pre-written
// sorting function, you will not get any credit for your work.
}

private void insert(T insertItem, ListNode<T> previousNode)
{
previousNode.nextNode = new ListNode(insertItem, previousNode.nextNode);
}

// insert item at front of SortedList
private void insertAtFront(T insertItem)
{
if (isEmpty()) // firstNode and lastNode refer to same object
firstNode = lastNode = new ListNode<T>(insertItem);
else // firstNode refers to new node
firstNode = new ListNode<T>(insertItem, firstNode);
}

// insert item at end of SortedList
private void insertAtBack(T insertItem)
{
if (isEmpty()) // firstNode and lastNode refer to same object
firstNode = lastNode = new ListNode<T>(insertItem);
else // lastNode’s nextNode refers to new node
lastNode = lastNode.nextNode = new ListNode<T>(insertItem);
}

// remove first node from SortedList
public T removeFromFront() throws EmptyListException
{
if (isEmpty()) // throw exception if SortedList is empty
throw new EmptyListException(name);

T removedItem = firstNode.data; // retrieve data being removed

// update references firstNode and lastNode
if (firstNode == lastNode)
firstNode = lastNode = null;
else
firstNode = firstNode.nextNode;

return removedItem; // return removed node data
} // end method removeFromFront

// remove last node from SortedList
public T removeFromBack() throws EmptyListException
{
if (isEmpty()) // throw exception if SortedList is empty
throw new EmptyListException(name);

T removedItem = lastNode.data; // retrieve data being removed

// update references firstNode and lastNode
if (firstNode == lastNode)
firstNode = lastNode = null;
else // locate new last node
{
ListNode<T> current = firstNode;

// loop while current node does not refer to lastNode
while (current.nextNode != lastNode)
current = current.nextNode;

lastNode = current; // current is new lastNode
current.nextNode = null;
}

return removedItem; // return removed node data
}

// determine whether list is empty
public boolean isEmpty()
{
return firstNode == null; // return true if list is empty
}

// output list contents
public void print()
{
if (isEmpty())
{
System.out.printf("Empty %s%n", name);
return;
}

System.out.printf("The %s is: ", name);
ListNode<T> current = firstNode;

// while not at end of list, output current node’s data
while (current != null)
{
System.out.printf("%s ", current.data);
current = current.nextNode;
}

System.out.println();
}
}
<!– /wp:shortcode –>

<!– wp:paragraph –>
<p>
SCREENSHOTS
SOLUTION
PAYMENT
The solution consists of:
A report word document for this assignment
All Java programs and classes
A Netbeans project in case you want to run the project on your computer.
Screenshots showing program running
Attachments [Move over files to preview content of those files]
CSIS312_Assignment_8_-_SecureRandom.zip (84.13 KB)
Classes
CSIS312-Week-8-SecureRandom-Screenshot-1.png
CSIS312-Week-8-SecureRandom-Screenshot-2.png
Source Code
EmptyListException.java
ListTest.java
SortedList.java
Preview EmptyListException.java
xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxx {
// xxxxxxxxxxx
xxxxxx xxxxxxxxxxxxxxxxxx() {
this(“List”); // call other EmptyListException constructor }
// constructor public EmptyListException(String name) { super(name + ” is empty”); // call superclass constructor }
} // xxx xxxxx xxxxxxxxxxxxxxxxxx
Preview ListTest.java
xxxxxx xxxx.xxxxxxxx.xxxxxxxxxxxx;
xxxxxx xxxxx xxxxxxxx {
public static void main(String[] args) { System.out.println(”
list = new SortedList<>(); SecureRandom rNum = new SecureRandom();
// insert 25 random (between 0 and 99 inclusive) integers into the list
xxx (xxx x = 0; x < 25; x++) //xxxx xxx xx xx xxxxxx xxxxxxxxxxxx xx xxxx xx xxxxxxx x //xxxxxx xxxx xxx xxxxxxx xx x xxxx. { xxxx.xxxxxxxxxxxx(xxxx.xxxxxxx(100)); } Preview SortedList.java xxxx(xxxxxx, xxxx); } // xxxxxxxxxxx xxxxxxx xxxxxxxx xxxx xxxxxx xx xxx xxxxxxxxx // xxxxxx xxx xx xxx xxxx xxxxxxxx ListNode(T object, ListNode node) { data = object; nextNode = node; } // return reference to data in node T getData() { return data; } // return reference to next node in list ListNode getNext() { xxxxxx xxxxxxxx; } } // xxx xxxxx xxxxxxxx // xxxxx xxxxxxxxxx xxxxxxxxxx xxxxxx xxxxx xxxxxxxxxx > {
Price: $19
You May Also Like:
CSIS 312 Entire Course
CSIS 312 Assignment 2 Employee Class
CSIS 312 Assignment 3 Payroll System
CSIS 312 Assignment 4 Random Sentences
CSIS 312 Assignment 5 LinkedList Object
CSIS 312 Assignment 6 printArray and Factorial Calculator
CSIS 312 Assignment 7 Pair Class
CSIS 312 Assignment 8 Stack Data Structure
CSIS 312 Assignment 6 Print Array

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.