Results 1 to 2 of 2

Thread: JAVA -- updated code

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    JAVA -- updated code

    i get cant find symbol errors on print(), meesage dialog, length(), and is empty

    any help would be appriciated

    Daren


    import java.io.*;
    import javax.swing.JOptionPane;
    import java.util.*;
    import java.lang. *;

    class DistancebetweenCities //make the class
    {
    private Queue qCities = new Queue();
    private City aCity ;
    private double totalDistance;
    private int length;
    private double distance;
    private double total;

    public void addCity()
    {
    // String msg = JOptionPane.showMessageDialog("Welcome to the city distance finder.");
    String strC = JOptionPane.showInputDialog(null, "Please let us know how many cities you wish to enter.");
    double coordx;
    double coordy;
    int qty = Integer.parseInt(strC);


    for (int i = 1; i <= qty; i++)
    {
    strC = JOptionPane.showInputDialog(null, "Please enter a city name:\n", "", 1);
    double cox = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the X Coordinate:\n", "" ,1));
    double coy = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the Y Coordinate:\n", "" ,1));

    qCities.enqueue(new City(strC, cox, coy));
    }
    length = qCities.length();
    }


    public void printCity()
    {
    while(!qCities.isEmpty)
    {
    aCity = (City)qCities.dequeue();
    aCity.Print();
    }
    }
    public String Print()
    {
    JOptionPane.showMessageDialog(null,"The distance is:/n" ,aCity +" " + distance);
    }


    public void getDistance()
    {
    if(qCities.isEmpty())
    {
    aCity = (City)qCities.dequeue();
    totalDistance += aCity.distance;
    aCity.Print();

    // distance = Math.sqrt((cox-cox)*(endX-startX) + (endY-startY)*(endY-startY));

    getDistance();
    }
    else
    // distance = Math.sqrt((cox-cox)*(endX-startX) + (endY-startY)*(endY-startY));
    JOptionPane.showMessageDialog(null,"The total distance is:/n" , totalDistance);

    }





    public void run()
    {
    while(true)
    {

    String msg = "Pleasechoose an option/n"+
    " 1 to enter city names/n"+
    " 2 to exit/n"+
    " Your chose: ";

    String thePick = JOptionPane.showInputDialog(null, msg, "" , 1);

    int choice = Integer.parseInt(thePick);

    switch(choice)
    {
    case 1:
    addCity();

    getDistance();
    break;

    case 2:
    return;
    }
    }

    }


    }//end class

    class City //make the class
    {
    public double coxa, coya;
    public double distance;
    public String cityx;


    public City()
    {
    }
    public City(String c, double i, double j)
    {
    cityx = c;
    coxa = i; coya = j;


    }
    public boolean equals(Object node)
    {
    return cityx.equals(((City)node).cityx);
    }
    public String toString()
    {
    return cityx + " = " + coxa + " " + coya;
    }

    }//end class

    public class Queue implements aQueue //make the class
    {
    private java.util.LinkedList cList = new java.util.LinkedList();
    public Queue()
    {
    } public void clear()
    {

    cList.clear();
    }
    public boolean isEmpty()
    {

    return cList.isEmpty();
    }
    public Object firstC()
    {
    return cList.getFirst();
    }
    public Object dequeue()
    {
    return cList.removeFirst();
    }
    public void enqueue(Object C)
    {
    cList.addLast(C);
    }
    public String toString()
    {
    return cList.toString();
    }

    }//end class


    public interface aQueue
    {
    public void clear();
    public void enqueue(Object el);
    public Object dequeue();
    public Object firstC();
    public boolean isEmpty();
    } //end

  2. #2
    Join Date
    Jan 2006
    Posts
    211

    Re: JAVA -- updated code

    This code is little confusing one as there are two classes where where curly braces you left blank, proper formatting for code makes it very difficult to find the problem, so I am suggesting that just provide the code where you are facing problem. I will keep above code for reference or else you may check for the correction of the above code at sun.java that may help you.

Similar Threads

  1. Replies: 1
    Last Post: 28-08-2012, 06:37 PM
  2. help me to understand java code (calendar java code) ?
    By so0oma in forum Software Development
    Replies: 2
    Last Post: 10-01-2011, 12:01 AM
  3. UPDATED: X360 Online Pass; Code Invalid or In Use.
    By Flamingo-R in forum Video Games
    Replies: 4
    Last Post: 22-10-2010, 03:44 AM
  4. updated code JAVA cant get it to erase now
    By Daren in forum Software Development
    Replies: 5
    Last Post: 30-05-2009, 01:07 AM
  5. Sun Java JRE 6 Update 14 updated with Win 7 compatibility
    By Erubiel in forum Windows x64 Edition
    Replies: 2
    Last Post: 29-05-2009, 07:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,032,073.33439 seconds with 16 queries