Question

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 = reader.readLine();
town=line;
line = reader.readLine();
state=line;
line = reader.readLine();
listOFCodes.addTOList(new zipcodes(code,town,state));
}
reader.close();
   } catch (IOException e) {
e.printStackTrace();
}
while(true)
{
System.out.print("Enter zipcode to find or -1 to exit: ");
code=input.nextInt();
if(code==-1)
break;
else
{
listOFCodes.searchZipCode(code);
System.out.print(" ");
}
}
}
  
}
zipcodes.java


package zipcodesproject;

public class zipcodes {
private int zipcode;
private String town,state;

public zipcodes() {
}

public zipcodes(int zipcode, String town, String state) {
this.zipcode = zipcode;
this.town = town;
this.state = state;
}

public void setZipcode(int zipcode) {
this.zipcode = zipcode;
}

public void setTown(String town) {
this.town = town;
}

public void setState(String state) {
this.state = state;
}

public int getZipcode() {
return zipcode;
}

public String getTown() {
return town;
}

public String getState() {
return state;
}

@Override
public String toString() {
return "Zipcode=" + zipcode + ", Town=" + town + ", State=" + state ;
}

}
ziplist.java


package zipcodesproject;

import java.util.ArrayList;

public class ziplist {
private ArrayList<zipcodes>zipCodeList=new ArrayList<>();
  
public ziplist() {
}
void addTOList(zipcodes zipObject)
{
this.zipCodeList.add(zipObject);
}
void searchZipCode(int code)
{
for(int i=0;i<this.zipCodeList.size();i++)
{
if(zipCodeList.get(i).getZipcode()==code)
{
System.out.println(zipCodeList.get(i));
return;
}
}
System.out.println(" The zip code was not found.");
}
}
output

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

Here is the commented code with UML diagram for this problem. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Zipcodesproject.java

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) {

                           // 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(

                                                                     "C:\Users\Jay\Desktop\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 zipcode 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(" ");

                                         }

                           }

              }

}

// 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;

              }

              /**

              * setter for state

              *

              * @param state

              *            new state name

              */

              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;

              }

}

// ziplist.java

import java.util.ArrayList;

/**

* class to represent a list of zip codes

*/

public class ziplist {

              //list to store all zipcodes

              private ArrayList<zipcodes> zipCodeList ;

              /**

              * default constructor

              */

              public ziplist() {

                           //initializing list

                           zipCodeList = new ArrayList<zipcodes>();

              }

             

              /**

              * method to add a zipcode to list

              */

              void addTOList(zipcodes zipObject) {

                           this.zipCodeList.add(zipObject);

              }

              /**

              * method to search for a zip code and displays it if found

              */

              void searchZipCode(int code) {

                           for (int i = 0; i < this.zipCodeList.size(); i++) {

                                         if (zipCodeList.get(i).getZipcode() == code) {

                                                       System.out.println(zipCodeList.get(i));

                                                       return;

                                         }

                           }

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

              }

}

/*UML diagram*/


Add a comment
Know the answer?
Add Answer to:
I need help with adding comments to my code and I need a uml diagram for...
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
  • 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...

  • The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket....

    The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient {       private static final String SERVER = "dict.org";    private static final int PORT = 2628;    private static final int TIMEOUT = 15000;    public static void main(String[] args) {        Socket   ...

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • Please help me fix my errors. I would like to read and write the text file...

    Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList {    Node head;    class Node    {        int data;        Node next;       Node(int d)        {            data = d;            next = null;        }    }    void printMiddle()    {        Node slow_ptr...

  • Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895...

    Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895    {        public static void header()        {            System.out.println("\tWelcome to St. Joseph's College");        }        public static void main(String[] args) {            Scanner input = new Scanner(System.in);            int d;            header();            System.out.println("Enter number of items to process");            d = input.nextInt();      ...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

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