Question

Hey I really need some help asap!!!! I have to take the node class that is...

Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input and output and more. The uml diagram and summary are most important! Thank you very much, and have a good day. Your help is appreciated.

My project just asks a user for a zipcode then prints the zipcode and it's town and state. Here's the file format for zipcodes.txt if u need it:

Here's how my report has to be:

Assignment Analysis and Design

In your own words, describe the problem including input and output. Briefly describe how you developed your code. Briefly describe what your code does and how it works – including anything different or unique or special that you did in your software. If the software is long or complicated, describe how it is organized.

Include a copy of any pseudocode or other design documents you used. If you worked with anyone else, asked anyone for help, or looked anything up, then mention it here. include proper references to source material.

Assignment Code

Include the code for your assignment Unless otherwise directed by the assignment or by your instructor, that will be a zipped copy of your NetBeans project attached to the report.

You can put the report and the NetBeans project all in one zipped folder. In the report, either tell the reader that it is attached file or include the code.

A zipped folder may contain another zipped folder. You can copy the zipped folder for your NetBeans project and your lab report into a folder for your assignment, then zip the assignment folder.

Assignment Testing

Describe how you tested this program to verify that it runs correctly.

Assignment Evaluation

Briefly describe what you learned from this project. What things did you struggle with? what was easy? Give your opinions of the process, including what you liked about the project and any suggestions you have for improving the project.

Here's how the format of the zipcodes.txt that was used for the project:

08001
Alloway
Salem County
08002
Cherry Hill
Camden County
08003
Cherry Hill
Camden County
08004
Atco
Camden County
08005

and so on for a lot of zip codes and properties.

Here's my code:

package LinkedListProject;
import java.util.Scanner;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class linkedListProject {


public static void main(String[] args) {

// creating a scanner to read user input from keyboard
Scanner input = new Scanner(System.in);

// creating a BufferedReader to read input file
    BufferedReader reader;

int code;

String state, town;

// creating an empty ziplist to store zip codes from file

ziplist listOFCodes = new ziplist();

// trying to open the file

try{
    reader = new BufferedReader(new FileReader("zipcodes.txt"));

// reading a line

    String line = reader.readLine();

// checking in loop if line has been read successfully

while (line != null) {

// converting line to integer, using as zip code

    code = Integer.parseInt(line);

// reading next line, using as town

    line = reader.readLine();

    town = line;

// reading next line, using as state

    line = reader.readLine();

    state = line;

// reading next line for the next loop

    line = reader.readLine();

// creating a zipcodes object and adding to the ziplist object

    listOFCodes.addTOList(new zipcodes(code, town, state));

}

//closing file reader

    reader.close();

}   catch (IOException e) {

//exception occurred, file not found

e.printStackTrace();

}

//looping indefinitely

while (true) {

//asking user for a zipcode

    System.out.print("Enter the ZIPCODE you want to find or STOP to exit: ");

//getting zip code

    code = input.nextInt();

//checking if zip code is sentinel value

if (code == -1)

    break; //end of loop

    else {

    //searching zipcode and displaying results

    listOFCodes.searchZipCode(code);

    System.out.print(" ");

}

}

}

}

//zipcode.java

package LinkedListProject;

// zipcodes.java

//class to represent a zipcode

public class zipcodes {

    // variable for storing zipcode

    private int zipcode;

    // variable for storing town and state

    private String town, state;

    /**

    * default constructor doing nothing

    */

    public zipcodes() {

    }

    /**

    * parameterized constructor taking initial values for zipcode,town and

    * state

    *

    * @param zipcode

    *            integer zip code

    * @param town

    *            town name

    * @param state

    *            state name

    */

    public zipcodes(int zipcode, String town, String state) {

        this.zipcode = zipcode;

        this.town = town;

        this.state = state;

    }

        /**

        * setter for zipcode

        *

        * @param zipcode

        *            new zip code

        */

    public void setZipcode(int zipcode) {

    this.zipcode = zipcode;

    }

        /**

        * setter for town

        *

        * @param town

        *            new town name

        */

    public void setTown(String town) {

        this.town = town;

    }

    public void setState(String state) {

        this.state = state;

    }

        /**

        * returns the zipcode
     * @return
        */

    public int getZipcode() {

        return zipcode;

    }

        /**

        * returns the town name
     * @return
        */

    public String getTown() {

        return town;

    }

