javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

By the way I just noticed that you loop the array the wrong way:

for(int i=0; i<rows; i++) {
  for(int j=0; j<i; j++) {
   System.out.println(finalTemp[i][j]);
  }
}

You have at the inner loop: j<i Why? Why do you set the upper limit to be i? It should be the length of the array you are trying to read. With the way you have it, the first loop will not print anything since i would be 0. The next loop will print only one element. You need to put the length of the array. At the outer loop you put the length of finalTemp but in the inner loop the array you are looping is: finalTemp:

// rows is in fact finalTemp.length
for(int i=0; i<rows; i++) {
  for(int j=0; j<finalTemp[i].length; j++) {
   System.out.println(finalTemp[i][j]);
  }
}

finalTemp is also an array and you want to print its elements: finalTemp[j] . So its length would be: finalTemp.length

I assume that since the thread is marked as solved you have corrected that error on your own. But in case you didn't I posted

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After you read the first line of the file, don't add it to the list. It's that simple. Or add that if statement where you add elements to the list.

if (!line.equals("Name Age")) {
  // add to the list
}

And don't compare the list with a String: list.equals("name is age years old") list is not a String. Don't do that. Also the coding is wrong because by the time you reach that point the list has all the elements of the file, so it will never have only this value:
"name is age years old"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After looking at the code:
In the displayPeopleWithSameAge method, you are comparing the input with the current. But one is a String and the other a PersonNode.
Also you haven't implemented the equals method in the PersonNode class. Try this:

public String displayPeopleWithSameAge(String input) {

for(PersonNode current = head; current != null; current = current.getNext()) {
     if (input.equals(current.getAge())) {
         output += current.toString() + "\n";
     }
   }
   return output;
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post some code? The best way to do this is not just print the messages, but save the results of the file in a structure. An array or a list. Then loop the list for the display. When the user enters the age then loop again and print only those with that age.

So, where is your code?

minimi commented: Great help!!!! +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you submit to the next page read the value of the radio button and query the database based on that number. Then display the data from the DB.

What code did you use to display the radio buttons. I assume that the value of the radio buttons are the number(id) of the account.

<input type="radio" name="radioAccountNo" value="<%=accountNum%>" />

And the above is in a for loop with the name being the same and you change only the value.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry to barge in after it's been solved, but with the number being an integer to begin with, you could have written:

if (number<10)
   number*=10;

Also, nest your if/else; they way you wrote it: it will test all your conditions. If Number isn't < 10 it most certainly is >= than 10, so no need to test in that second if.

No that is completely wrong and you should read first the previous posts more carefully.
The idea is to convert the integer: 5 to: "05" With your way the number 5, would become 50!

Also a more simple way would be:

if(mNumber < 10) {
  m = "0" + mNumber;
}

When you concatenate numbers and Strings the conversion to String happens automatically. If you simply want to convert an int to a String then the above is not the best approach and use the method you are already using. But if you want to concatenate an int with a String then the above is simpler.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have a JFrame with a JTextArea and the buttons: Save, Load, Compile, Run. And a way for the user to select a file for loading or saving. (JFileChooser)

The user will write his code in the text area and with the buttons you will perform the actions.
Save: You will read what the user entered and save to a file.
Do the same for the rest.

For compile and run, I would suggest you study how to run command prompt commands with java using the Process class. Just run the javac command to compile.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't believe that you need to put login.java. When you create a servlet it is defined in an xml file where the name of the servlet is set as well as the java class file. So there is a mapping between the servlet name and the class file. Netbeans does that automatically so I believe that if you put action="login" it should work. That is probably the name that NetBeans has given

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

how should I set the data being entered by the user in main...please give an example how..

And what have I been doing in the last posts?
All that code and examples aren't they enough?

You have your main; you are already reading the data from the keyboard; and setting them to the array. The examples given answer exactly your questions. It is not as if I do not want to answer your question because I already have answered it. I even implemented one of the methods (add) for you, and told you how to do the others. Posting the same code and giving the same explanations is a waste of time. My time.

Antenka commented: WOW. That's even more than impressive. I think, this is the best example of patience, that I've ever seen. You'd be a great teacher ;) +2
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<a href="page.jsp?id=5">Text</a>

Or for a dynamic link jsp:

<a href="page.jsp?id=<%=id%>">Text</a>

Where 'id' is a java variable

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The suggestion you said to me makes my program more complicated....why don't you just help me how to solve it by editing my code...I also made an effort its just that i cannot figured it out...I want a help can...is that for you to answer thats a big favor im asking you I do an effort to that..so help me...

I told you exactly what you needed to do. It will not make the code more complex. For example in the add method I told you:
"
In the code when adding elements you add an element when the array is full which is wrong.
"
You have in the code:
if(isFull())
emplo[count++]=x;

I told you that you add the element when the list is full, which is wrong. How complicated would make the code correcting that?

In the search I told you to return the index not the element you search. All the changes are 1 line, ONE line.
You didn't bother to read them or try them.

The compile errors, which you didn't post, and you get, are very simple. Just read them and then read what you have written. When you declare a method to return a certain type, your return statement must return a variable of that type.

You made no attempt to fix your code with what I told you. It is as if you don't listen what I say.

tux4life commented: You've done enough effort. His lazyness is the bottleneck :P +8
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Add a Double object as attribute and when you get it, cast it to Double. Look at the java API for the class: java.lang.Double. It's a class like any other. Don't let its name confuse you. It's a class with methods and attributes.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, have you been told how will you need to read the input?
If it is ok to read the Names separately then you are fine.
If it is required to read once the whole string with the words then you can do what I suggested.
Remember, you can loop the String and get each character with that method. You can use the String.length() method to find the upper limit of the index.

My suggestion was:

"
You might want to loop the String and use the charAt to take each character, using the charAt. Have a new String an initialize it outside the for loop.
In the loop once you find an empty character, means that you have finished with a word so the next character is the first letter of the next word. Concatenate only the next character to the String.
"

If you can use any method to help you then you can use the split method, that will give you the words of the String in an array:

String s = "Dani A. Ona";
String [] tok = s.split(" ");

// tok now is an array with elements:
// tok={"Dani", "A.", "Ona"}

Now you can loop that array and get the first character of each element, but you need to make sure that you are allowed to use that method. Maybe not if you said that you can use only the charAt.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you written any code or, you used exclusively the gui builder for that?

You should learn how to code those events. How to add action listeners to your buttons. You need to read some tutorials and try to make that gui on your own.
Just declare those components and add them to your main JFrame.
Classes you will need:
javax.swing.JText (for text fields)
javax.swing.JLabel (for labels)
javax.swing.JButton (for buttons)

Check the API for their methods and constructors.

And if you are a beginner then this project way too much for you. You will one main JFrame with buttons like a menu where you need to select if you want to add a new contact or view the existing ones. Those would be independent classes/JFrames. Once one of those buttons is clicked you need to call its class by creating a new instance of that JFrame and display it.

Assuming you have classes for adding and viewing that extend JFrame: JView.java, JAdd.java.
Then depending on the button clicked:

JView view = new JView(); // JView extends JFrame
view.setVisible(true); // method inherited from JFrame
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can you gave us a running program about selection sort that the user will input something from the keyboard...thank you...

NO.

Start a new thread. There are plenty of examples on how to read input with the Scanner class. Start a new thread with some code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do have the JAVA_HOME environment variable set. After doing some searching, and now I remember that I had the same problem, I found that you have to put first the latest java version that you are using when declaring that variable. You must also set your classpath correctly in order to use the latest java version when compiling and running

After very little search, I found this page:
http://www.devdaily.com/blog/post/java/java-lang-unsupportedclassversionerror/

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I wrote my version using your code. I used the JPanel class. I declared it as an attribute of the class so I can have access to it in the method that handles the double clicking.

package stam.bar;

import java.awt.event.*;
import javax.swing.*;

public class SimpleFrame extends JFrame implements MouseListener {
    private JLabel lb1 = new JLabel("Hi 1");
    private JLabel lb2 = new JLabel("Hi 2");
    private JLabel lb3 = new JLabel("Hi 3");

    private JPanel panel = new JPanel();
    
    public SimpleFrame() {
        setSize(300, 300);
        
        lb1.addMouseListener(this);
        lb2.addMouseListener(this);
        lb3.addMouseListener(this);
        
        panel.add(lb1);
        panel.add(lb2);
        panel.add(lb3);
        
        add(panel);
    }

    public static void main(String[] args) {
        SimpleFrame simpleFrame = new SimpleFrame();
        simpleFrame.setVisible(true);
    }
    
    public void mouseClicked(MouseEvent e) 
    {
        if (e.getClickCount() == 2)  
        {
            if (e.getComponent()!=null) {
                panel.remove(e.getComponent());
                repaint();
            }
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }
}

I my version I add the mouse listeners directly to the components: lb3.addMouseListener(this);

LianaN commented: thanks. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yes that's right I wanna the code of the keyListener???
and moving could be timer..

Code For KeyListener

You could have also found that on the net

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use the String class. Specifically the split method. Check the String API for that method:

String s = "Bleach,22,13,TiteKubo";
String [] tokens = s.split(",");

//Now print the array and see what happens:
for (int i=0;i<tokens.length;i++) {
  System.out.println(i+": "+tokens[i]);
}

System.out.println("-----");

System.out.println(tokens[0]);
System.out.println(tokens[1]);
System.out.println(tokens[2]);
System.out.println(tokens[3]);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know your logic, but what if you try this:

class MultiThreader {

    main(...) {

 
       new MultiThreader().jobSpawner(jobName);
    }

    void jobSpawner(String jobName) {
        new Thread(new JobThread(this, jobName)).start(); // use 'this' here
    }

}

In this case the 'this' would reference the instance that is created in the main:
new MultiThreader().jobSpawner(jobName)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
new MultiThreader().jobSpawner(this, jobName);

'this' is a key word that can be used in a class only by its class members and it used to call class variables and methods:

private int a = 0;

public void setA(int a) {
  System.out.println(this.a); // it will print the value of the 'a' class variable
  System.out.println(a); // it will print the argument.

  this.a = a; // it will set the value of the class variable to be the argument
}

You cannot use the 'this' in a static method like the static void main()

In the main method you need to pass a instance of that class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just to add something to jon.kiparsky's good advice, each object has a toString method, whether it is overriden or not. Even the ArrayList.
If an ArrayList has String objects:

ArrayList<String> list = new ArrayList<String>();

list.add("aaaa");
list.add("bbbb");

// They both do the same
System.out.println(list);
//or
System.out.println(list.toString());

Then the above code will print all the Strings in the list, because that is how the toString method of the class ArrayList is overridden. What it does, it returns all the Strings in that list.
Meaning,
if you add any other object in the ArrayList, then again, the toString method of the ArrayList, will call the toString method of each of the objects in the list and return that:

Try this.

class Person {
  private String name = null;
  private int age = null;

  public Person(String n, int a) {
     name = n;
     age = a;
  }

  public String toString() {
     return name+" is "+age+" years old";
  }
}
ArrayList<Person> list = new ArrayList<Person>();

list.add(new Person("Aaaaa", 10));
list.add(new Person("Bbbbb", 20));

System.out.println(list);

So you can call the toString method of the list and append that to the JTextArea, or you can loop it and append each object in the list in any way you want.

In addition you can look the class JList. You can also add objects in the way you add them to an ArrayList and the toString method of each of those objects will be displayed like a list. It has a better looking …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is the same question you asked in one of your previous threads:
http://www.daniweb.com/forums/thread305019.html

You got answers to that thread. If you didn't like the answers don't start a new thread.

In that thread we asked what a "picture puzzle" was and got no answers. Instead you created a new thread with the answer of our question. It is like you ignored our attempts to help you.

As for an idea.
Use JLabels or JButtons that display different images and have one button with a blank image. Once a button is clicked, check if it has an empty space next to it (the button with no image). If yes, swap the buttons images.

Check the JButton class API to see how to add images to a button.
Also read some tutorials about swing, on how to write ActionListeners.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Whole code for your pleasure to read it and use it here

I don't know why but that link doesn't work for me. I get an error saying that I can not access the page?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

dude actually i m not intrested in software develoment field....m focusing on n/w oriented career..

I m in final yr engg nw.....project work is compeltion part!!!

evry1 has diff choices....

nys will focus on ur rply 2...

thanx....

First of all If you have read the forum rules you would know we don't give homework and it also against the rules the way you talk:

i knw dis man...also ashamed 4 d same..
i nvr took ny of languages seriously.....
i hav 2 mail till 2mrw...
nys thanx 4 all ur concerns...

Use proper english! One of your previous post doesn't make any sense!

And if you are not interested in software development field then this sponsorship is not for you because it requires some programming skills .

And if you have to mail this by tomorrow, how long ago was this assignment given to you?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why should we write such program. I have no use for that, and I am not interested in finding the longest substring in two given strings that is common to both. Some things are better left unknown.

If you want to find the longest substring in two given strings that is common to both then show some effort by posting some code and ask your question in a better manner.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you have a small misunderstanding with that logic. The API says:
"The ordering imposed by a Comparator c on a set of elements S is said to be consistent with equals if and only if "

The API says at some point that the compare method does not have to be consistent with equals. Even if you implement it, you don't have to make sure that when equals returns true the compare method will also return 0.

The API only said:
"The ordering imposed by a Comparator c on a set of elements S is said to be consistent with equals if and only if "
They don't have to have the same behavior. It simply stated that if you want to say that they are consistent, the equals must behave like the compare. If they don't then that is also ok.

Also this: "if the compare function serves the test for equality too"
That is wrong. Just because 2 objects are equal with each other doesn't mean that their compare methods will return 0 and the other way around.

And we do need both.
Equals for determining equality and compare for sorting. Some classes like java.lang.String are consistent. The compare method and equals method have the same results. Others not.

And a practical example why they are different:
Assuming you have a person class with an id and a name:

class Person {
  private int id …
stephen84s commented: Good Explanation +5
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

" I had already describe what my requirement was. Why you always go to swing application? I'm not using any swing application. Is font colors only applicable to swing application or what? I'm asking simple one that how can we change the font colors in simple java application program. I already give an example to compate with html. U are failed to understand the threads properly. Read the thread again and give the answer properly if u can.

In what kind of java application you are referring to?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So after going over this a few times I found that the issue was with the 5/9 and 9/5. For some reason Java was not calculating them correctly so I had to input the decimal equivalents instead.

You were right ti out the decimal equivalents, but java was calculating them correctly:

9 is an int
5 is an int
When you divide 2 ints, another int must be the result.
So the result should be:
int/int = int
9/5 = 1

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is not a good example and it is a bad way to do things. Not to mention that the OP said nothing about html code.

Only the database connectivity is almost ok. You forgot to close the ResultSet, Statement and ResultSet.
First: How do you know that the table entered at the field will always have 2 columns.
Second: Never put html code in servlets. Read the data from the DB, put those into an array of objects using OOP, and then send the array of objects back to a jsp through the request in order to be displayed at the jsp page.

Of course the above would have been helpful if the OP has said that the whole application would be web application.

ali.nazia999 commented: good +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You hardly use session. Maybe you should put it in request and use request dispathcer to send the request to another jsp or servlet.
Use the request.setAttribute(String, Object) and the request.getAttribute(String)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the button is clicked you can hide, or better dispose(I think that that is the name of the method of the JFrame class) and create new window.

class JLogin extends JFrame ... {

..

  public void methodUsedWhenLoginButtonClicked(ActionEvent evt) {
      JMainPage mainPage = new JMainPage();
      mainPage.setVisible(true);
      this.dispose(); // use this if you don't want to keep the state of the class. Meaning if you want to close completely the window and forget lose all the values of its attributes.
  }

..

}

For making a back-forward page:

class JFirstPage extends JFrame .... {
   private JSecondPage secondPage = null;   

   public JFirstPage() {
     super();
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      if (secondPage==null) secondPage = new JSecondPage(this); // passing it to the next window
      secondPage.setVisible(true); // showing the next window
   }

}
class JSecondPage extends JFrame .... {
   private JFirstPage firstPage = null;   

   public JSecondPage(JFirstPage firstPage) {
     super();
     this.firstPage= firstPage;
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      firstPage.setVisible(true); // showing the previous window. Keeping ALL the values it had (the values of the text fields or anything else)
   }

}

With the first way you "dispose" the window and you lose the values it had and if you want to open it again, you need to make a new one.

With the second way you pass the same instance to the other window through the constructor and you can hide or show which ever window you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to put all of your components JtextFields, Jlabel as global variables and have them all visible.

When you click add, you will take the text from all the fields and add a new person.

When the use clicks search, even though all the fields would be visible, you will take the value only of the 'name' field, search that person and then display its info at the other fields.

The same for delete or update.
One easy solution, like I said is to have all of them visible and depending on what was clicked to take the text only from the fields that you need them.

For showing all of the persons, you can add a JTextArea and when the button 'show all' is clicked you can show all of those persons there.
Since you have overridden the toString method, which is a good thing you can also use a JList to display all the persons.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The idea is not to get output, since all it does is save to a file.
By the way you have a mistake. This is the correct one:

for (int i = 0; i<data.length; i++){
	        	      for(int j = 0; j<data[B][i][/B].length; j++){
    ....
    }
}

Also try to close the PrinterWriter at the end:

import java.io.*;
import java.util.*;

public class TestingII {
	
	
	public static void main(String[] args){
		int[][] data = {{1,2,3,4},
						{5,6,7,8},
						{4,9,1,0},
						{2,5,8,3}};
		Scanner stdIn = new Scanner(System.in);
		PrintWriter writer;
	 
		try
		{
			System.out.print("Enter a filename: ");
			writer = new PrintWriter(stdIn.nextLine());
			for (int i = 0; i<data.length; i++){
	        	      for(int j = 0; j<data[i].length; j++){
	        		    writer.print(data[i][j] + ",");
	        	      }writer.println();
			}	
		}
		catch (FileNotFoundException e){
			System.out.println("Error: " + e.getMessage());			
		} [B]finally[/B] {
                          try{if (writer!=null) writer.close(); } 
                         catch (Exception e) {System.out.println("Could not close writer");}
                }
	}
}

Also I don't know the API of the PrintWriter but I assume that it takes as argument a String, which the way you have it

kdott commented: thanks for the help! +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

To find the mode you have to find the number that has been repeated the most in a sequence. You could use a loop to check this.

If that is true about the mode then since you have this rule:
if(input>=1 && input <=1000)
You can do this:

int [] array = new int[1000];

The input given would be the index of that array, and whenever you enter a number increase the index:

int [] array = new int[1000];
if(input>=1 && input <=1000){
   total = total + input;
   array[input-1] = array[input-1] + 1;
}

For example if you enter '3' 5 times then the: array[[B]2[/B]] would have value 5. Then find where the max of that array is the index would be the number with the most occurrences:
[0]: 1
[1]: 2
[2]: 6
[3]: 3
[4]: 5

Number 3 was entered 6 times.
Find the max number which is 6, that would mean that the index 2 was given 6 times.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No one understands what you say. Use proper English and code tags. Press the code button when you make a new post and put your code inside. It makes your code easier to read.

Also please don't do this: "plxxxxxxxxxxx" It is against the forum rules and annoying.

stephen84s commented: *nods* +5
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And may I add that you need to declare the temp array in the main. Also, I don't know if it is a problem with copying your code, but you have 2 main methods.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because in the same file, you declare 2 classes:

class threads implements Runnable {
  threads() {

  }

class ThreadStarter {

}
}

You don't need a separate inner class for the main. Just put it in the threads class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The shorthand method returns a String. So call it with argument the line given and print what it returns:

String result = shorthand(s);
System.out.println(result);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are other loops as well. Not only the for loop. And check the API. How on earth did you came up with this: sc.length . You cannot just call whatever methods you imagine. That is why you have the API. To see which methods each class has.

Scanner sc = new Scanner(System.in);
boolean cont = true;

while (cont) {
   System.out.println("Enter value:");
   String s = sc.nextLine();

   if ("*".equals(s)) {
     cont = false;
  } else {
     // do stuff with the 's'
  }

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Asking others to do your homework is against the rules.
Asking others to do your homework for money is an insult to the people here.
Asking others to do your homework for that small amount (20-40) of money is an insult to the professionals of this forum that get paid thousands of dollars and offer their help here for free!

What I also find insulting is the fact that you said:

You need to have an understanding of UML as well

as If, if someone wishes to do your work for you, you will turn him down for not knowing UML.

Salem commented: Well said! +20
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Even if we wanted to give hints in order to get you started, the description you posted is impossible you understand:

Construct a dissimilarity matrix ā€˜d’
using the measurement in definition2.

What is this suppose to mean?! Don't assume that we are in your class and know what you are talking about.

And don't post your email, it is against the forum rules. Also if you want some help start by showing what you have so far.

Salem commented: We aren't in their class - unfortunately, they're not in their class either ;) +20
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

(Can i get the class name of Class1 using c)??

BestJewSinceJC's answer was not wrong.

But the answer to the above question, is no. After taking the 'c' instance you cannot programmatic-ally know in which class it was created.
Unless you make some changes.

As BestJewSinceJC said inside method1 you know that you are inside the Class1. So change the Class2 constructor that takes as argument an object. And whenever you create a 'Class2' pass as parameter the object in which Class2 was created. Or better pass the Class of that object.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all learn how to read data from the database and proper OOP.
When you copy code you must understand what it does. Not use it blindly:

while(res.next()){
                count ++;
            }

            res.beforeFirst();
..

Where in your code you use the 'count' variable and what is its purpose? Do you understand what that code does? If yes, then why do you use it, since you are already using Vector. When you have vector you don't need the total count.

Also this doesn't do what you think:

while(res.next()){
                roomDetails.add(res.getString("roomType"));
                roomDetails.add(res.getDouble("roomRate"));
                roomDetails.add(res.getDouble("discountRate"));
                roomDetails.add(res.getString("discountValidityStart"));
                roomDetails.add(res.getDouble("discountValidityEnd"));

                hotel.add(roomDetails);

            }

You add data in the roomDetails and then add it to the hotel vector. But at the next loop you add the next row to the same roomDetails instance!!!

After the first loop the roomDetails has: {roomType,roomRate,...,discountValidityEnd}.

After the second loop roomDetails has:
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd}.

After the third loop roomDetails has:
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd}.

Because you add them at the same instance.

And then you add the same instance to the hotel Vector. That would mean that all the elements of the hotel Vector are the same roomDetails instance, meaning that all the elements of the hotel Vector have something like this:
hotel = {
{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},

{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},


{roomType,roomRate,...,discountValidityEnd, roomType,roomRate,...,discountValidityEnd,
roomType,roomRate,...,discountValidityEnd,.......},
....
}


The answer:
Declare a class: HotelRoom with attributes: roomType, roomRate, ....
Inside the loop, …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is also could to close what you open. And you also forgot to return the array and increase the index 'i' :) . May I post some similar code?

