~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You ain't doing it right. Maybe this would help.

srs_grp commented: It was really helpful!! +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I am sure PHP has some sort of MVC architecture implementation wherein the controller handles the requests and delegates it to an appropriate entity.

// Here /operations is mapped to a PHP file which acts as a 
// controller and performs the delegation activity based on
// the operation requested, here, find-provinces
xmlHttp.open("GET", "/operations/find-provinces", true);
xmlHttp.send(null);

Maybe posting this PHP related query in the PHP sub-forum might bring out some good responses since this seems more like a server-side url mapping/configuration issue.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe something like [untested]:

var reg = /(<span[^/>]+)\/>/gi;
var str = "<span id='d'/><div id='3'>d</div>" +
          "<span id='j' style='blah: 10px'/>";
var a = str.replace(reg, "$1><\/span>");
alert(a);

But this would mean looking away from the actual problem; the problem here is that SPAN HTML tags need to have a ending tag. What is xmlParser here? How come xmlParser returns an invalid span tag; can't it be fixed to return proper spans?

And BTW, this isn't a Firefox problem, it is actually doing what it should do. Since SPAN tags need to have content, the /> is ignored and <span id="something" /> is treated as the start of a SPAN tag.

IMO, the solution you are seeking seems more like a hack.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Multi posted in the Javascript forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The twoDArray in your case is just an array of size 10 with each slot referring to a integer array i.e. two dimensional arrays in Java are just an array of arrays. Hence you can either use twoDArray[3] = oneDArray; or System.arraycopy if you don't want modifications in the original oneDArray to be reflected in twoDArray. Also read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Any exception in Java comes with a stack trace. Try to read the entire exception trace and see on which line things are going wrong. If you are using an IDE like Eclipse, use the debugging feature to inspect the values at run time. If you are using a normal text editor, look into the command line debugger JDB. BTW, have you allocated memory to the Member array box?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Slim chances since this seems to be a question from a programming course and not a tricky interview question. Though it is one of the logically correct solutions, if this really were the case, no break would be needed in the original snippet. Plus the breaking condition can be something which can't be computed before hand or placed in the loop conditional, hence the suggested solution.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Since all of the checkboxes have the same ID

You would be violating the specification if you had more than one HTML element with the same value of ID attribute. There are better/valid ways of identifying or a grouping together form elements. Read this.

And since you have asked for additional comments, regarding CSV's, any database design which requires the application logic to slash and hack the retrieved data is broken IMO. Also, I would assign a unique name to each check box and each check box would have one of the two class names: checked and unchecked; this would facilitate easier processing via JavaScript and application of style sheets.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> He stated that both methods are bad programming practices.

No, it isn't; don't fall into such debates as anyone who tries to convince you such is just selling snake oil. If it really were that bad, you wouldn't have found Sun's internal implementation of most of the library classes to be cluttered with them.

IMO, not all things are bad in an absolute sense; there are just good and bad ways of using the same thing.

Ezzaral commented: Exactly what I thought when I read that. +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's pretty easy; make full use of the conditional expression which gets tested before the body of the loop is executed. When the given condition is reached or encountered within the loop body, set a boolean flag and test the same in your loop conditional.

for(int i = 0; i < 10; ++i) {
  if(i == 5) {
    break;
  }
}

boolean done = false;
for(int i = 0; i < 10 && !done; ++i) {
  if(i == 5) {
    done = true;
  }
}

Of course you can use anything instead of a boolean but the basic premise of the solution remains the same. Make sure you skip normal execution after setting the flag otherwise the semantics of the solution changes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

From what I understand, your web page has a text field which allows the user to enter his search criteria. Based on the user input, a new set of check boxes are fetched from the server but before doing that, you need to persist the state of the check boxes currently visible to the user. Is your requirement the recording of the state of the check boxes before the new content replaces them?