    /**

    * returns the state name
     * @return
    */

    public String getState() {

        return state;

    }

    /**

    * returns a string containing all info
     * @return
    */

    @Override

    public String toString() {

     return "Zipcode=" + zipcode + ", Town=" + town + ", State=" + state;

    }

    }

//ziplist.java

package LinkedListProject;
// ziplist.java

/**

* class to represent a list of zip codes

*/

public class ziplist {
    // Class variables for the Linked List
    private static ListNode head;
    private static int totalNodes;

   // constructor with no args that initialise things
    public ziplist() {
        head = null;
        totalNodes = 0;
    }

   public ziplist(zipcodes code) {
        head = new ListNode(code);
    }

   public static int getSize() {
        return totalNodes;
    }

   public void addTOList(zipcodes zipcodes) {
        // Check if the list is empty
        if (head == null) {
            head = new ListNode(zipcodes);
            totalNodes++;
        }

       ListNode tmp = new ListNode(zipcodes);
        ListNode currentNode = head;

       if (currentNode != null) {

           // starting at the head node to the end. Add the new element after last node
            while (currentNode.next != null) {
                currentNode = currentNode.next;
            }

           // Now update the reference for the last node to new node
            currentNode.next = tmp;
            totalNodes++;
        }
    }

   //looks for the specific zipcode in the list and returns the result accordingly
    public void searchZipCode(int code) {
        System.out.println("Find code: " + code);
        ListNode t = head;

       for (int i = 0; i < totalNodes; i++) {
            if (t.data.getZipcode() == code) {
                System.out.println(t.data);
                return;
            } else {
                t = t.next;
            }
        }
        System.out.println(" The zip code was not found.");
    }
class ListNode {
        // Declare class variables
        private ListNode next;
        private zipcodes data;

       public ListNode(zipcodes zipcodes) {
            data = zipcodes;
        }

       public Object getData() {
            return data;
        }
    }
}

//////////////////////////////////////////End zipList.java/////////////////////////////////////////////////////////////////


  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Assignment Analysis and Design

In this problem, we designed a system to store and retrieve information about zip codes using object oriented programming. We were given a text file in specific format which contains the information about zip codes, the corresponding state and town. So the first thing to be designed was a class representing a single record of a zip code- namely a class to store a zip code, state name and town name. For that we implemented the zipcodes class with proper constructor, getters and setters. Next, we needed a system to manage a collection of zipcodes. For that we designed a ziplist class that manages the database of zipcodes in linked list representation. In addition to constructors, getters and setters, some important methods are implemented- one to add a zipcode to the collection, at the end of the list, another to search for a zipcode and display the results. A method to return the size of the list is also implemented. Each record in the linked list is represented by a ListNode class which stores the zipcodes object, and the pointer to the next node. Finally we implemented a linkedListProject.java class which opens a text file containing zip code data, creates a ziplist from it, prompts the user to search for a zip, display the results, and continue this process until user chooses to quit. In addition to the input file which contains the records in format <integer zip code> <town name> <state name>, numeric inputs are received from the user which represents a zip code to be searched.

Assignment Code

Provided at the end of this solution , with UML diagram

Assignment Testing

The system is tested with the given input file in specified format and valid integer inputs, and verified that everything is working fine as long as the inputs are valid. If the input file is in invalid format/not found or if the input zip code is not a valid integer, the system fails as there is no exception handling mechanism set up.

Assignment Evaluation

The system design and implementation helped to learn more about File Input and Output, Console Input and Output and most importantly, linked list representation of objects and their manipulation involving searching for an object in the entire list. The suggestion is to implement exception handling mechanism to make the program robust and more efficient, also to add more functionalities for the ziplist class in future (to remove a zipcode, update details of existing zipcodes etc).

Completed code is given below, make sure you put them in separate files

//start of linkedListProject.java

package LinkedListProject;

import java.util.Scanner;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class linkedListProject {

              public static void main(String[] args) {

                           // creating a scanner to read user input from keyboard

                           Scanner input = new Scanner(System.in);

                           // creating a BufferedReader to read input file

                           BufferedReader reader;

                           int code;

                           String state, town;

                           // creating an empty ziplist to store zip codes from file

                           ziplist listOFCodes = new ziplist();

                           // trying to open the file

                           try {

                                         reader = new BufferedReader(new FileReader("zipcodes.txt"));

                                         // reading a line

                                         String line = reader.readLine();

                                         // checking in loop if line has been read successfully

                                         while (line != null) {

                                                       // converting line to integer, using as zip code

                                                       code = Integer.parseInt(line);

                                                       // reading next line, using as town

                                                       line = reader.readLine();

                                                       town = line;

                                                       // reading next line, using as state

                                                       line = reader.readLine();

                                                       state = line;

                                                       // reading next line for the next loop

                                                       line = reader.readLine();

                                                       // creating a zipcodes object and adding to the ziplist object

                                                       listOFCodes.addTOList(new zipcodes(code, town, state));

                                         }

                                         // closing file reader

                                         reader.close();

                           } catch (IOException e) {

                                         // exception occurred, file not found

                                         e.printStackTrace();

                           }

                           // looping indefinitely

                           while (true) {

                                         // asking user for a zipcode

                                         System.out

                                                                    .print("Enter the ZIPCODE you want to find or -1 to exit: ");

                                         // getting zip code

                                         code = input.nextInt();

                                         // checking if zip code is sentinel value

                                         if (code == -1)

                                                       break; // end of loop

                                         else {

                                                       // searching zipcode and displaying results

                                                       listOFCodes.searchZipCode(code);

                                                       System.out.print(" ");

                                         }

                           }

              }

}

//end of linkedListProject.java

// Start of ziplist.java

package LinkedListProject;

/**

* class to represent a list of zip codes

*/

public class ziplist {

              // Class variables for the Linked List

              private static ListNode head;

              private static int totalNodes;

              // constructor with no args that initialise things

              public ziplist() {

                           head = null;

                           totalNodes = 0;

              }

              public ziplist(zipcodes code) {

                           head = new ListNode(code);

              }

              public static int getSize() {

                           return totalNodes;

              }

              public void addTOList(zipcodes zipcodes) {

                           // Check if the list is empty

                           if (head == null) {

                                         head = new ListNode(zipcodes);

                                         totalNodes++;

                           }

                           ListNode tmp = new ListNode(zipcodes);

                           ListNode currentNode = head;

                           if (currentNode != null) {

                                         // starting at the head node to the end. Add the new element after

                                         // last node

                                         while (currentNode.getNext() != null) {

                                                       currentNode = currentNode.getNext();

                                         }

                                         // Now update the reference for the last node to new node

                                         currentNode.setNext(tmp);

                                         totalNodes++;

                           }

              }

              // looks for the specific zipcode in the list and returns the result

              // accordingly

              public void searchZipCode(int code) {

                           System.out.println("Find code: " + code);

                           ListNode t = head;

                           for (int i = 0; i < totalNodes; i++) {

                                         if (t.getData().getZipcode() == code) {

                                                       System.out.println(t.getData());

                                                       return;

                                         } else {

                                                       t = t.getNext();

                                         }

                           }

                           System.out.println(" The zip code was not found.");

              }

}

//end of ziplist.java

// Start of zipcodes.java

package LinkedListProject;

//class to represent a zipcode

public class zipcodes {

              // variable for storing zipcode

              private int zipcode;

              // variable for storing town and state

              private String town, state;

              /**

              * default constructor doing nothing

              */

              public zipcodes() {

              }

              /**

              * parameterized constructor taking initial values for zipcode,town andstate

              *

              * @param zipcode

              *            integer zip code

              * @param town

              *            town name

              * @param state

              *            state name

              */

              public zipcodes(int zipcode, String town, String state) {

                           this.zipcode = zipcode;

                           this.town = town;

                           this.state = state;

              }

              /**

              * @param zipcode

              *            new zip code

              */

              public void setZipcode(int zipcode) {

                           this.zipcode = zipcode;

              }

              /**

              * setter for town

              *

              * @param town

              *            new town name

              */

              public void setTown(String town) {

                           this.town = town;

              }

              public void setState(String state) {

                           this.state = state;

              }

              /**

              * returns the zipcode

              */

              public int getZipcode() {

                           return zipcode;

              }

              /**

              * returns the town name

              */

              public String getTown() {

                           return town;

              }

              /**

              * returns the state name

              */

              public String getState() {

                           return state;

              }

              /**

              * returns a string containing all info

              */

              @Override

              public String toString() {

                           return "Zipcode=" + zipcode + ", Town=" + town + ", State=" + state;

              }

}

// End of zipcodes.java

//Start of ListNode.java

package LinkedListProject;

class ListNode {

              // Declare class variables

              private ListNode next;

              private zipcodes data;

              public ListNode(zipcodes zipcodes) {

                           data = zipcodes;

                           next = null;

              }

              // required getters and setters

              public zipcodes getData() {

                           return data;

              }

              public void setNext(ListNode next) {

                           this.next = next;

              }

              public ListNode getNext() {

                           return next;

              }

}

//End of ListNode.java

/*OUTPUT*/

Enter the ZIPCODE you want to find or -1 to exit: 08001

Find code: 8001

Zipcode=8001, Town=Alloway, State=Salem County

Enter the ZIPCODE you want to find or -1 to exit: 08004

Find code: 8004

Zipcode=8004, Town=Atco, State=Camden County

Enter the ZIPCODE you want to find or -1 to exit: 01234

Find code: 1234

The zip code was not found.

Enter the ZIPCODE you want to find or -1 to exit: -1

/*UML*/

Add a comment
Know the answer?
Add Answer to:
Hey I really need some help asap!!!! I have to take the node class that is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • I need help with todo line please public class LinkedList { private Node head; public LinkedList()...

    I need help with todo line please public class LinkedList { private Node head; public LinkedList() { head = null; } public boolean isEmpty() { return head == null; } public int size() { int count = 0; Node current = head; while (current != null) { count++; current = current.getNext(); } return count; } public void add(int data) { Node newNode = new Node(data); newNode.setNext(head); head = newNode; } public void append(int data) { Node newNode = new Node(data);...

  • In C++, for the provided template linked list class create a derived class of it which...

    In C++, for the provided template linked list class create a derived class of it which adds the functionality to it to find the high and low value of any given data stored in the list. The derived class must be a template. LinkedList.h #pragma once #include <iostream> using namespace std; template <class T> class ListNode {    public:        T data;        ListNode<T>* next;        ListNode(T data)        {            this->data = data;...

  • Java - I need help creating a method that removes a node at the specific index...

    Java - I need help creating a method that removes a node at the specific index position. The * first node is index 0. public boolean delAt(int index) { src code 2 different classes ******************************************** public class Node { private String data; private Node next; public Node(String data, Node next) { this.data = data; this.next = next; } public Node() { } public String getData() { return data; } public void setData(String data) { this.data = data; } public void...

  • Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element...

    Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element stored at this node */ private int element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n...

  • Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the...

    Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...

  • This Individual Assignment is a set of three problems. The first is a recursion "warm up"...

    This Individual Assignment is a set of three problems. The first is a recursion "warm up" exercise, and the second two are QuickSort variations. The "warm up" should be implemented as a static method in your main App class and the second two will use additional classes (as instructed below). All three problems should be included in the same NetBeans project (exported to ZIP as usual). ----------------- All of your classes should be properly encapsulated, follow all proper coding conventions...

  • Complete the implementation of the method replace: public class SinglyLinkedList private Node head, public SinglyLinkedListo this(null) public SinglyLinkedList(Node head) [ this.head -head public Nod...

    Complete the implementation of the method replace: public class SinglyLinkedList private Node head, public SinglyLinkedListo this(null) public SinglyLinkedList(Node head) [ this.head -head public Node getHeado return head public void setHead(Node head) [ head: this. head Method that creates a Node containing 'item' @param item Value to be added this.headnew Node(item, this.head) * and adds it as the first element in the list *I public void add(int item) Method that finds the node at the given index d replaces its value...

  • public class myLinkedList<E extends Comparable<E>>{       private Node<E> head = null;                    private Node<E>...

    public class myLinkedList<E extends Comparable<E>>{       private Node<E> head = null;                    private Node<E> tail = null;                       public myLinkedList() {        head = null;       } public void concatenateList (myLinkedList<E> M) {//attach another linkedList refered by M to the end of this linkedList       }          public int searchElement (E targetElement){//test if a target element can be found on the list, return the occurrences of the target element         ...

  • We have written the following Node class: class Node { // instance variables private int value;...

    We have written the following Node class: class Node { // instance variables private int value; private Node next; // constructor public Node(int value) { this.value = value; } // get the 'next' variable public Node getNext() { return this.next; } // get the 'value' variable public int getValue() { return this.value; } // set the 'next' variable public void setNext(Node next) { this.next = next; } } TASK: Create a class called List that has the following properties: It...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT