Hey guys! Huge part of my grade !! My code works already but I need it so it references to my node list class instead of my array, what would I need to change? My assignment was to create a list from an assignment when we used an array, but I cant make it to work without the array, help! The professor said it was okay to either keep the array or to delete it altogether.
package zipcode;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ZipCodeDriver {
public static void main(String[] args) {
//file contening the data that will be loaded into the array
String filename = "zipcodes.txt";
// Load data
try {
Scanner infile = new Scanner(new File(filename));
ZipCodeList list = new ZipCodeList();
ZipCode c;
while(infile.hasNext()){
c = new ZipCode();
c.setZipcode(infile.nextLine());
c.setTown(infile.nextLine());
c.setState(infile.nextLine());
list.add(c);
}
infile.close();
System.out.println("Loaded " + list.getSize() + " zip
codes");
// Search for the data
String search = "";
Scanner keyboard = new Scanner(System.in);
while(true){
System.out.print("Hello, please enter zip code to search (type done
to stop): ");
search = keyboard.next();
if(search.equalsIgnoreCase("done"))
break;
c = list.find(search);
if(c == null)
System.out.println("Sorry but the zip code entered was not
found");
else
System.out.println("Found " + search + ": [" + c + "]");
}
// In case we don''t find the data
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
}
--
package zipcode;
public class ZipCode {
//add components
private String zipcode;
private String town;
private String state;
//add constructors
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String toString(){
return "ZipCode: " + zipcode + ", Town: " + town + ", State: " +
state;
}
}
--
package zipcode;
public class ZipCodeList {
// Add components; The limit of the size, the array holding the
data and a counter
private static int MAX_LIST_SIZE = 1000;
private ZipCode[] zipcodes;
private int count;
//counter
public ZipCodeList(){
zipcodes = new ZipCode[MAX_LIST_SIZE];
count = 0;
}
//Limit of the array
public void add(ZipCode c){
if(count == MAX_LIST_SIZE){
System.out.println("Could not add " + c);
}
else{
zipcodes[count++] = c;
}
}
//find the zipcode
public ZipCode find(String code){
for(int i = 0; i < count; i++){
if(zipcodes[i].getZipcode().equals(code))
return zipcodes[i];
}
// not found
return null;
}
//find size
public int getSize(){
return count;
}
}
-- And the last class which is the one I need to use on my list
public class ZipCodeListNode {
public ZipCode data;
public ZipCodeListNode next;
public ZipCodeListNode(ZipCode data, ZipCodeListNode next) {
this.data = data;
this.next = next;
}
public ZipCodeListNode(ZipCode data) {
this.data = data;
}
}
class ZipCodeList1 {
private int count;
private ZipCodeListNode head;
public ZipCodeList1() {
head = null;
count = 0;
}
public void add(ZipCode c) {
head = new ZipCodeListNode(c, head);
count++;
}
public ZipCode find(String code) {
ZipCodeListNode start = head;
while(start != null) {
if(start.data.getZipcode().equals(code)) {
return start.data;
}
start = start.next;
}
return null; // not found
}
public int getSize() {
return count;
}
}
Please find the below class modified to reference the node created. And let me know if you need further clarification on this.
ZipCodeDriver Class:
package zipcode;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ZipCodeDriver {
public static void main(String[] args) {
// file contening the data that
will be loaded into the array
String filename =
"zipcodes.txt";
System.out.println(filename);
// Load data
try {
Scanner infile =
new Scanner(new File(filename));
/*Create new
object myZipCodeList of type ZipCodeList1,
* copy the
Zipcode object c which was created and assigned with
zipcode,town,state.
and use the add
method of class ZipCodeList1 and add ZipCode c to the ZipCodeList1
myZipCodeList.
Rest of things
are implemented earlier.*/
ZipCodeList1 myZipCodeList = new
ZipCodeList1();
ZipCode c;
while
(infile.hasNext()) {
c = new ZipCode();
c.setZipcode(infile.nextLine());
c.setTown(infile.nextLine());
c.setState(infile.nextLine());
myZipCodeList.add(c);
}
infile.close();
System.out.println("Loaded " + myZipCodeList.getSize() + "
zip codes");
// Search for
the data
String search =
"";
Scanner keyboard
= new Scanner(System.in);
while (true)
{
System.out.print("Hello, please enter zip code
to search (type done to stop): ");
search = keyboard.next();
if (search.equalsIgnoreCase("done"))
break;
c =
myZipCodeList.find(search);
if (c == null)
System.out.println("Sorry but
the zip code entered was not found");
else
System.out.println("Found " +
search + ": [" + c + "]");
}
// In case we
don''t find the data
} catch (FileNotFoundException e)
{
System.out.println(e.getMessage());
}
}
}
ZipCode Class:
package zipcode;
public class ZipCode {
// add components
private String zipcode;
private String town;
private String state;
// add constructors
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String toString() {
return "ZipCode: " + zipcode + ",
Town: " + town + ", State: " + state;
}
}
ZipCodeListNode Class:
package zipcode;
public class ZipCodeListNode {
public ZipCode data;
public ZipCodeListNode next;
public ZipCodeListNode() {
}
public ZipCodeListNode(ZipCode data) {
this.data = data;
}
public ZipCodeListNode(ZipCode data,
ZipCodeListNode next) {
this.data = data;
this.next = next;
}
}
class ZipCodeList1 {
private int count;
private ZipCodeListNode head;
public ZipCodeList1() {
head = null;
count = 0;
}
public void add(ZipCode c) {
head = new ZipCodeListNode(c,
head);
count++;
}
public ZipCode find(String code) {
ZipCodeListNode start = head;
while (start != null) {
if
(start.data.getZipcode().equals(code)) {
return start.data;
}
start =
start.next;
}
return null; // not found
}
public int getSize() {
return count;
}
public ZipCode getZipcode(){
return this.getZipcode();
}
}
ZipCodeList Class:
package zipcode;
public class ZipCodeList {
// Add components; The limit of the size, the array
holding the data and a
// counter
private static int MAX_LIST_SIZE = 1000;
private ZipCode[] zipcodes;
private int count;
// counter
public ZipCodeList() {
zipcodes = new
ZipCode[MAX_LIST_SIZE];
count = 0;
}
// Limit of the array
public void add(ZipCode c) {
if (count == MAX_LIST_SIZE) {
System.out.println("Could not add " + c);
} else {
zipcodes[count++] = c;
}
}
// find the zipcode
public ZipCode find(String code) {
for (int i = 0; i < count; i++)
{
if
(zipcodes[i].getZipcode().equals(code))
return zipcodes[i];
}
// not found
return null;
}
// find size
public int getSize() {
return count;
}
}
Follow the image for the changes made in ZipCodeDriver

Compare the changes made(left side red color) and previous(right side green color)

Sample input:
560036
Chennai
Tamil Nadu
560034
Bangalore
Karnataka
Output:
Loaded 2 zip codes
Hello, please enter zip code to search (type done to stop):
560036
Found 560036: [ZipCode: 560036, Town: Chennai, State: Tamil
Nadu]
Hello, please enter zip code to search (type done to stop):
560034
Found 560034: [ZipCode: 560034, Town: Bangalore, State:
Karnataka]
Hello, please enter zip code to search (type done to stop):
10001
Sorry but the zip code entered was not found
Hello, please enter zip code to search (type done to stop):
done
Please rate the solution , your rating is precious and valuable.
Hey guys! Huge part of my grade !! My code works already but I need it...
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 =...
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...
Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...
(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 to code the HeapSort Algorithm in java. Most of the code is already done just need to code the "heapify" part of the heapsort algorithm. My heapify code is in bold below called "sink", but when I run it it gives me 2 errors with the string compare part saying: WordCountHeap.java:61: error: cannot find symbol if(l < k && String.Compare(pq[l], pq[n]) < 0) ^ symbol: method Compare(String,String) location: class String Please fix the code and the "heapify"...
Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...
Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...
Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
What is wrong with my code, when I pass in 4 It will not run, without the 4 it will run, but throw and error. I am getting the error required: no arguments found: int reason: actual and formal argument lists differ in length where T is a type-variable: T extends Object declared in class LinkedDropOutStack public class Help { /** * Program entry point for drop-out stack testing. * @param args Argument list. */ public static void main(String[] args)...