javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because the x.substring(0,200) throws a StringIndexOutOfBoundsException not a TryCatchException1.

If things worked the way you thought then when people do this:

try {

} catch (NumberFormatException e) {

} catch (SQLException e) {

} catch (Exception e) {

}

Then the other exceptions will never be caught and everything would go to the last Exception. It is true that you extend the StringIndexOutOfBoundsException, but that method doesn't throw the TryCatchException1.
Look at this:

public void methTryCatch() throws  TryCatchException1 {
   throw new TryCatchException1("TryCatchException1");
}

public void methOutOfBounds() throws StringIndexOutOfBoundsException {
   throw new StringIndexOutOfBoundsException("StringIndexOutOfBoundsException");
}
main() {
  try {
       methTryCatch();
  } catch (TryCatchException1 e) {
      System.out.println("methTryCatch: "+e.getMessage());
  } catch (StringIndexOutOfBoundsException e) {
      System.out.println("methTryCatch: "+e.getMessage());
  }

try {
       methOutOfBounds();
  } catch (TryCatchException1 e) {
      System.out.println("methOutOfBounds: "+e.getMessage());
  } catch (StringIndexOutOfBoundsException e) {
      System.out.println("methOutOfBounds: "+e.getMessage());
  }

try {
       methTryCatch();
  } catch (StringIndexOutOfBoundsException e) {
      System.out.println("methTryCatch: "+e.getMessage());
  }
}

Also since your method throws a TryCatchException1 you can do this:

public static void MyNumber(String x) throws TryCatchException1{
	try{
		
			String y = x.substring(0,200);
			
		} catch(java.lang.StringIndexOutOfBoundsException e){
                        throw new TryCatchException1(e.getMessage());
		}

	}

OR

public static void MyNumber(String x) throws TryCatchException1{
			String y = x.substring(0,200);
	}

Try catching the above like this and see what happens:

try{
		
			MyNumber("myStirng");
			
		}catch(TryCatchException1 e){
			System.out.println("BBBBB: "+e.getMessage());
		}catch(java.lang.StringIndexOutOfBoundsException e){
			System.out.println("AAAAAAA: "+e.getMessage());
		}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

print display the following message...

An instance of class Pig: position 1, colour Colour.RED.

When it should really be in position 0, colour PINK.

Can you post the latest code of what you can post.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

when you say print the value method do you mean println, I am using graphical objects. The actual work I am doing is different. I don't really want to give the whole code out. I will check on the return value of the getPosition.

It doesn't matter. The print is for debugging just for you to see what value it has, in order to understand what is going on.
And yes I mean: System.out.print....

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks for the quick reply..really appreciate it but i have some doubts ..can u pls help me out

public void method(File dir) {

do i pass my root directory over here..

That method gets all the Files under the input directory. If it is a text file then it reads it, if it is a folder then it calls it self in order to read the Files under that directory.

Look at the code. With what was given it is up to you to understand it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all always use {} brackets. Look what you wrote:

if(arg == "Exit")
 System.out.println("Program Terminated.");
 System.exit(0);

And what I wrote:

if(arg == "Exit") {
 System.out.println("Program Terminated.");
 System.exit(0);
}

In your first code, if the if statement is true it will execute only the System.out.println("Program Terminated.") and the System.exit(0) will always be executed, because you didn't put ant brackets.

And I would suggest not to use this:

String arg = e.getActionCommand();

 if(arg == "NewGrades") {

}

But this:

public void actionPerformed(ActionEvent e)
{ 
   Object src = e.getSource();

   if (mnuFileNewGrades == src) {
      // ....
  } else if (mnuFileExit == src) {
     System.out.println("Program Terminated.");
     System.exit(0);
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all don't use the list() method because it doesn't return the full path and you forced to do this:

String NewDir = dirLocation +"\\"+filename;

Try this:

public void method(File dir) {

File [] children = dir.listFiles(); 

for (int i=0;i<children.length;i++) {
   if (children[i].isFile()) {
       BufferedReader reader = null;
       try {
              // read the file
              reader = ...;
       } catch (Exception e) {
            System.out.println(e.getMessage());
       } finally {
            try {
               close(); // close the readers you used to read the file (BufferedReader and so on)
           } catch (Exception e) {}
       }
   } else if (children[i].isDirectory()) {
             method(children[i]); // recursive call
   }
}

}

You can also check if the file is a .txt file before reading it:

public isTxt(File file) {

String name = file.toString();
int length = name.length;

if (length<=3) return false;

return name.subString(length-3, length).equalsIgnoreCase("txt");
}

And next time use code tags. Press the (code) button when creating a new post.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

like that it will not set the file path correctly.
so instead of
File inuse = new File(temp)
you need to write
File inuse = new File("c:\\test\\"+temp)
cheers

vchandra is right.

Also it is a good thing always to check the API of the classes you are using. Why did you assumed that the dir.list() method returns what you want. If you had looked the API you would have seen that it doesn't return the full path.
You could also see this other method that does what you want:

File [] children = dir.listFiles();

You could have used that instead that returns the full path of the file.

Also whenever you are having problems you can print the values of what you are using:

// -->
System.out.println("Deleting: "+inuse);

boolean success =	inuse.delete();

You would have seen that the "inuse" file is not the right file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Probably because in the while loop you have code that sets the balance to the initial amount. Put that piece of code outside the loop.
I think that it happens here:
ca.setInitial(checkingAmt)
. You keep asking for the user to enter initial amount in the loop.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then print the value of the method. You say that the if doesn't work, but do you know what value does the getPosition() returns?

Also post your entire code using code tags. Press the (code) button when creating a post and put code inside.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hmm..interestesing...i like the effect..i even commented the line inside main..and i got only one 'a' printed. just to be clear......correct me if i'm wrong.. i am thinking this is happening because the the static reference main2 to the object is executed before the programm startes from main....and is not stored as a member of the class object if main?...
just curious..

If it is not static, then this: Main main2 = new Main(); would be called any time you create a new instance, which also creates a new instance and so on and so on.

static fields don't need an instance of the class in order to be accessed. So when this is called: static Main main2 = new Main(); the constructor is called and a new instance is created and all the attributes are created but not the static fields because they are not part of the instance itself.

I don't know a better way to explain it the technical terms elude me

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didnt know the rules and regulations, I have joined this forum before 3 days and only purpose was to help others.
I didnt know that ppl are posting only homeworks here.

It is good to help others with their homework. But in this case you ended up doing all the work.
Let's us both wait for funjoke88 to post some of his code, before giving any more assistance. It wouldn't be too difficult with all the help you gave him.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

public void actionPerformed(ActionEvent e){
JButton field1=(JButton)e.getSource();
String text=left.getText();

i really dunno how 2 write the code ...can you help out more pls?

public void actionPerformed(ActionEvent evt) {
   Object src = ect.getSource();
   if (src==button1) { // button1 is for multply from your code
      // look at the API for the classes JTextField, JTextArea
  }
}

Use the getText method of the JTextField class to get the input. Use the other method I told you to convert the input into a number: double d = Double.parseDouble(s); Then use the setText method of the JTextArea to set the result

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public void actionPerformed(ActionEvent e){
if (JButton button1=(JButton)e.getSource());
input = new Input(Integer.parseInt(field1.getText()));
area.setText(field1.getText() + " A+B = " + input);
area.setText(field1.getText() + " A*B = " + input);
else
(JButton button2=(JButton)e.getSource());

How is that remotely close with what I just posted. Don't ask if is wrong or not. If it doesn't compile, it is wrong and you will get error messages. Read them.
I gave you code on how to do the checks and what you posted has nothing to do with it. Is it so difficult to read both fields and apply the operators?

read text from field1
read text from field2

add them or multiply them

Use this to turn them into numbers:

String s = "1.23";
double d = Double.parseDouble(s);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the this.pig is null. You declare it as attribute at the class but you never give it value. You need to pass the parameter of the constructor to it:

public Amplifier(Pig aPig)
{
   this.pig = aPig;
   this.number.resetCount = 0;
}

Also in the reset method you check for the position but you never change it. If this.pig.getPosition() is greater than 1 then you will enter the loop, the color will change but you don't change the position. So the expression: this.pig.getPosition() > 1 will not change and you will never exit the loop.
Better try an if statement and change both these values to 0 and pink. Also there is a difference between saying: > 1 and >=1

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at the ActionListener interface and implement the method that it has. Now whenever you click a button that method is called. You can find which button was clicked by doing:

public void actionPerformed(ActionEvent evt) {
   Object src = ect.getSource();
   if (src==button1) {
      // the button1 was clicked. Use the getText methods of the textfields to get the input and multiply them. Look at the API of the classes you are using. Once you get the result set it to the TextArea
  }
}

Once again look at the API of the classes. You will need the get/set Text methods.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then post what you have done so far. The code that there is in the txt is not complete and doesn't compile. You are missing the closing brackets

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why, have you given any effort?

In the entire thread, vchandra has been given you the answer even though it is against the forum rules. You have showed no effort from your part. You just took the code, run it, and report back what you didn't like in order to get the latest code. Now that you are "satisfied" with the result you want the gui program written for you as well?

If the code given works for you, then do some studying on your own and start writing the gui application. Post some code in order to get positive feedback.

And to vchandra.
Please next time use code tags when posting code. Press the code button and put your code inside.
Also, as noble as your motives were, you were giving hime everything and when there was an error, YOU were the one again trying to solve it in order to post the correct code. After given him the code instead of trying to understand it and correct it, he was expecting everything from you. It is not your job to do funjoke88's homework.
Now that he wants the GUI version, he is unable to do it on his own because he hadn't learned anything. How was that helpful and how is he going to learn how to complete his next assignments. Do you plan on doing all of his homework?

I am only saying this, because I don't think it is fair on your behalf …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In one arraylist you will put the 5 marks. And it would be better if they were ints

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your question doesn't make much sense but I will give you an example in case it helps:

PAGE 1:

<a href="page2.jsp?name=someSchool&address=someA&number=11">Link in page 1</a>

PAGE 2: (page2.jsp)

<%
String name = request.getParameter("name");
String address= request.getParameter("address");
String number= request.getParameter("number");
%>


<a href="page2.jsp?name=<%=name%>&address=<%=address%>&number=<%=number%>">Link in page 2</a>

Inside the <%=%> you put the java variable. You can name the variable whatever you want. But inside the request.getParameter("") you must put as String what you used at the link as name of the parameter:

?name=someSchool
request.getParameter("name")

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i need to get the marks of five students,and i should grade them according to their marks lyk,1st rank,2nd rank.....here i should use arraylist....

Search this forum for examples on how to use the java.util.Scanner class. You will use it to read data from the keyboard.
Scanner

Then put those values into an ArrayList. Use a for loop.

for - loop { // 5 times or as many times as you like
  // read input
  list.add(input)
}

Then write a method that sorts the ArrayList. Or better yet, use the algorithm that searches for the max number of the ArrayList, print it and remove it. Then repeat until the ArrayList is empty:

while (list.size()>0) {
  // find the max
  // print it
  //  remove it
}

Check the API for the java.util.ArrayList class:
ArrayList

Then post the code you have so far, so we can give suggestions on how to proceed.
After you post what you have done, ask specific questions about which part of the code you are having problems with and what errors do you get at which line or what you don't understand

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

K ILL NOT REPEAT THIS AGAIN....Send me d coding...

Repeat what? Where are you having problems with and what is your question?

Just because you send me 3 PMs it doesn't mean that everybody can read my messages and nobody knows your question. And hijacking an old 1-year old thread will not get you any answers. It doesn't mean that we are suppose to remember the question you made in one old thread that nobody reads and give the answer to a new one.

You have a question; then asked it. Because what you wrote doesn't mean anything and almost everybody here don't know your original question.

We are waiting for the appropriate question because it is not our job to give you the answer, we are volunteering to help you. It is you who have the question and needs to be polite.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
p.println ("This is written to a file");

That is what is written to the file. I can't understand what is the problem. It writes whatever you want it to write. If you want something else written then put whatever you want written in that code:

p.println ("This is written to a file");
p.println ("and this");
p.println ("and this");
p.println ("and this");
p.println ("and this");

Also you have posted what you want written. Whatever results you get just put them as parameter at the println method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

my badd...thanks lots..i just kept on focusing on the clone..:):):) solved!!

If you want to have an attribute that is the instance of the class, if you make it static, it will work. But do that only when it is useful. If you can't think of why, then you shouldn't but this is how it is done:

public class Main {
    [B]static[/B] Main main2 = new Main();

    public Main() {
        System.out.println("a");
    }

    public static void main(String [] args) throws Exception {
        Main main = new Main();
    }
}

Try running the above and see what happens and then remove the static from the second line.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This code: private Employee e = new Employee("ME","MYSSN"); calls the constructor.

public class Employee {
	
[B]	private Employee e = new Employee("ME","MYSSN");[/B]
	
	public Employee(Employee e){
		this(e.name,e.SSN);
		
	}

When the constructor of a class is called you create an instance of that class and its attributes are declared and/or initialized.
Meaning that when you do this: private Employee e = new Employee("ME","MYSSN"); you call the constructor that creates a new instance. When you do that the e attribute of the class is created and it calls this: private Employee e = new Employee("ME","MYSSN"); . When you do that the e attribute of the class is created and it calls this: private Employee e = new Employee("ME","MYSSN"); When you do that the e attribute of the class is created and it calls this: private Employee e = new Employee("ME","MYSSN"); When you do that the e attribute of the class is created and it calls this: private Employee e = new Employee("ME","MYSSN"); When you do that the e attribute of the class is created and it calls this: private Employee e = new Employee("ME","MYSSN"); So after a while when you create an instance you call this: ( private Employee e = new Employee("ME","MYSSN"); ) That piece of code creates another instance that calls the private Employee e = new Employee("ME","MYSSN"); which creates another instance, ...

So remove the private Employee e = new Employee("ME","MYSSN"); from the code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks guys 4 the help....
this program is not for the java it actually for c++ program..
let me explain to yo..
in this coding..the users must enter the grade.ex:grade A,then it must appear in grade point which its 4.00....so that means we must cin the grade point...but I still did'nt get the correct coding....can you guys help me by giving the full coding for this program...

I already provided code that does that and kvass offered a more clever solution.
Do some studying in order to find the right C++ commands that do what we describe, or post to the C forum of this site.
Also better explain at what part exactly are you having problems with.
But don't expect anyone to give the answer if you don't show some effort

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you getting compile error?
I am not familiar with C#, but If we assume that the concatenation works the same then maybe this is the problem:

This:

<script type="text/javascript" src="<%=ResolveUrl"jquery.js"%>"></script> 
<script type="text/javascript" src="<%=ResolveUrl"JScript.js"%>"></script>

Should be like this:

<script type="text/javascript" src="<%=ResolveUrl + "jquery.js"%>"></script> 
<script type="text/javascript" src="<%=ResolveUrl + "JScript.js"%>"></script>

If it doesn't solve your problem then sorry.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is because you enter to the stack character by character:

theStack.push((int) (ch - '0'));

Meaning that this input: 10+2, will be entered in the stack like this:
1, 0, +, 2
You want this:
10, +, 2

Try this:

String s = "10+2-3/4*11";
StringTokenizer st = new StringTokenizer(s,"[+-/*]",true);

while (st.hasMoreTokens()) {
    System.out.println(st.nextToken());
}

And see what it prints.

Also for the above you will need you stack to take String array, not char:

String num2 = theStack.pop();
String num1 = theStack.pop();
if ("+".equals(operator)) {
     interAns = Integer.parseInt(num1) + Integer.parseInt(num2);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Mortal Kombat
Resident Evil Series
Diablo 2
Starcraft

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After reading the requirements they are pretty big, but most of all pretty explanatory. And given the introduction, I don't believe that you are required to do them all at once.

So at which point are you having problem with. What do you need to implement at first. The pdf tells you which classes to create, and it says that a DB is optional so you can use dummy data hard coded in the code.

Also at the end it explains what the code needs to do when testing.

And most important, since you have been given this, it means that you have been taught what is necessary or you need to study it. We cannot study for you. We have already done that.

Each week there will be a project
task that is related to the topic covered in the lab that week

So how many labs have you attended. If this is the first week then start with what you have been assigned and DO only what you have been asked. It shouldn't be too complex since it is the first lab.

If you have any problems post you code with the errors that you get, using code tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If I understood correctly your problem I think that you lack the basic of Maths.
I assume that a PolynomialTerm is this: aX^b: 4X^3.
If x=2 then the above would be: 4*(2*2*2) = 32

Then the addition can only be done only when the exponents are the same.
You cannot add these: 4X^3 + 4X^5. And when you add them it goes like this:
aX^e + bX^e = (a+b)X^e

For multiplication though it is like this:
aX^z * bX^k = (a*b)X^(z+k)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Write if statements. Have a method that takes as argument what you want and return the other. You say that the uses enters the grade and expects to see the grade point

public void nameTheMethod(Stirng grade) {
   if ("A".equals(grade)) {
          System.out.println(4.00);
   } else if ("A-".equals(grade)) {
        System.out.println(3.7);
   } else if () ...
}

Or better:

public double nameTheMethod(Stirng grade) {
   if ("A".equals(grade)) {
          return 4.00;
   } else if ("A-".equals(grade)) {
        return 3.7;
   } else if () ...
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The code you had didn't put any values into the array.
With the those 2 lines you can read input from the keyboard:

System.out.println("Enter Score " + (i+1) + ": ");
score = scan.nextLine();

You take the score, parse it into an int and put it into the array.

What you said is how you declare arrays that already have values:
int[] gradeArray = {80,90,91,92,93,94,95,96,97,98};

When you do this: scores[i] = Integer.parseInt(score); You put at the 'i' "element" of the array, the value you entered.
You read from the keyboard the grade as String (score variable) and then you turn it into an int:
Integer.parseInt(score) and put it into the array.

You need to take that part of the code and add it to your solution.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
[B]Scanner scan = new Scanner(System.in);[/B]

//enter 10 scores
String score = "";
for (int i = 0;i<= scores.length-1;i++)
{
  try {

      System.out.println("Enter Score " + (i+1) + ": ");
      [B]score = scan.nextLine();[/B]
      scores[i] = Integer.parseInt(score);

  } catch(Exception e) {
       System.out.println("Value entered: "+score+" is not a number");
       System.exit(1);
  }

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It means that such a constructor doesn't exist. Look at the Employee constructors. What do they take as argumentand what does the myStore.elementAt(i) return?

u=new Employee(myStore.elementAt(i));

Also shouldn't you be doing this:

u=(Employee)myStore.elementAt(i);
           if(txtName.getText().equals(u.name)) 
           {      
               txtName.setText(u.name);
               txtPhonenum.setText(u.phoneNo);
               txtNi.setText(u.natInsceNo);
            }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just create the labels, buttons and textfields like the example.
Check the API for what you need to use.

When the radio buttons are clicked get the value of the text field like the example.
Look the API of the JRadioButton and see what Listener to use. Use the getSource() method of the argument of the method the listener has to get which button was clicked.
Now that you know that just do multiplication to find the amount in euros and display it.
Like the example

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In a separate class or in one of the ones you already have, put that method:

public static void main(String [] args) {
   // instantiate objects and call their methods
}

Inside it you will put the code that you want executed. Then you will run the file that has the main method inside:
> java MainClass

Also in the constructor you do not use the arguments and the variables you do use (NUM_COLUMNS) have value 0. Shouldn't you be assigning the arguments to the local variables?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to print it and then run it to an sql client or an sql editor and see what is the problem:

..
String query = "INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')";

System.put.println(query);

prepStat = connection.prepareStatement(query);

Take what is printed and run it. Also you can post it here with the values that you entered.

The above are for general debugging in case you have any future errors. After looking at the query, I would like to ask:

The Date column, what type is it? Is it type VARCHAR2 or type DATE. If it is type DATE then I don't think that this would work: ('"+date+"', Also, and I don't know if it is a problem or not, I believe that "date" is a reserved word for the sql and you cannot use it to name columns. If that is the problem, you can try to rename it to weather_history_date

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if it can be done but instead of using the ActionListener interface, you can use the MouseListener interface. Check the API of the JButton to see if it can accept such a listener. If yes, then look at the methods that it has.

Also when you drag the button you can set a variable to true and check that variable when you click the button to determine if it was dragged or not. When the button is released after it is dragged you can set that variable back to false.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have defined another class called Connect4Column. I have sorted the cannot find symbols. Its just the one error
cannot find symbol symbol : variable my_array location: class Connect4Model
return my_array[thisColumn];

Have you declared such a variable?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i think Connect4Column is a class..

how can you instantiate such class as an array...

i can't understand what u done...

It can be done. Provided of course that such a class exists.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you defined a Connect4Column class?

Also I have given suggestions in the other thread which you didn't follow. (About the ';').

The constructor seems ok though. If it is the same as before then I must have missed something.

Next time use Code tags. Press the button: (code) when you make a new post

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks for quick response

OK so now I have

    public Card()
    {
    final int SUITE_NUM = 4;
    final   int CARD_VAL_NUM = 13 ;
    String[][] pack={{"Hearts","Clubs","Diamonds","Spades"},
        {"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}};
        int x =(int)(Math.random()*(SUITE_NUM))+1 ;
        int y =(int)(Math.random()*(CARD_VAL_NUM))+1 ;
        this.card = pack[0][x] + pack[1][y] ;
    }


}

which gives error

Card.java:13: incompatible types
found   : java.lang.String
required: java.lang.String[][]
        this.card = pack[0][x] + pack[1][y] ;
                               ^
1 error

but this works fine what is difference please?

String[][] names = {{"Mr. ", "Mrs. ", "Ms. "},
                        {"Smith", "Jones"}};
            int x = (int)(Math.random()*(2))+1;
            int y =(int)(Math.random()*(1))+1;
    System.out.println(names[0][x] + names[1][y]); //Mr. Smith
    System.out.println(names[0][x] + names[1][y]); //Ms. Jones

end quote.

I would also like to add something that I didn't mention and might give you an extra help:

This:

this.card = pack[0][x] + pack[1][y];

Is putting the String: pack[0][x] + pack[1][y] into an array.

This:

System.out.println(names[0][x] + names[1][y]);

Is printing the String: names[0][x] + names[1][y]

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i want to disable forward and back button of IE in jsp page

Perhaps it would be better to tell us WHY you want to disable the forward/back button. Maybe what you are trying to achieve can be done in another way than disabling the buttons.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i give up - you can't assign string values to an array?

An array is an array and a String is a String. How can you expect to do this:
array = String this.card = pack[0][x]; card is an array. pack is an array.
card[x][y] is a String. pack[x][y] is a String.


you can't make new array and assign a few of those to another array

That doesn't make any sense.


if i can assisgn methods to array surely i can assign string values

You cannot assign a method to an array. A method returns an array.

public String [] methodArray() {
  String [] arr = {"a", "b"};
  return arr;
}

String [] aNewArray = methodArray();

The methodArray returns an array and you put the result that it returns to an array.
In the same way a method returns an int:

int methodInt() {
   return 5;
}

int i = methodInt();

If you want to put the values of one array into an other then
Create a new array that has the same length as the original.
Then write a for loop. Loop the array and put each of the elements of one array into the other.

It would be helpful if ask specific questions on what you are trying to achieve

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at this:

Connect4Model(int numCols, int numRows); constructor
{

You have a semicolon after the parenthesis. It means that you ended the command there and the rest: {...} are not inside the constructor. Don't use ';' at the declarations of methods.

In methods like this: int getCounter(thisColumn, thisRow) you don't define the type of the parameters. May I suggest this: int getCounter(int thisColumn, int thisRow) Also don't call the same constructor inside its own constructor:

[B]Connect4Model[/B](int numCols, int numRows)
{

columns[i] = new [B]Connect4Column[/B](NUM_ROWS); //New object 

}

If you do that, the inside constructor will call the constructor which will again call the constructor inside it, which will again call the constructor inside it, which will again call the constructor inside it, ....

It would be better if inside a class you just create a 2D array of type int or String that represents the Connect4 values of the game:

class Connect4 {
  private char [][] array = null;

  public static final char EMPTY = ' ';

  public static final char RED = 'R';
  public static final char BLUE = 'U';
  // OR
  // public static final char P_1 = '1'; // player 1
  // public static final char p_2 = '2'; // player 2

  public Connect4(int rows, int columns) {
      array = new char[rows][columns];
     // loop the array to give it values.
     array[i][j] = EMPTY; // 
  }
}

Then have a method that loops the array to find if there are 4 consecutive occurrences …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

try this

public class Battleship{
public static void main(String[] args){
int boardInput = Integer.parseInt(args[0]);
}
}

Cheers

That is correct, but I would prefer something like this:

public class Battleship{

public static void main(String[] args){
    if (args.length>0) {
         int boardInput = Integer.parseInt(args[0]);
    } else {
         System.out.println("No arguments given");
    }
}

}

After you understand the above and get familiar with exceptions then try this in case the argument is not a number.

public class Battleship{

public static void main(String[] args){
    if (args.length>0) {

          try {
              int boardInput = Integer.parseInt(args[0]);
          } catch(NumberFormatException nfe) {
              System.out.println("No number was given: "+args[0]);
          }

    } else {
         System.out.println("No arguments given");
    }
}

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After you call the second query, do you check if there were any rows returned before calling the rs.getString ?

// Maybe you should do this:
rs1.close();

rs1 = st.executeQuery(ssql2);

// And this:
if (rs1.next()) {
  buffer = rs1.getString("balance");

}

You also don't close the rs, the st and the conn inside a finally block and the dbConnect, should throw the Exception. If there is one you catch it, do nothing and then continue even though the connection failed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks for quick response

OK so now I have

    public Card()
    {
    final int SUITE_NUM = 4;
    final   int CARD_VAL_NUM = 13 ;
    String[][] pack={{"Hearts","Clubs","Diamonds","Spades"},
        {"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}};
        int x =(int)(Math.random()*(SUITE_NUM))+1 ;
        int y =(int)(Math.random()*(CARD_VAL_NUM))+1 ;
        this.card = pack[0][x] + pack[1][y] ;
    }


}

which gives error

Card.java:13: incompatible types
found   : java.lang.String
required: java.lang.String[][]
        this.card = pack[0][x] + pack[1][y] ;
                               ^
1 error

but this works fine what is difference please?

String[][] names = {{"Mr. ", "Mrs. ", "Ms. "},
                        {"Smith", "Jones"}};
            int x = (int)(Math.random()*(2))+1;
            int y =(int)(Math.random()*(1))+1;
    System.out.println(names[0][x] + names[1][y]); //Mr. Smith
    System.out.println(names[0][x] + names[1][y]); //Ms. Jones

end quote.

I have already explained why, and the error tells you exactly that:
this.card is an array and these pack[0][x], pack[1][y] are Strings. You cannot assign a String to an array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you take the text from the JTextPane, and do you write it to the file?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have a counter in each of those methods. When you print something increase it by one. When it reaches 5 or 9, call the System.out.println(); and set it to 0.

int count = 0;
for (loop) {
    System.out.print("something ");
    count++;
    if (count==5) {
       count=0;
       System.out.println(); 
    }
}