If yes, then you can make two async requests; one which serializes the state of the form [the one containing the check boxes] and sends it to the server and another which fetches the new content based on the search criteria. You can even glue together both the parts by sending both the serialized form state and the search criteria in the same request.

If it's something else, you need to be a bit more explicit with some pseudo code or illustrations.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> String[] sentences = str.split("(?<=[\\.!?]+)(?![\\.!?]+) *");

Like previously mentioned, you don't need to escape regular expression meta characters inside bracketed character classes. Hence [.!?]+ to be used instead of [\\.!?]+ .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you plan on viewing the output on Eclipses's console, it shouldn't be that big a problem. Try following the advice in this post.

But if you are stuck with windows console, then there isn't a reliable / sure shot way of getting it to work. Many have suggested setting the code page to 65001 though I am not very sure whether it works in all cases.

Let me know if the above suggested fixes work in your case. Best of luck for your project; hoping to see it on sourceforge. ;-)

puneetkay commented: Superb! Thanks for help! +2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Because number can be greater or smaller then other number,
> however you can not apply same logic to characters

Yes, you can, because characters form a part of numeric data type. There are only two primitive types in Java: boolean and numeric.

Directly comparing characters can be troublesome if your application is aimed at providing internationalization in which case some sort of unicode sensitive comparison needs to be provided.

> Couldn't you also convert the char to an integer, then compare
> the two chars?

Not applicable to the discussion here; read above.

> My program keeps looping when asking for seat letter. Can anyone
> help me out as to why that is?

As I see now, your program is a complete mess with the core logic tightly coupled with I/O and hard coded magic number everywhere. Try redesigning your application and assigning proper responsibilities to well thought out classes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There is as such no problem with your code; IMO the fault lies with the incompetence of the shell to render fonts correctly. I assume you are on a windows box? Anyways, this is just a rendering issue. Maybe a little more background on what you are trying to achieve here would be required to offer some advice.

Anyways, to mess around with code points and to get a feel of how the characters looks, try this sample snippet which creates an HTML document 'test.html'.

// Error handling and best practices omitted for brevity

public class HtmlTester {

  private final static String HTML = 
  "<html><head><META HTTP-EQUIV=\"Content-Type\" " +
      "CONTENT=\"text/html; charset=UTF-8\"></head><body><div>{0}" +
      "</div></body></html>";

  public static void main(final String[] args) throws Exception {
    testIt();
  }

  public static void testIt() throws Exception {
    String toWrite = MessageFormat.
      format(HTML, String.valueOf("\u0A72 \u0A73 \u0A74"));
    writeData(toWrite, new File("test.html"));
  }

  public static void writeData(String s, File f) {
    try {
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
          new FileOutputStream(f), "utf-8"));
      out.write(s);
      out.flush();
      out.close();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

}

The gurmukhi characters are displayed correctly since I guess browsers have their own font rendering engine.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

At least post your attempt in terms of indexOf and substring indicating the problem you are facing.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have two options:
- If your delimiters are simple single character sequences [. and !] in your case, you can try looping over the entire string and extracting the relevant parts using indexOf and substring
- If your delimiters end up being multi-character sequences you can try to use the hammer of text processing i.e. regular expressions.

A sample implementation:

import java.util.regex.*;

public class SentenceTester {

  public static void main(final String[] args) {
    splitTest();
  }

  // Implement a splitting logic using regex which also works for 
  // multi line strings.
  private static void splitTest() {
    String line = "hello there!!!!! how're you doing? " + 
      "\ni am pretty sure you are doing well.\nright?";

    // Pattern: Any-of-.?!{1, n} followed by whitespace{0, n}
    Pattern pat = Pattern.compile("[.?!]+\\s*", Pattern.DOTALL);

    // Create matcher instance which will match the given regex with
    // the line in consideration.
    Matcher mat = pat.matcher(line);

    int start = 0, end = 0;
    while(mat.find()) {
      start = end;
      // return a `1 based index' into the string where the pattern
      // match ends. Hence when `end' is 17 means character at 
      // position 18 in the string.
      end = mat.end();
      System.out.println("#" + line.substring(start, end) + "#");
    }    
  }

}

> So in effect when the regex parser encounters it the expression is reduced
> to "\.?!", this "\" indicates to the regex parser that the following "." is not a
> regex quantifier.

The quantifiers lose their special meaning when used inside …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> But, sometimes, I just don't feel like taking the effort to try
> talking them out of it.

Yes, even I get that sort of feeling but seeing that VernonDozier is a Daniweb regular, I took my chances. ;-)

> that calling getRed () really slowed the program down and that
> there was a lot of overhead with it, but that's not true, is it?

No, it isn't, really. If you are still concerned about calling the same method again and again, instead of having your class maintain the state or cache the `red' value, shove the responsibility to the invoked method instead.

private void mutate() {
  int red = color.getRed();
  // some complicated, multi step calculation using `red'
  color.setRed(red);
}

And talking of terms like overhead for a program without any concrete profiling data whatsoever is wrong IMO.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It gives me immense pleasure to mark this thread as solved. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah, this is what I get for posting a reply based on the thread title. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, at least not when using the standard library because in *nix, the creation time isn't stored anywhere. If you are running on a windows box, you have two options:
- spawn a shell process which fires the command 'dir /a' and extract the creation time [easiest]
- Use JNI, maybe something like FileTimes library

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Wha..?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In Java, everything is passed by value; in case of primitive types, a copy of the value is created and then passed as an argument to the method invoked.

private void mutateItNot(int v) {
  v = 10; // no effect on the original integer value
          // this `v' is just a copy of the `int' being passed
}

In case of references, a copy of the reference variable is created and then passed as an argument to the invoked method. Think of this as a remote control used to regulate the functioning of a T.V. When a reference type is passed to the method, a copy of it i.e. a copy of the remote is created which in the end is used to manipulate the same T.V. You can regulate the T.V. with this cloned remote in the same way as you would do with the original but destroying this remote has no effect on the original.

private void mutateItNot(SomeThing s) {
  // use the reference to manipulate the object it points to
  // [assuming we are not talking about immutable classes here]
  s.setField(someValue); 
  s = null; // the clone is now made to point to nothing
            // with absolutely no effect on the original
}

> I'm also storing the red, green, blue, alpha values as integer
> attributes in those classes because I am using them a lot

Why? Ease of use? Performance? This is no sane reason to duplicate data; your class instance …

stephen84s commented: Earlier had created a mess answering a similar question, this was very well put. +4
VernonDozier commented: Good explanation +10
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tsk tsk, let's not get into unproductive discussion here. I am pretty sure you both understand that there is no point in nitpicking each others' post to the point that it turns into name calling.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> This also assumes that encoding won't be problem.

If this is what he actually wants, encoding shouldn't be a problem as long as an appropriate character set is specified when creating the string. String text = new String(bytes, "UTF-8"); .

> byte[] b = new byte[f.length]; .

Array bites? ;-) byte[] bytes = new byte[f.length()];

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Terms like efficiency make little sense when used in an absolute context. For finding the most efficient way to solve a problem you first need to track down your applications' usage pattern i.e. what kind of file reading does your application need? Is the data read promptly consumed or is stored for future use? Profiling your application is by far the best approach to selecting an efficient solution.

BTW, StringBuilder & StringBuffer are mutable companion classes to the immutable class String ; one being non-thread safe and the other being thread safe respectively.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I felt a bump was in order for this one...

> Unfortunately, the implementation of ArrayList<T> looks
> [something] like this--

Doesn't seem unfortunate to me; as long as the state is persisted and can be recovered from the flattened representation of the object, it doesn't matter which approach is taken to serialize the object. In this case, the implementer chose not to serialize the array which backs the ArrayList but the individual elements for obvious reasons [hint: the size of the array is not always equal to the number of elements in the ArrayList ].

The only thing you need to look out for is that the objects contained in the ArrayList can be serialized [the concrete class implements either Serializable or Externalizable ].

If my memory serves me right, you posted something along the same lines in a thread you created; maybe it's time to go back and edit it. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No l33t speak and use of code tags on the very first post; this has given me happiness indeed.

Anyways, the problem with your approach is that you attempt to read in `int' from the file but don't test for it i.e. instead of fileRead.hasNext() test for fileRead.hasNextInt() . Also, your code will fail if any of the lines have less than four tab separated integer strings. Consider having a test for int before reading one.

IMO, reading in a single line from the file and parsing it manually gives you much more control and flexibility in your implementation than using fileRead.nextInt() . To prove this point, try replacing one of your integer strings with a alphanumeric character. Also, intermixing the file reading logic along with the parsing logic / file format logic is bad in itself; consider having a separate class process each line of file separately so that if you need to change the format, the impact is minimalistic.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Much better than Thread.getThread().sleep(3000) which doesn't compile. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Thread.getThread().sleep(3000); //Pause for 3 s Thread.currentThread().sleep(3000);

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I was wondering if someone could explain to me how to merge two arrays so that one is not simply appended to the other, but they need to be merged into one sorted array. I could simply append the two arrays and then sort the result, but that would be too easy. Instead I need to have my javascript look over each element of both arrays to see which number is smaller to merge into one sorted array. I need to be able to understand how and why it works if possible.

For example:

arr1 = [1,2,7,10];
arr2 = [3,4,9,19];
//needs to merge into one array appearing as [1,2,3,4,7,9,10,19];

Any quick explanation on how to do this would be greatly appreciated. Have a wonderful holiday weekend everyone and I look forward to talking with someone soon.

There are better ways to understand sorting than doing things the hard way. Anyways, what you can do is:

- Sort both the arrays
- Inspect the first element of both the arrays
- The array which has the smallest element as its first element is the one into which the other array will be merged. Let A1 be the array into which array A2 will be merged.
- Run a loop over the array A2 and for each element; let that element be E.
- Run a loop over A1 and find an appropriate place in A1 to insert E
- Rinse and repeat

Of course the above would require …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I have tried reading: Struts 2 In Action, but I wasn't very thrilled
> about it

Reading anyways isn't as thrilling as getting your hands dirty with the real stuff. Try some sample projects you can think of when learning Struts and practice as you read. The online documentation plus the book should be good enough.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> the method I need is:public static Person binarySearch(Person[]
> people, String target)

Is this a school assignment for implementing binary search? If not, then use the binarySearch method of the Arrays class.

And you don't need another method; what you need is just an instanceof check along with an appropriate cast.

Comparable c = binarySearch(persons, person);
Person p = null;
if(c instanceof Person) {
  p = (Person)c;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
String s1="a";
String s2="a"; //2 Different objects.

(s1==s2) //false
(s1.equals(s2)) //true

Think again; hint: String pool.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The simplest way would be to use the Collections#shuffle(List<?> list) method which delivers decent performance and output.

If you have an assignment to create such a shuffling algorithm, then look at the source code of the Collections class for hints.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This means that instead of either catching IOException and doing nothing or making the method throw IOException , introduce a custom exception hierarchy for your application. This hierarchy might contain something from two to twenty custom exceptions depending on the breadth of your application.

For e.g. in the above case, you might just create a custom Exception class which extends RuntimeException and use it to wrap the actual IOException which occurs in your code.

public void someMethod(String fileName) {
  try {
  } catch(IOException ioe) {
    throw new SystemException("File not found: " + fileName, ioe);
  }
}

Since the exception is unchecked type, it gives you the flexibility to completely ignore the possibility of an exception occurring when reading a given file or handle it in case you feel like it and process it accordingly. Just make sure you specify the cause when creating a new Exception instance so that it can be used for logging or other debugging purposes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Google for createElement and insertBefore.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use the Error Console feature of Firefox to track down Javascript errors. Use the Firebug extension of Firefox for debugging Javascript application. Also don't search for parent elements of node, just use the parentNode property of the Node.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

s.o.s, no offense, but sifting through a ton of material to *maybe* answer my question doesn't sound too appealing. If reflection is indeed useful, there have to be some practical, simple explanations of why this is the case.

It seems as though you missed my entire post. The first two paragraphs of my previous post mention the most widely used implementations of the reflection API. Another use of the reflection API is to implement the Webservice client for SOAP type web services wherein the XML response from the server is converted to an object tree using the schema definitions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As far as I know, exceptions that are not subclasses of runtime exception or error should be caught (handled).

When a file exception occurs, it should be caught because its a subclass of exception class, but how can it be recovered? If file is not found,it sounds silly to recover it when the program has to read file to run,I think the program should be terminated.

} catch (IOException e) {
            e.printStackTrace();
            System.exit(0);
} finally {
        if(in != null)
           in.close();
}

I preferred to exit in catch block,what should be done in such a situation?

Making IOException and SQLException as checked exceptions is regarded as one of the blunders of the Java standard library design. Many might argue that having checked exceptions in itself is a big PITA but that's a story for some other day.

Anyways, just make sure you don't propagate error codes anywhere in your application design; it's one of the worst design decisions to make esp when using a language like Java which has exceptions built in.

You have two options here:
- Either let the method throw the same IOException which occurs and let the invoking method handle the case. This seems to be a bad choice since the calling method now has to handle an exception it shouldn't have been bothered with in the first place.
- Create your own RuntimeException class which fits ecosystem of your application and wraps around the IOException thrown. This exception should be thrown when an …

jasimp commented: well said +9
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think of all the frameworks which let you specify your custom class in their configuration file and load those classes at runtime. The servlet specification for instance has a deployment descriptor which allows the developer to configure servlets, filters for his application. All the developer has to do is to specify the class name and the required processing is done at runtime by the container.

Also look into Spring or Guice which are IOC/Dependency Injection frameworks.

That being said, there *are* a lot of uses of reflection; it's just that they aren't that obvious.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

As per the specification, in a HTML document, the ID attribute must be unique. Assign a different ID and NAME to each INPUT element. Don't use GET, use POST for sending your form data.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> It just lets me know about certain properties of an Object, such as its classname

It does much more than that.

> The concept of a Map is somewhat familiar, but it doesn't help avoid the work, does it?

It provides a solution to your problem. IMO, what you are looking for is not a solution but a syntactic sugary way of doing things. Like previously mentioned, either use an array, a map or a JVM targeted scripting language like maybe Groovy, Scala, Rhino etc.

> I guess this isn't possible in Java though.

Yes, in the same way it isn't possible to create classes in C.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> For example, if I have an Animal named germanShephard, is there some way I could say
> String gerSh = "germanShephard"; and then treat gerSh as if it was the equivalent of
> saying germanShephard in my program?

You can't because gerSh is now a String. The closest you can come to this kind of name to Object mapping is by using a Map or by using the reflection API, which again doesn't work for `private' members.

The behavior you speak of can be seen in all ECMAScript implementations. Something of the sort:

var obj = {dog: {name: "poo boy", type: "poodle"},
                cat: {name: "neko san", type: "siamese"}};
var key = "dog";
alert(obj.dog.type); // poodle
alert(obj[key].type); // poodle
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't override service ; just override the method which you want to support and accordingly override the doGet() or doPost() method.

The `action' attribute of the FORM tag is mandatory. You don't need to use Javascript, just use the action attribute of FORM tag with a normal submit button.

Also there is no reason for a service method to run twice unless there actually were requests made; print out the request.getRequestURL() inside your request handling method to see which URL was requested by the client. In case your page references other resources like images or Javascript files present on the server and your web.xml maps each request to your servlet, the multiple invocations might just be explained.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> and the meaning of this is that in this case we must call the base constructor with super()
> but my question is how in th first class CounterDemo extends Counteexample we do not
> need super();

In case you don't provide a constructor for your class, the compiler automatically inserts one with the same access modifier as that of the class for you. It is called a *default* constructor. A default constructor is a no-arg constructor but an explicitly provided no-arg constructor isn't a default one. A few examples:

// original code
public class A {}

// generated code
public class A {

  // default constructor
  public A() {
    super();
  }

}
// original code
class B {}

// generated code
class B {
  
  // default constructor
  public B() {
    super();
  }

}
// Original code
public class C {
  
  // An explicitly created no-arg constructor
  public C() {
  }

  public C(int i) {  
  }

}

// Generated code
public class C {
  
  public C() {
    super();
  }

  public C(int i) {
    super();
  }

}

Of course, things start getting hairy when Serialization is involved, but that's a story for some other day...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have a few options:
- Creating hidden fields which hold your temporary results.
- Saving the state in a global variable which can be used across function invocations.
- Creating your own custom object which maintains the state.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The script in case of a SCRIPT element may be defined inside the contents of the SCRIPT element or in an external file. The only difference here is that an additional request is made in the case of an external script file. Hence you can treat your script as though it was embedded in the document even when it comes from an external source.

You have a few options; either pass in the `id' / `name' of the form elements whose values you need to access to the Javascript function or just access them directly from your function assuming that the form elements with the given `name' / `id' are always present.

