anonymous / LinkedListNode.java
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View LinkedListNode.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import java.util.*;
 
public class LinkedListNode
{
//local constants
 
//local variables
 
//BEGIN CODE
 
public UserData userInfo = new UserData("no data","no data",0);
public LinkedListNode link;
 
}//END LinkedListNode
View LinkedListNode.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
public class UserData
{
//local constants
 
//local variables
String firstName;
String lastName;
float userScore;
 
 
/**********************************************************
* Method Name : Constructor
* Author : Chad Johnson
* Date : Mar 05, 2013
* Course/Section : CSC112 - section number
* Program Description: This method will initialize all the
* data that the StudentDriver class will keep track of.
*
* BEGIN StudentDriver
* END StudentDriver
**********************************************************/
 
public UserData(String inFirstName, String inLastName, float inUserScore)
{
//local constants
 
//local variables
 
//Declarations
firstName = inFirstName;
lastName = inLastName;
userScore = inUserScore;
 
} //end main method
 
/**********************************************************
* Method Name : toString
* Author : Ryan Peters
* Date : Feb 11, 2013
* Course/Section : CSC112 - section number
* Program Description: This method will returns values to the main
*
* BEGIN toString
*
* END toString
**********************************************************/
 
public String toString()
{
//local constants
 
//local variables
 
return firstName +" "+ lastName +" "+ userScore+"\n";
}
 
} //end Lab03
 
View LinkedListNode.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
import java.util.*;
 
public class UserDriver
{
/**********************************************************
* Method Name : Main
* Author : Chad Johnson
* Date : Feb 11, 2013
* Course/Section : CSC112 - section number
* Program Description: This method will take data from the
* user, store it in its own data element(that being UserData)
* and that will be added to a Linked List. The user will be
* any part of the Linked List.
*
*
* BEGIN main
* ud.menu();
* WHILE(option isn't quit)
* IF(option is addData)
* prompt user for which data
* add data to linked List and move pointer in list
* ELSEIF(option is display)
* IF(data has been entered)
* display allData until the linked list is null
* ELSE
* tell user no data was entered
* ENDIF
* ENDIF
* ud.menu();
* ENDWHILE
* END main
**********************************************************/
 
public static void main(String args[])
{
//local constants
final String QUIT = "-1";
final String ADD_DATA = "1";
final String DISPLAY = "2";
final String DELETE = "3";
 
//local variables
String firstName, lastName, option;
float score;
boolean dataEntered;
LinkedListNode head = null, curr, prev;
 
UserData userInfo = new UserData("no data2","no data2",0);
UserDriver ud = new UserDriver();
Library myLib = new Library();
//BEGIN MAIN METHOD~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
curr = head;
dataEntered = false;
ud.menu();
option = Keyboard.readString();
myLib.clrscr();
while(!option.equalsIgnoreCase(QUIT))
{
if(option.equalsIgnoreCase(ADD_DATA))
{
//prompt user for info
System.out.print(" Enter First Name: ");
firstName = Keyboard.readString();
System.out.print(" Enter Last Name: ");
lastName = Keyboard.readString();
System.out.print(" Enter User Score: ");
score = Keyboard.readFloat();
 
//gets info from user, puts it into data class, and points to next node
userInfo = new UserData(firstName, lastName, score);
curr.userInfo = userInfo;
prev = curr;
curr = curr.link;
dataEntered = true;
}
else if(option.equalsIgnoreCase(DISPLAY))
{
//checks if info has been entered yet
if(dataEntered == true)
{
curr = head;
while(curr != null)
{
System.out.println(" User Info: " + curr.userInfo);
curr = curr.link;
}//end while
}
else
{
System.out.println(" No Data Entered");
}//end if
}//end if
ud.menu();
option = Keyboard.readString();
}//end while
} //end main method
 
public void menu()
{
System.out.println(" [1] Enter UserData");
System.out.println(" [2] Display UserData");
System.out.println(" [3] Delete UserData");
System.out.println(" [-1] Quit");
System.out.print( " User Input: ");
}//end menu method
} //end UserDriver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.