Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package doggydates;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.util.ListIterator;
- /**
- *
- * @author WeaponX
- */
- public class Account {
- private ListNode head;
- private ListNode current;
- private ListNode previous;
- private String username;
- private String password;
- private String email;
- private String name;
- private String breed;
- private String gender;
- private String age;
- private String state;
- private String hobby;
- public Account (String username, String password, String email, String name, String breed, String gender, String age, String state, String hobby){
- head = null;
- current = null;
- previous = null;
- this.username = username;
- this.password = password;
- this.email = email;
- this.name = name;
- this.breed = breed;
- this.gender = gender;
- this.age = age;
- this.state = state;
- this.hobby = hobby;
- }
- public String getUsername(){
- return username;
- }
- public String getPassword(){
- return password;
- }
- public String getEmail(){
- return email;
- }
- public String getName(){
- return name;
- }
- public String getBreed(){
- return breed;
- }
- public String getGender(){
- return gender;
- }
- public String getAge(){
- return age;
- }
- public String getState(){
- return state;
- }
- public String getHobby(){
- return hobby;
- }
- public void setUsername(String u){
- username = u;
- }
- public void setPassword(String p){
- password = p;
- }
- public void setEmail(String e){
- email = e;
- }
- public void setName(String n){
- name = n;
- }
- public void setBreed(String b){
- breed = b;
- }
- public void setGender(String g){
- gender = g;
- }
- public void setAge(String a){
- age = a;
- }
- public void setState(String s){
- state = s;
- }
- public void setHobby(String h){
- hobby = h;
- }
- @Override
- public String toString() {
- return ""+username+"\n"+password+"\n"+email+"\n"+name+"\n"+breed+"\n"+gender+"\n"+age+"\n"+state+"\n"+hobby;
- }
- public boolean onList(String target){
- return find(target) != null;
- }
- public String[] toArray(){
- String[] anArray = new String[length()];
- ListNode position = head;
- int i = 0;
- while(position != null){
- anArray[i] = position.data;
- i++;
- position = position.link;
- }
- return anArray;
- }
- private ListNode find(String target){
- boolean found = false;
- ListNode position = head;
- while ((position != null) && !found){
- String dataAtPosition = position.getData();
- if(dataAtPosition.equals(target))
- found = true;
- else
- position = position.getLink();
- }
- return position;
- }
- public void showList(){
- ListNode position = head;
- while (position != null){
- System.out.println(position.getData());
- position = position.getLink();
- }
- }
- public int length(){
- int count = 0;
- ListNode position = head;
- while (position != null){
- count++;
- position = position.getLink();
- }
- return count;
- }
- public void addANodeToStart(String addData){
- head = new ListNode(addData, head);
- if ((current == head.link) && (current != null))
- previous = head;
- }
- public void resetIteration(){
- current = head;
- previous = null;
- }
- public boolean moreToIterate(){
- return current != null;
- }
- public void goToNext(){
- if (current != null){
- previous = current;
- current = current.link;
- }
- else if (head != null){
- System.out.println("Iterated too many times or uninitialized iteration.");
- System.exit(0);
- }
- else{
- System.out.println("Iterating with an empty list.");
- System.exit(0);
- }
- }
- public String getDataAtCurrent(){
- String result = null;
- if (current != null)
- result = current.data;
- else{
- System.out.println("Getting data when current is not at any node.");
- System.exit(0);
- }
- return result;
- }
- public void setDataAtCurrent(String newData){
- if(current != null){
- current.data = newData;
- }
- else{
- System.out.println("Setting data when current is not at any node.");
- System.exit(0);
- }
- }
- public void insertNodeAfterCurrent(String newData){
- ListNode newNode = new ListNode();
- newNode.data = newData;
- if(current != null){
- newNode.link = current.link;
- current.link = newNode;
- }
- else if (head != null){
- System.out.println("Inserting when iterator is past all " + "nodes or is not initialized.");
- System.exit(0);
- }
- else{
- System.out.println("Using insertNodeAfterCurrent with empty list.");
- System.exit(0);
- }
- }
- public void deleteCurrentNode(){
- if((current != null) && (previous == null)){
- previous.link = current.link;
- current = current.link;
- }
- else if((current != null) && (previous == null)){
- head = current.link;
- current = head;
- }
- else{
- System.out.println("Deleting with uninitialized current or any empty " + "list.");
- System.exit(0);
- }
- }
- private class ListNode{
- private String data;
- private ListNode link;
- public ListNode(){
- link = null;
- data = null;
- }
- public ListNode(String newData, ListNode linkValue){
- data = newData;
- link = linkValue;
- }
- //sets data into a node
- public void setData(String newData){
- data = newData;
- }
- // gets data in a node
- public String getData(){
- return data;
- }
- //connects a node to another node
- public void setLink(ListNode newLink){
- link = newLink;
- }
- //gets the next node
- public ListNode getLink(){
- return link;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement