Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Classes Help!

hoody1601hoody1601 Posts: 1Member
I am having a huge problem atm:
I am reading in a text file with 2 co-ordinates and then the name of the landmark at those co-ordinates like so:
1 12 House
2 5 Car
5 7 Southern

I have managed to read these in to an array within the main method,
I then have two other methods: Landmark and LandmarkList

The Landmark class is used to hold a single object with various get methods and a boolean value to be toggles when the landmark has been visited, here is the constructor for the class:
public class Landmark
private int x = 0;
private int y = 0;
private String name = null;
private boolean visited;

public Landmark(String xIn, String yIn, String nameIn)
x = Integer.parseInt(xIn.trim());
y = Integer.parseInt(yIn.trim());
name = nameIn;
boolean visited = false;

The code for the main method looks like this:
Scanner sc = new Scanner(new File("landmarks.dat"));
Scanner sc2 = new Scanner(new File("landmarks.dat"));

int LMcount = 0;
System.out.println("the number of items in the array is " + LMcount + " and the number of rows in the array is " + LMcount/3);

//now have the size of the landmarks file in items. need to create a new LandmarkList
LandmarkList LMList = new LandmarkList((LMcount/3));

//filling the array LMarray with items from the file landmarks.dat, all items are strings
String [][] LMarray = new String [LMcount/3][3];
int p = 0;
LMarray[p][0] =;
LMarray[p][1] =;
LMarray[p++][2] =;
System.out.println("************ LANDMARKS *************");
for (int w = 0; w < LMarray.length; w++)
System.out.println("x " + LMarray[w][0] + " y " + LMarray[w][1] + " " + LMarray[w][2]);

and the code for the LandmarkList looks like this:
import java.util.*;

public class LandmarkList
private Landmark[] list;

public LandmarkList(int sizeIn)
list = new Landmark[sizeIn];

private int search(int xIn, int yIn)
for (int i = 0; i < list.length; i++)
Landmark tempAccount = list[i]; //find at index i
int findX = tempAccount.getX();
if (findX == xIn)
return i;
return -999; //denotes value not found

public int arrayLength()
return list.length;

public void fillArray(String[][] ArrayIn)
for (int i = 0; i < ArrayIn.length; i++)
String x = ArrayIn[i][0];
String y = ArrayIn[i][1];
String n = ArrayIn[i][2];
list[i] = (x,y,n);

i know that its long winded but im really stuck and dont know how to get the LMarray into the Landmark class throught the LandmarkList class if that makes sense....

any help please?
Sign In or Register to comment.