Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: I cant work it out!!!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I cant work it out!!!

    Can anyone please tell me why this code is not working?? plz would be much appriciated

    Suggestions to fix by netbeans are:
    cannot find symbol
    symbol: class Location
    location: class javaapplication10.Stations

    cannot find symbol
    symbol: class Line
    location: class javaapplication10.Stations



    ********************
    package javaapplication10;
    import javax.swing.*;
    /**
    *
    *
    */
    public class Stations {

    public static void main(String[] args) {

    // declairing variables
    double tempBearing;
    double tempLength;
    double distanceToClosest;
    double distanceToClosestDest;
    double tempBearingDest;
    double tempLengthDest;


    //an array of stations
    Station[] stations = new Station[16];

    //populate the array with stations and values
    stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
    stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
    stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
    stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
    stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
    stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
    stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
    stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
    stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
    stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
    stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
    stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
    stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
    stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
    stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
    stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));

    //To get users current bearings and and locations and creating objects

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Be aring to current location?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLength = Double.parseDouble(JOptionPane.showInputDialog("di stance from origin of current?"));

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Be aring to Destination?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("di stance to end Destination?"));


    Location current = new Location(tempBearing, tempLength);

    Station closest = stations[0];
    distanceToClosest = current.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = current.calcDistance(stations[i].location);

    if(tempDist < distanceToClosest){
    closest = stations[i];
    distanceToClosest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop


    //2nd loop for end destination
    Location currentDest = new Location(tempBearingDest, tempLengthDest);

    Station closestDest = stations[0];
    distanceToClosestDest = currentDest.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = currentDest.calcDistance(stations[i].location);

    if(tempDist < distanceToClosestDest){
    closestDest = stations[i];
    distanceToClosestDest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop



    JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
    + "\nIt is " + distanceToClosest + " away.");

    JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
    + "\nIt is " + distanceToClosestDest + " away.");

    }

    }

    class Station{ // a station class

    Location location;
    String name;
    Line line;

    public Station(String n, Location l, Line r){
    name = n;
    location = l;
    line = r;
    }
    class Line {
    String lname;
    public Line (String String) {
    lname = String;
    }

    }//class station

    class Location{
    double bearing;
    double length;

    public Location(){
    bearing = 0.0;
    length = 0.0;
    }

    public Location(double b, double l){
    bearing = b;
    length = l;
    }

    public double calcDistance(Location l){
    double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
    double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)) );
    return Math.pow(temp, 0.5);



    }

    }

    }


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: I cant work it out!!!

    I am going to have a very difficult time helping you due to the way you posted your code.

    Please surround code with

    [highlight=Java]
    //your code here
    [/highlight]


    That way I can better understand and help you.

    The first thing that comes to mind is that maybe you haven't imported the Location and Line classes? Are these classes you have written, or classes that already exist?
    Last edited by snowguy13; January 11th, 2012 at 02:39 PM.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    did you mean

    package javaapplication10;
    import javax.swing.*;
    /**
    *
    *
    */
    public class Stations {

    public static void main(String[] args) {

    // declairing variables
    double tempBearing;
    double tempLength;
    double distanceToClosest;
    double distanceToClosestDest;
    double tempBearingDest;
    double tempLengthDest;


    //an array of stations
    Station[] stations = new Station[16];

    //populate the array with stations and values
    stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
    stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
    stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
    stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
    stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
    stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
    stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
    stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
    stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
    stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
    stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
    stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
    stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
    stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
    stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
    stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));

    //To get users current bearings and and locations and creating objects

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Be aring to current location?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLength = Double.parseDouble(JOptionPane.showInputDialog("di stance from origin of current?"));

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Be aring to Destination?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("di stance to end Destination?"));


    Location current = new Location(tempBearing, tempLength);

    Station closest = stations[0];
    distanceToClosest = current.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = current.calcDistance(stations[i].location);

    if(tempDist < distanceToClosest){
    closest = stations[i];
    distanceToClosest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop


    //2nd loop for end destination
    Location currentDest = new Location(tempBearingDest, tempLengthDest);

    Station closestDest = stations[0];
    distanceToClosestDest = currentDest.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = currentDest.calcDistance(stations[i].location);

    if(tempDist < distanceToClosestDest){
    closestDest = stations[i];
    distanceToClosestDest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop



    JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
    + "\nIt is " + distanceToClosest + " away.");

    JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
    + "\nIt is " + distanceToClosestDest + " away.");

    }

    }

    class Station{ // a station class

    Location location;
    String name;
    Line line;

    public Station(String n, Location l, Line r){
    name = n;
    location = l;
    line = r;
    }
    class Line {
    String lname;
    public Line (String String) {
    lname = String;
    }

    }//class station

    class Location{
    double bearing;
    double length;

    public Location(){
    bearing = 0.0;
    length = 0.0;
    }

    public Location(double b, double l){
    bearing = b;
    length = l;
    }

    public double calcDistance(Location l){
    double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
    double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)) );
    return Math.pow(temp, 0.5);



    }

    }

    }

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    thats all my code

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Where is the class: Location defined? The compiler can not find its definition.

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    Also please post the FULL text of the error message. You have left off important parts of it.
    Last edited by Norm; January 11th, 2012 at 03:31 PM.

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    package javaapplication10;
    import javax.swing.*;
    /**
    *
    *
    */
    public class Stations {

    public static void main(String[] args) {

    // declairing variables
    double tempBearing;
    double tempLength;
    double distanceToClosest;
    double distanceToClosestDest;
    double tempBearingDest;
    double tempLengthDest;


    //an array of stations
    Station[] stations = new Station[16];

    //populate the array with stations and values
    stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
    stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
    stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
    stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
    stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
    stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
    stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
    stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
    stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
    stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
    stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
    stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
    stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
    stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
    stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
    stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));

    //To get users current bearings and and locations and creating objects

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Be aring to current location?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLength = Double.parseDouble(JOptionPane.showInputDialog("di stance from origin of current?"));

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Be aring to Destination?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("di stance to end Destination?"));


    Location current = new Location(tempBearing, tempLength);

    Station closest = stations[0];
    distanceToClosest = current.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = current.calcDistance(stations[i].location);

    if(tempDist < distanceToClosest){
    closest = stations[i];
    distanceToClosest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop


    //2nd loop for end destination
    Location currentDest = new Location(tempBearingDest, tempLengthDest);

    Station closestDest = stations[0];
    distanceToClosestDest = currentDest.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = currentDest.calcDistance(stations[i].location);

    if(tempDist < distanceToClosestDest){
    closestDest = stations[i];
    distanceToClosestDest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop



    JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
    + "\nIt is " + distanceToClosest + " away.");

    JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
    + "\nIt is " + distanceToClosestDest + " away.");

    }

    }

    class Station{ // a station class

    Location location;
    String name;
    Line line;

    public Station(String n, Location l, Line r){
    name = n;
    location = l;
    line = r;
    }
    class Line {
    String lname;
    public Line (String String) {
    lname = String;
    }

    }//class station

    class Location{
    double bearing;
    double length;

    public Location(){
    bearing = 0.0;
    length = 0.0;
    }

    public Location(double b, double l){
    bearing = b;
    length = l;
    }

    public double calcDistance(Location l){
    double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
    double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)) );
    return Math.pow(temp, 0.5);



    }

    }

    }

    /code

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    Sorry i dont know what you mean like this .........

    The problem seems to be with the Location and the line

    error message in netbeans:-

    cannot find symbol
    symbol: class Location
    location: class javaapplication10.Stations

    cannot find symbol
    symbol: class Line
    location: class javaapplication10.Stations

    Sorry 4 being thick


    code=java

    package javaapplication10;
    import javax.swing.*;
    /**
    *
    *
    */
    public class Stations {

    public static void main(String[] args) {

    // declairing variables
    double tempBearing;
    double tempLength;
    double distanceToClosest;
    double distanceToClosestDest;
    double tempBearingDest;
    double tempLengthDest;


    //an array of stations
    Station[] stations = new Station[16];

    //populate the array with stations and values
    stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
    stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
    stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
    stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
    stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
    stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
    stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
    stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
    stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
    stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
    stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
    stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
    stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
    stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
    stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
    stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));

    //To get users current bearings and and locations and creating objects

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Be aring to current location?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLength = Double.parseDouble(JOptionPane.showInputDialog("di stance from origin of current?"));

    //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Be aring to Destination?"));

    //temp = JOptionPane.showInputDialog("distance from origin of current?");
    tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("di stance to end Destination?"));


    Location current = new Location(tempBearing, tempLength);

    Station closest = stations[0];
    distanceToClosest = current.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = current.calcDistance(stations[i].location);

    if(tempDist < distanceToClosest){
    closest = stations[i];
    distanceToClosest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop


    //2nd loop for end destination
    Location currentDest = new Location(tempBearingDest, tempLengthDest);

    Station closestDest = stations[0];
    distanceToClosestDest = currentDest.calcDistance(stations[0].location);

    for(int i = 1; i < stations.length; i++){
    double tempDist = currentDest.calcDistance(stations[i].location);

    if(tempDist < distanceToClosestDest){
    closestDest = stations[i];
    distanceToClosestDest = tempDist;
    }//if (tempDist < distanceToClosest)
    }//for loop



    JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
    + "\nIt is " + distanceToClosest + " away.");

    JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
    + "\nIt is " + distanceToClosestDest + " away.");

    }

    }

    class Station{ // a station class

    Location location;
    String name;
    Line line;

    public Station(String n, Location l, Line r){
    name = n;
    location = l;
    line = r;
    }
    class Line {
    String lname;
    public Line (String String) {
    lname = String;
    }

    }//class station

    class Location{
    double bearing;
    double length;

    public Location(){
    bearing = 0.0;
    length = 0.0;
    }

    public Location(double b, double l){
    bearing = b;
    length = l;
    }

    public double calcDistance(Location l){
    double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
    double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)) );
    return Math.pow(temp, 0.5);



    }

    }

    }

    /code

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    Note the [ and the ] around the word code

    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    The error message you posted leaves off the line number and the text of the source line.

  9. #9
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    1 /*
    2 * To change this template, choose Tools | Templates
    3 * and open the template in the editor.
    4 */
    5 package javaapplication10;
    6 import javax.swing.*;
    7 /**
    8 *
    9 * @author mpjames
    10 */
    11 public class Stations {
    12
    13 public static void main(String[] args) {
    14
    15 // declairing variables
    16 double tempBearing;
    17 double tempLength;
    18 double distanceToClosest;
    19 double distanceToClosestDest;
    20 double tempBearingDest;
    21 double tempLengthDest;
    22
    23
    24 //an array of stations
    25 Station[] stations = new Station[16];
    26
    27 //populate the array with stations and values
    28 stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
    29 stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
    30 stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
    31 stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
    32 stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
    33 stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
    34 stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
    35 stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
    36 stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
    37 stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
    38 stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
    39 stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
    40 stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
    41 stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
    42 stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
    43 stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));
    44
    45 //To get users current bearings and and locations and creating objects
    46
    47 //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    48 tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Be aring to current location?"));
    49
    50 //temp = JOptionPane.showInputDialog("distance from origin of current?");
    51 tempLength = Double.parseDouble(JOptionPane.showInputDialog("di stance from origin of current?"));
    52
    53 //String temp = JOptionPane.showInputDialog("Bearing to current location?");
    54 tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Be aring to Destination?"));
    55
    56 //temp = JOptionPane.showInputDialog("distance from origin of current?");
    57 tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("di stance to end Destination?"));
    58
    59
    60 Location current = new Location(tempBearing, tempLength);
    61
    62 Station closest = stations[0];
    63 distanceToClosest = current.calcDistance(stations[0].location);
    64
    65 for(int i = 1; i < stations.length; i++){
    66 double tempDist = current.calcDistance(stations[i].location);
    67
    68 if(tempDist < distanceToClosest){
    69 closest = stations[i];
    70 distanceToClosest = tempDist;
    71 }//if (tempDist < distanceToClosest)
    72 }//for loop
    73
    74
    75 //2nd loop for end destination
    76 Location currentDest = new Location(tempBearingDest, tempLengthDest);
    77
    78 Station closestDest = stations[0];
    79 distanceToClosestDest = currentDest.calcDistance(stations[0].location);
    80
    81 for(int i = 1; i < stations.length; i++){
    82 double tempDist = currentDest.calcDistance(stations[i].location);
    83
    84 if(tempDist < distanceToClosestDest){
    85 closestDest = stations[i];
    86 distanceToClosestDest = tempDist;
    87 }//if (tempDist < distanceToClosest)
    88 }//for loop
    89
    90
    91
    92 JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
    93 + "\nIt is " + distanceToClosest + " away.");
    94
    95 JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
    96 + "\nIt is " + distanceToClosestDest + " away.");
    97
    98 }
    99
    100 }
    101
    102 class Station{ // a station class
    103
    104 Location location;
    105 String name;
    106 Line line;
    107
    108 public Station(String n, Location l, Line r){
    109 name = n;
    110 location = l;
    111 line = r;
    112 }
    113 class Line {
    114 String lname;
    115 public Line (String String) {
    116 lname = String;
    117 }
    118
    119 }//class station
    120
    121 class Location{
    122 double bearing;
    123 double length;
    124
    125 public Location(){
    126 bearing = 0.0;
    127 length = 0.0;
    128 }
    129
    130 public Location(double b, double l){
    131 bearing = b;
    132 length = l;
    133 }
    134
    135 public double calcDistance(Location l){
    136 double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
    137 double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)) );
    138 return Math.pow(temp, 0.5);
    139
    140
    141
    142 }
    143
    144 }
    145
    146 }
    147

  10. #10
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    every line that has line or location UP to line 76 is underlined and has error

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  12. #12
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    cannot find symbol
    symbol: class Location
    location: class javaapplication10.Stations
    ----
    (Alt-Enter shows hints)

  13. #13
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    cannot find symbol
    symbol: class Line
    location: class javaapplication10.Stations
    ----
    (Alt-Enter shows hints)

  14. #14
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package javaapplication10;
    import javax.swing.*;
    /**
     *
     * @author mpjames
     */
    public class Stations {
     
        public static void main(String[] args) {
     
            // declairing variables
            double tempBearing;
            double tempLength;
            double distanceToClosest;
            double distanceToClosestDest;
            double tempBearingDest;
            double tempLengthDest;
     
     
            //an array of stations
            Station[] stations = new Station[16];
     
            //populate the array with stations and values
            stations[0] = new Station("windmillHill",new Location(60.0,12.0), new Line ("Docks Line"));
            stations[1] = new Station("trim bridge",new Location(63.0,6.0), new Line ("Docks Line"));
            stations[2] = new Station("piracCresent",new Location(80.0,8.0), new Line ("Gyratory Line"));
            stations[3] = new Station("easton",new Location(85.0,12.0), new Line ("Brunel Line"));
            stations[4] = new Station("parkway",new Location(102.0,9.0), new Line ("Brunel Line"));
            stations[5] = new Station("templeFields",new Location(140.0,7.0), new Line ("Gyratory Line"));
            stations[6] = new Station("stDennis",new Location(180.0,1.0), new Line ("Docks Line"));
            stations[7] = new Station("moxbridge",new Location(180.0,2.0), new Line ("Brunel Line"));
            stations[8] = new Station("shakespeareCourt",new Location(192.0,5.0), new Line ("Gyratory Line"));
            stations[9] = new Station("weston-on-shore",new Location(232.0,14.0), new Line ("Docks Line"));
            stations[10] = new Station("jacobsWell",new Location(240.0,3.0), new Line ("Docks Line"));
            stations[11] = new Station("central",new Location(243.0,5.0), new Line ("Docks Line"));
            stations[12] = new Station("newbridge",new Location(245.0,11.0), new Line ("Docks Line"));
            stations[13] = new Station("tivoli",new Location(275.0,6.0), new Line ("Brunel Line"));
            stations[14] = new Station("cliftonStreet",new Location(285.0,11.0), new Line ("Brunel Line"));
            stations[15] = new Station("stJudesHill",new Location(355.0,4.0), new Line ("Gyratory Line"));
     
            //To get users current bearings and and locations and creating objects
     
            //String temp  = JOptionPane.showInputDialog("Bearing to current location?");
            tempBearing = Double.parseDouble(JOptionPane.showInputDialog("Bearing to current location?"));
     
            //temp = JOptionPane.showInputDialog("distance from origin of current?");
            tempLength = Double.parseDouble(JOptionPane.showInputDialog("distance from origin of current?"));
     
           //String temp  = JOptionPane.showInputDialog("Bearing to current location?");
            tempBearingDest = Double.parseDouble(JOptionPane.showInputDialog("Bearing to Destination?"));
     
            //temp = JOptionPane.showInputDialog("distance from origin of current?");
            tempLengthDest = Double.parseDouble(JOptionPane.showInputDialog("distance to end Destination?"));
     
     
            Location current = new Location(tempBearing, tempLength);
     
            Station closest = stations[0];
            distanceToClosest = current.calcDistance(stations[0].location);
     
            for(int i = 1; i < stations.length; i++){
                double tempDist = current.calcDistance(stations[i].location);
     
                if(tempDist < distanceToClosest){
                    closest = stations[i];
                    distanceToClosest = tempDist;
                }//if (tempDist < distanceToClosest)
            }//for loop
     
     
            //2nd loop for end destination
            Location currentDest = new Location(tempBearingDest, tempLengthDest);
     
            Station closestDest = stations[0];
            distanceToClosestDest = currentDest.calcDistance(stations[0].location);
     
            for(int i = 1; i < stations.length; i++){
                double tempDist = currentDest.calcDistance(stations[i].location);
     
               if(tempDist < distanceToClosestDest){
                    closestDest = stations[i];
                    distanceToClosestDest = tempDist;
                }//if (tempDist < distanceToClosest)
            }//for loop
     
     
     
            JOptionPane.showMessageDialog(null, "the closest station is " + closest.name + closest.line.lname
                    + "\nIt is " + distanceToClosest +  " away.");
     
            JOptionPane.showMessageDialog(null, "the closest station to your destination is " + closestDest.name
                    + "\nIt is " + distanceToClosestDest +  " away.");
     
      }
     
    }
     
    class Station{  // a station class
     
        Location location;
        String name;
        Line line;
     
        public Station(String n, Location l, Line r){
            name = n;
            location = l;
            line = r;
        }
    class Line {
       String lname;
       public  Line (String String) {
        lname = String;
    }
     
    }//class station
     
    class Location{
        double bearing;
        double length;
     
        public Location(){
            bearing = 0.0;
            length = 0.0;
        }
     
        public Location(double b, double l){
            bearing = b;
            length = l;
        }
     
        public double calcDistance(Location l){
            double angle = Math.abs(bearing - l.bearing);//calculating the angle between the bearings
            double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)));
            return Math.pow(temp, 0.5);
     
     
     
        }
     
    }
     
    }
     
    >

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Your IDE is hiding the full text of the error message.
    Can you compile the source with the javac compiler to get the full text of the error message?

    Why doesn't the IDE find the definitions for the Location and Line class?

  16. #16
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    yay lol......

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Try separating the definitions of all the classes to separate files with one class per file.

  18. #18
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    i cant m8 i wouldnt know how - its taken all i got to do what ive done lol sorry m8 but thanks anyway

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    There shouldn't be any problem selecting each of the class definitions from the class statement through the ending } and copying it to a new file.

    Who taught you to put all the class definitions in one file?
    That is not how it is normally done.

  20. #20
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: I cant work it out!!!

    class Station{  // a station class
     
        Location location;
        String name;
        Line line;
     
        public Station(String n, Location l, Line r){
            name = n;
            location = l;
            line = r;
        }
    class Line {
       String lname;
       public  Line (String String) {
        lname = String;
    }
     
    }

    Look closely here... I think there's a missing bracket.

    Also, I noticed that you closed the Stations class and then defined Station, Location, and Line outside of the Stations class. This doesn't work; you have to define each class in its own separate file or define the other classes within the Stations class.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  21. The Following User Says Thank You to snowguy13 For This Useful Post:

    tuts73 (January 11th, 2012)

  22. #21
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    OMG snow guy ive got rid of the location issues because of the one bracket as u said!!!! been looking for hours and couldnt see it.

    Still cant get it to accept the line class even within the station class....but ty anyway

  23. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I cant work it out!!!

    Post your error messages if you want help with them.

  24. #23
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    Take Line/Location/Station out as seperate java class files and ur program worked for me.. something like
    package javaapplication10;
     
    public class Line {
     
        String lname;
     
        public Line(String String) {
            lname = String;
        }
    }

  25. #24
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: I cant work it out!!!

    It is very hard to assist you because your code is like so unreadable. In order for the code to be easily readable, please, before pasting your code into the forum, type [highlight = java] and then insert code and finally before posting it, add [/java] at the end. why is this instruction so hard to get?

  26. #25
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I cant work it out!!!

    Hello tuts73, I have a very similar task to complete but im sturrgling to calculate the bearing. Have you managed to achieve this?

Page 1 of 2 12 LastLast

Similar Threads

  1. Why doesn't this work?
    By mailman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 9th, 2012, 11:19 PM
  2. Do you work out?
    By thesolo in forum Totally Off Topic
    Replies: 4
    Last Post: October 24th, 2011, 08:03 AM
  3. Why does this not work?
    By Spidey1980 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 12th, 2011, 09:47 AM
  4. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 10:24 AM
  5. Why won't this while loop work?
    By trueblue in forum Loops & Control Statements
    Replies: 2
    Last Post: July 17th, 2009, 09:10 AM