Advertisement
YmBSnakeEye

Account Class

Mar 13th, 2012
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.91 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package doggydates;
  6.  
  7. import java.io.BufferedWriter;
  8. import java.io.File;
  9. import java.io.FileWriter;
  10. import java.util.ListIterator;
  11.  
  12. /**
  13.  *
  14.  * @author WeaponX
  15.  */
  16. public class Account {
  17.  
  18.     private ListNode head;
  19.     private ListNode current;
  20.     private ListNode previous;
  21.     private String username;
  22.     private String password;
  23.     private String email;
  24.     private String name;
  25.     private String breed;
  26.     private String gender;
  27.     private String age;
  28.     private String state;
  29.     private String hobby;
  30.  
  31.     public Account (String username, String password, String email, String name, String breed, String gender, String age, String state, String hobby){
  32.         head = null;
  33.         current = null;
  34.         previous = null;
  35.         this.username = username;
  36.         this.password = password;
  37.         this.email = email;
  38.         this.name = name;
  39.         this.breed = breed;
  40.         this.gender = gender;
  41.         this.age = age;
  42.         this.state = state;
  43.         this.hobby = hobby;
  44.     }
  45.  
  46.     public String getUsername(){
  47.         return username;
  48.     }
  49.     public String getPassword(){
  50.         return password;
  51.     }
  52.     public String getEmail(){
  53.         return email;
  54.     }
  55.     public String getName(){
  56.         return name;
  57.     }
  58.     public String getBreed(){
  59.         return breed;
  60.     }
  61.     public String getGender(){
  62.         return gender;
  63.     }
  64.     public String getAge(){
  65.         return age;
  66.     }
  67.     public String getState(){
  68.         return state;
  69.     }
  70.     public String getHobby(){
  71.         return hobby;
  72.     }
  73.  
  74.     public void setUsername(String u){
  75.         username = u;
  76.     }
  77.     public void setPassword(String p){
  78.         password = p;
  79.     }
  80.     public void setEmail(String e){
  81.         email = e;
  82.     }
  83.     public void setName(String n){
  84.         name = n;
  85.     }
  86.     public void setBreed(String b){
  87.         breed = b;
  88.     }
  89.     public void setGender(String g){
  90.         gender = g;
  91.     }
  92.     public void setAge(String a){
  93.         age = a;
  94.     }
  95.     public void setState(String s){
  96.         state = s;
  97.     }
  98.     public void setHobby(String h){
  99.         hobby = h;
  100.     }
  101.    
  102.     @Override
  103.     public String toString() {
  104.         return ""+username+"\n"+password+"\n"+email+"\n"+name+"\n"+breed+"\n"+gender+"\n"+age+"\n"+state+"\n"+hobby;
  105.     }
  106.    
  107.     public boolean onList(String target){
  108.         return find(target) != null;
  109.     }
  110.    
  111.     public String[] toArray(){
  112.         String[] anArray = new String[length()];
  113.         ListNode position = head;
  114.         int i = 0;
  115.         while(position != null){
  116.             anArray[i] = position.data;
  117.             i++;
  118.             position = position.link;
  119.         }
  120.         return anArray;
  121.     }
  122.    
  123.     private ListNode find(String target){
  124.         boolean found = false;
  125.         ListNode position = head;
  126.         while ((position != null) && !found){
  127.             String dataAtPosition = position.getData();
  128.             if(dataAtPosition.equals(target))
  129.                 found = true;
  130.             else
  131.                 position = position.getLink();
  132.         }
  133.         return position;
  134.     }
  135.    
  136.     public void showList(){
  137.         ListNode position = head;
  138.         while (position != null){
  139.             System.out.println(position.getData());
  140.             position = position.getLink();
  141.         }
  142.     }
  143.    
  144.     public int length(){
  145.         int count = 0;
  146.         ListNode position = head;
  147.         while (position != null){
  148.             count++;
  149.             position = position.getLink();
  150.         }
  151.         return count;
  152.     }
  153.    
  154.     public void addANodeToStart(String addData){
  155.         head = new ListNode(addData, head);
  156.         if ((current == head.link) && (current != null))
  157.             previous = head;
  158.     }
  159.    
  160.     public void resetIteration(){
  161.         current = head;
  162.         previous = null;
  163.     }
  164.    
  165.     public boolean moreToIterate(){
  166.         return current != null;
  167.     }
  168.    
  169.     public void goToNext(){
  170.         if (current != null){
  171.             previous = current;
  172.             current = current.link;
  173.         }
  174.         else if (head != null){
  175.             System.out.println("Iterated too many times or uninitialized iteration.");
  176.             System.exit(0);
  177.         }
  178.         else{
  179.             System.out.println("Iterating with an empty list.");
  180.             System.exit(0);
  181.         }
  182.     }
  183.    
  184.     public String getDataAtCurrent(){
  185.         String result = null;
  186.         if (current != null)
  187.             result = current.data;
  188.         else{
  189.             System.out.println("Getting data when current is not at any node.");
  190.             System.exit(0);
  191.         }
  192.         return result;
  193.     }
  194.    
  195.     public void setDataAtCurrent(String newData){
  196.         if(current != null){
  197.             current.data = newData;
  198.         }
  199.         else{
  200.             System.out.println("Setting data when current is not at any node.");
  201.             System.exit(0);
  202.         }
  203.     }
  204.    
  205.     public void insertNodeAfterCurrent(String newData){
  206.         ListNode newNode = new ListNode();
  207.         newNode.data = newData;
  208.         if(current != null){
  209.             newNode.link = current.link;
  210.             current.link = newNode;
  211.         }
  212.         else if (head != null){
  213.             System.out.println("Inserting when iterator is past all " + "nodes or is not initialized.");
  214.             System.exit(0);
  215.         }
  216.         else{
  217.             System.out.println("Using insertNodeAfterCurrent with empty list.");
  218.             System.exit(0);
  219.         }
  220.     }
  221.    
  222.     public void deleteCurrentNode(){
  223.         if((current != null) && (previous == null)){
  224.             previous.link = current.link;
  225.             current = current.link;
  226.         }
  227.         else if((current != null) && (previous == null)){
  228.             head = current.link;
  229.             current = head;
  230.         }
  231.         else{
  232.             System.out.println("Deleting with uninitialized current or any empty " + "list.");
  233.             System.exit(0);
  234.         }
  235.     }
  236.    
  237.     private class ListNode{
  238.        
  239.         private String data;
  240.         private ListNode link;
  241.        
  242.         public ListNode(){
  243.             link = null;
  244.             data = null;
  245.         }
  246.        
  247.         public ListNode(String newData, ListNode linkValue){
  248.             data = newData;
  249.             link = linkValue;
  250.         }
  251.        
  252.         //sets data into a node
  253.         public void setData(String newData){
  254.             data = newData;
  255.         }
  256.        
  257.         // gets data in a node
  258.         public String getData(){
  259.             return data;
  260.         }
  261.        
  262.         //connects a node to another node
  263.         public void setLink(ListNode newLink){
  264.             link = newLink;
  265.         }
  266.        
  267.         //gets the next node
  268.         public ListNode getLink(){
  269.             return link;
  270.         }
  271.        
  272.     }
  273.    
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement