Completed Final Exam

master
Noah Pederson 6 years ago
parent 322c83c84c
commit e609061bf5
  1. 1
      .idea/modules.xml
  2. 124
      .idea/uiDesigner.xml
  3. 11
      FinalExam/FinalExam.iml
  4. 28
      FinalExam/src/Pair.java
  5. 21
      FinalExam/src/PairTest.java
  6. 184
      FinalExam/src/SortedList.java
  7. 21
      FinalExam/src/SortedListTest.java

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Final-Project/Final-Project.iml" filepath="$PROJECT_DIR$/Final-Project/Final-Project.iml" />
<module fileurl="file://$PROJECT_DIR$/FinalExam/FinalExam.iml" filepath="$PROJECT_DIR$/FinalExam/FinalExam.iml" />
<module fileurl="file://$PROJECT_DIR$/Lab-01/Lab-01.iml" filepath="$PROJECT_DIR$/Lab-01/Lab-01.iml" />
<module fileurl="file://$PROJECT_DIR$/Lab-03/Lab-03.iml" filepath="$PROJECT_DIR$/Lab-03/Lab-03.iml" />
<module fileurl="file://$PROJECT_DIR$/Lab-04/Lab-04.iml" filepath="$PROJECT_DIR$/Lab-04/Lab-04.iml" />

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<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.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<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.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<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.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.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.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" 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-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,28 @@
/**
* Created by noah on 8/29/2016.
*/
public class Pair <F, S> {
F p1;
S p2;
public Pair(F p1, S p2) {
this.p1 = p1;
this.p2 = p2;
}
public F getFirst() {
return p1;
}
public void setFirst(F p1) {
this.p1 = p1;
}
public S getSecond() {
return p2;
}
public void setSecond(S p2) {
this.p2 = p2;
}
}

@ -0,0 +1,21 @@
public class PairTest
{
public static void main( String[] args )
{
// create pair of integer and string
Pair< Integer, String > numberPair =
new Pair< Integer, String >( 1, "one" );
// display original numberPair
System.out.printf( "Original pair: < %d, %s >\n",
numberPair.getFirst(), numberPair.getSecond() );
// modify pair
numberPair.setFirst( 2 );
numberPair.setSecond( "Second" );
// display modified numberPair
System.out.printf( "Modified pair: < %d, %s >\n",
numberPair.getFirst(), numberPair.getSecond() );
} // end method main
} // end class PairTest

@ -0,0 +1,184 @@
// class SortedList definition
//=====================================================
public class SortedList< T extends Comparable< T > >
{
private ListNode< T > firstNode;
private ListNode< T > lastNode;
private String name; // string like "sortedlist" used in printing
// Constructors
//------------------------------------------------
// constructor creates empty SortedList with "sorted list" as the name
public SortedList()
{
this( "sorted list" );
} // end List no-argument constructor
// constructor creates an empty SortedList with a name
public SortedList( String listName )
{
name = listName;
firstNode = lastNode = null;
} // end List one-argument constructor
//------------------------------------------------
// insert item in sorted order
public void insertInOrder( T insertItem )
{
if ( isEmpty() )
firstNode = lastNode = new ListNode< T >( insertItem );
else if ( firstNode.getData().compareTo( insertItem ) > 0 )
// value is the smallest
firstNode = new ListNode< T >( insertItem, firstNode );
else if ( lastNode.getData().compareTo( insertItem ) <= 0 )
// value is the largest
lastNode = lastNode.nextNode = new ListNode< T >( insertItem );
else
{
ListNode< T > currentNode = firstNode.getNext();
ListNode< T > previousNode = firstNode;
// find correct insert position and update all
// references to insert the new node
// your code goes here
//While the item in the list being compared is still larger than or equal to the insert item, and the current
//Items next node is not null, keep loops through the list.
while(currentNode.getData().compareTo(insertItem) <= 0 && currentNode.nextNode != null) {
//The current node is now the last node
previousNode = currentNode;
//The current node is the previous current nodes next node
currentNode = currentNode.nextNode; //WHY IS THIS A PUBLIC INSTANCE VARIABLE!?!?
}
//Create a new ListNode<T> item with the insertItem data
ListNode<T> newItem = new ListNode<T>(insertItem);
//Set the previous nodes nextNode to the next item
previousNode.nextNode = newItem;
//the next new items nextNode is the current node, because it's greater than this one :D
newItem.nextNode = currentNode;
} // end else
} // end method insertInOrder
//------------------------------------------------
// remove first node from SortedList
public T removeFromFront()
{
if ( isEmpty() ) // throw exception if SortedList is empty
System.out.printf("List is Empty\n");
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()
{
if ( isEmpty() ) // throw exception if SortedList is empty
System.out.printf("List is Empty\n");
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;
} // end else
return removedItem; // return removed node data
} // end method removeFromBack
//------------------------------------------------
// determine whether list is empty
public boolean isEmpty()
{
return firstNode == null; // return true if list is empty
} // end method isEmpty
//------------------------------------------------
// output list contents
public void print()
{
if ( isEmpty() )
{
System.out.printf( "Empty %s\n", name );
return;
} // end if
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;
} // end while
System.out.println();
} // end method print
} // end class SortedList< T >
//class ListNode declarations.
//===========================================================
//class to represent one node in a list
class ListNode< T >
{
// instance variables
T data; // data for this node
ListNode< T > nextNode; // reference to the next node in the list
//Constructors
//------------------------------------------------
// constructor creates a ListNode that refers to object
ListNode( T object )
{
this( object, null );
} // end ListNode one-argument constructor
// constructor creates ListNode that refers to the specified
// object and to the next ListNode
ListNode( T object, ListNode< T > node )
{
data = object;
nextNode = node;
} // end ListNode two-argument constructor
//-----------------------------------------------------
// return reference to data in node
T getData()
{
return data; // return item in this node
} // end method getData
//------------------------------------------------------
// return reference to next node in list
ListNode< T > getNext()
{
return nextNode; // get next node
} // end method getNext
} // end class ListNode< T >

@ -0,0 +1,21 @@
// class SortedListTest definition
//=====================================================
// Test driver for SortedList class.
import java.util.Random;
public class SortedListTest
{
public static void main( String[] args )
{
Random random = new Random();
SortedList< Integer > list = new SortedList< Integer >();
// fill SortedList with 25 random integers
for ( int i = 0; i < 25; i++ )
list.insertInOrder( random.nextInt( 101 ) );
// display sorted list
list.print();
} // end main
} // end class SortedListTest
Loading…
Cancel
Save