<input type="text" name="txtOne" id="txtOne">
<input type="text" name="txtTwo" id="txtTwo">
<input type="button" value="Calculate" onclick="getIncomeTax('txtOne', 'txtTwo');">

<!-- OR -->

<input type="text" name="txtOne" id="txtOne">
<input type="text" name="txtTwo" id="txtTwo">
<input type="button" value="Calculate" onclick="getIncomeTax(this.form);">

function getIncomeTax(frm) {
  var e1 = frm.elements['txtOne'];
  var e2 = frm.elements['txtTwo'];
  var iTax = doSomething(e1.value, e2.value);
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The above post is all in one class and not in different classes like I had wanted.

Of course, otherwise I would have ended up giving you the entire solution.

public void in(InputStream in)
	{
		class2 class3Obj = new class3();
	
		x=((class3)class3Obj).get_x();
		y=((class3)class3Obj).get_y();

		for(int i=0;i<arr.length;i++)
		{
			String[] tmp = arr[i];
			for (int j=0;j<tmp.length;j++)		
			{	
					tmp[j]=" X ";
					arr[x][y]=" O ";
			}
		}
	}

Again a lot of problems with your code.
- Don't create a `public' Scanner instance; use the `in' passed in the `in' method of class1 to create a Scanner , that's the entire point of passing in an InputStream .
- If you need to set something at the position x,y of your array, do it once, not in a loop. It is because of this loop that the previous values are getting wiped off. Also check the values of `x' and `y' to avoid ArrayIndexOutOfBoundsException .

Any reason why `class3' extends `class2' and `class3' has a reference to `class1'? Your design has a lot of coupling and almost no cohesion. Like I mentioned previously, reconsider your design choices, discuss with your peers and professors about this assignment and read some good tutorials/books.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Either pass the array reference declared in main() to your methods or just make sure that the display() method prints out the instance variable 'arr' instead of passing it an array declared in the main() method.

// Untested: Error handling omitted for brevity
class ArrayTest {

  private String[][] twoDimArr;

  public ArrayTest(int x, int y) {
    // handle invalid input
    twoDimArr = new String[x][y];
  }

  public void populateArray(InputStream in) {
    // loop over the array, accept input from the source (here `in')
    // and populate it.
  }

  public void displayArray() {
    // loop over the array and display each element.  
  }

  public static void main(final String[] args) {
    ArrayTest t = new ArrayTest(3, 3);
    t.populateArray(System.in);
    t.display();
  }

}