public class UCTest{

	public String[] run() throws SQLException {
		Connection con = null;
                Statement stmt = null;
                ResultSet res = null;
                String[] test = null;
		try{
			con = new database().getConnection();
			stmt = con.createStatement();

			String sql = "SELECT * FROM test";
			res = stmt.executeQuery(sql);

                        int count = 0;
                        while(res.next()){
                            
                            count++;
                        }
                        
                        res.beforeFirst();
                        int i = 0;
                        test = new String[count];
			while(res.next()){
                            test[i] = res.getString("Q1");
                            //// Continue code from here for obtaining answers

i++;
                        }

                }catch(SQLException e){
                    e.printStackTrace();
                } finally {
                   if (rs!=null) rs.close;
                   if (stmt!=null) stmt.close; 
                   if (con!=null) con.close;
                 }
                 return test;
	}
}

And if you want to return more columns you'd better define a class with attributes the columns and return an array of that object.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The updateHealth method is of the LittleAlien class, so in the method Caught, you can do this:

public void Caught(LittleAlien aLalien)
{
   aLalien.updateHealth();
}

Also more code would be required. And I don't think that LittleAlien should extend BigAlien, but I could be wrong. Post your requirements as well.

ttboy04 commented: 1 +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am sorry for not reading the entire post. I focused on the code.
...
I think I noticed something that might be the solution. Maybe by the time you read this, you have seen it too, or it is just a typo while you were posting the code:

<select name="[B]lista1[/B]" id="lista1"></select><br/>

String name1 = request.getParameter("[B]list1[/B]");

Try this: String name1 = request.getParameter("[U]lista1[/U]"); Instead of this:" String name1 = request.getParameter("list1"); If this doesn't solve your problem, can you post some more code?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Print the query that you are executing:

String query = ".....";
System.out.println(query);
i1=st1.executeUpdate(query);
System.out.println(i1);

What does it print?
Also try to take the query that was printed and run it to an sql command promt.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is is against the forum rules to spam; and any other forum. When you have nothing useful to add or post new information dont post at all.

ProgrammersTalk's post which was quoted in peter_budo's reply was such:

that's just the same thing haha..

What did it contribute to the discussion? How was it helpful for the question that was initially made. It dind't do anything. So posting to a thread to say nothing is against the rules. You may don't know it, but in this forum such as others, there are sometimes people that just make posts that say nothing just for the reason to increase their post counter.

I am not referring to your post, but to the post that had no contribution and resulted in peter_budo's intervantion.

Also your post is a total violation to the rules. And if you start talking about freedom, then when people sign in there are rules to follow. No one is forcing them to sign in and no one is forcing them to stay to this forum. But they have agreed to the rules. So they must follow them.

You critised others without helping anyone. And I am not saying that you are not allowed to express your opinion, I am saying that in this forum, we don't critise others, we help people with their code. I would like to see you do that some time.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

SELECT col1, col2, .... FROM table_name