javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Lines 74 to 84:

catch(FileNotFoundException fnfe)
{
   System.out.println("File Results not found.");}
catch(IOException ioe)
{
   System.out.println("Unable to read from Results");}
   return area;
}

As you can see you are missing a bracket. And here is a tip for the future.
Whenever you open a bracket immediately close it, and them start writing code inside it. If keep opening and writing code, then there is no way to remember of find where to close.
And I hope that you leave tabs when you open brackets:

if () {
    if () {
         for (;;) {

         }
         while () {

         }
    } else {

    }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, can someone explain to me what he said?:

Ezzarel you dont havta reply to this prolly think I am the biggest idiot living but I still am having problems with this program...I tried movin a bench of stuff around but just went back to this w\some minor changes and still havin problems

Because my English are not that good

And it seems to me that Ezzarel has told you the solution. If you don't understand it then learn basic java and don't stuff like gui

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also something that I forgot:

select username,password from user where username=? and password = ?

I hope that you have a table named: user at your database, with columns: username,password

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you are using PreparedStatement and not the simple Statement then change this:

pstat = conn.prepareStatement("select username,password from user where username='"+ username + "' and password = '"+password+ "'"); to this:

pstat = conn.prepareStatement(
"select username,password from user where username=? and password = ?"
);

After you get the resultSet and call its methods(rs.next()) and before you break, you must close everything:
rs.close();
pstat.close();
conn.close(); Note: if you want to run a query again, you must reopen the connection, so it would be better if you put the code that opens it in some method so you can call it whenever you want to open a connection

Next time besides the code, post the errors you get and at which line

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public static void connect()
{
		Connection conn = null;
// the rest of your code

}

At the above method which you wrote, you correctly open a connection to the database. But the conn variable is declared inside the method locally. You cannot use it outside the method and it has no meaning, because as soon you open the connection, then you close it.
You can change the method to return the connection. Remove the code that closes the connection.
Then in another method as I said you will use the connect() method to get the connection to run the query. Then when you get the result form the query and store it in variables, close the connection and return true or false whether the user can login or not.
You will call this method where you get the username and password from the gui.

If you don't understand this then you don't know the basics of java or OOP, so don't just copy code from books (connect method) if you don't know what it does.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is your code?
Do you use: resultSet.getString(); or resultSet.getDouble(); ?
Perhaps you can do this: double d = Double.parseDouble( resultSet.getString(3) );

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The connection class should be declared outside the method connect() and take value inside it. In the way you have it, you create a new connection and when the connect method finishes, you can not use the conn variable since it is out of scope.
Have a method the takes as arguments username, password and then inside create the query, call the database and check if the arguments are valid. Then return true or false.
Take the username, password from the gui and call the previous method.

String s = "select username, password from table_users where username = '"+ username +
"' and password = '"+password+ "'";

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Store them where? Because you are already storing them in varables:

int frow = Integer.parseInt(st.nextToken());
int fcol = Integer.parseInt(st.nextToken());

Where you want them to be stored? You can put these variables wherever you want. Perhaps create a new class for each line and put those values in the class and then store each class in a Vector

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does it execute, and does it print what you want? And what are these things at the end of your post:

<br />import java.util.Scanner;<br /><br />/** A class which hold the Lyric in an array of String */<br />public class Lyrics<br />{<br /> String[] song = {<br /> "My Bonnie lies over the ocean", <br /> "My Bonnie lies over the sea", <br /> "My Bonnie lies over the ocean", <br /> "Oh bring back my Bonnie to me", <br /> "Bring back, bring back", <br /> "Bring back my Bonnie to me, to me", <br /> "Bring back, bring back"<br /> };<br /><br /> // method that returns the song<br /> String[] getSong() {<br /> return song;<br /> }<br /><br /> // static method to do the job<br /> public static void main (String[] args)<br /> {<br /> // pickup by what replacing "Bonnie"<br /> String name;<br /> Scanner scan = new Scanner(System.in);<br /> System.out.print ("Enter the name of the user: ");<br /> name = scan.next();<br /> // Get an instance of Lyrics<br /> Lyrics lyrics = new Lyrics();<br /> // Get the song lines<br /> String[] str = lyrics.getSong();<br /> // lopp thru all lines<br /> for(int i = 0; i < str.length; i++) {<br /> // replacing "Bonnie" by the name I have scanned<br /> System.out.println(str.replaceAll("Bonnie", name));<br /> }<br /> } // end of main method<br />} // end of Lyrics class<br />

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At what line do you get it, and can we see some more code (the class Item for example)?
But in general this exception happens when you try to cast something that cannot be casted.
Probably the hash.get(info) does not return Item but String, but I cannot be certain about this if you don't show a little more code and where do you get the error. It could be something else.


PS: I have fixed my internet at home. The modem that the manual was describing was not the one that they have sent, so the line connections where wrong.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't need this: public static double

At your system.out, instead of Bonnie, you will have a variable. And according to your assignment the user will give this value from the keyboard.

And from what I see the song has many lines that repeat so you can store these lines to variables and print them instead of having to write them all over again.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I wrote:

Why did you create a new thread and ask the same question? If you didn't understand my answer at the previous thread then ask for more details or ask a better question.

I would like to apologize to both of you and whoever read this thread. I am sorry for the way I replied and I made a very big and silly mistake. Yesterday I was preparing a reply for this thread but before I submitted my internet connection went down and I could not connect again. So naturally I didn't submit any answer to the question. But I forgot about it, and today when I saw the thread again I thought that it was a new thread because I was so sure that I submited yesterday, but I didn't.
So I would like to apologize again for my manners and especially to KimJack.

Ezzaral commented: hehe oops! These things happen. +7
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You could use the time in millis and take the last digit:
System.currentMillis(); if I remember correct the method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The data would probably be inside an array. Write a write-loop that reads the array and checks every element if it is 12. Then break from the loop because you only need the first. After you print the result then write another while-loop that reads the array backwards and does the same thing.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why did you create a new thread and ask the same question? If you didn't understand my answer at the previous thread then ask for more details or ask a better question.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are only reading the word to censor. You should read the word that will replace the first word you read, as well as the text in which you will search for the word to censor.

I think that the : keyboard.nextDouble(); returns double
You must declare a variable in which you will store the input:
This is wrong: String = keyboard.nextDouble();
This is correct: String s = keyboard. (i don't remember the method'S name)


In this line: System.out.println(altstring); you don't define altstring. You don't give it any value nor you declare it.

The variable sentence should be read from the keyboard. It is the text in which you will search for the word to censor.

You are correct to use the split method and search for the word to censor.
But inside the if you are replacing the entire sentence. Instead you should only replace the censored word:

for (int j=0; j < temp.length; j++ )
{
 if (temp[j].equals(wordToCensor))
 {
  temp[j] = replacementWord
 }
}

Don't forget that wordToCensor, replacementWord should be read from the keyboard with Scanner at the begining of the program.

After the for-loop just add another loop that prints the array temp that has the censored words replaced.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you are a beginner in Java and you cannot understand this thing how can you expect write something as complex as an emaiSender combined with GUI. Even I don't dare to try this.
What he told you is that inside the main there are commands that are executed one after the other. You need to run those commands at you gui. But you cannot use the way they are. You separate them inside methods and the arguments will be given from the gui.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you can have only one compareTo method, meaning that you can only have one rule for sorting. You cannot dynamically choose based on what you will sort. That is defined in the compareTo method. When you implement the method it will only sort based on that. If you want to sort using something else you will have to change the method.
The sort method of Collections will use a specific algorithm for sorting. As you know any sorting algorithm compares the elements it will sort with each other in order to see which is greater or lower in order to sort them. But how will the sort method of Collections determine which is greater or lower in order to sort them? It will use compareTo method and you will have to tell it when it compares two elements which one is greater or lower in order to do a swap or whatever the algorithm does.
So, when you have two objects, and someone (like Collections.sort()) asks you: Which one is greater?, what will you tell him? I will tell him for eg. that the first is greater because the variable height is greater (or lower, do whatever you want) than the other's objects.
So how will you compare these two BookingResponse objects. What will be the answer to the above question? If you want them to be sorted based on the Origin, then decide which object's Origin is greater, lower or equal than the …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think I found it. Under your first post there is a link "Reply to Thread" with orange background and an arrow. Next to it, there should be what you are looking for. It is above the area where you can post a quick reply

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Somewhere in this page there has to be a link that says Solved

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the compareTo method you will say how you want the objects to be compared.
Assume you have an Object with attributes name, height and weight.

If you want them to be sorted based on the height. write: (I don't remember the exact signature of compareTo so just pay attention to what is inside)

int compareTo(AnObject obj) {
 if (this.height>obj.height) return 1; //a positive number
 if (this.height<obj.height) return -1; //a negative number
 return 0; //if both heights are the same
}

Do the same if you want them to be sorted based on their weight.
Remember that equals is used for comparing if two objects have the same values so when the compareTo returns 0 doesn't necessary means that equals will return true. It may do, it do not.

About your case based on what you want them to be sorted? if it is based on Origin as you said, and if Origin is String then:

int compareTo(BookingResponse obj) {
   return Origin.compareTo(obj.Origin);
}

Or you can use your own criteria. Just remember to return positive, negative or 0 depending on how you want them to be compared

Ezzaral commented: Clear and helpful +6
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One thing I forgot. The compareTo method will compare the objects in any way you like. Meaning that in your case you will only use the Origin in order to compare the objects. If it is a String use the compareTo method of the String class as your return statement.
And as you will read if you return 0, the equals method doesn't have to return true.

Meaning that you might want to sort two object based on the 'age' for example but the equals method will use the 'name' in order to determine if they are equal. That is for a hypothetical Person object

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I believe that the Collections class has a sort method: Here is what you must do:

Your object that you put inside the ArrayList has to implement the Comparable interface. When you do that you will have to implement the compareTo method that compares this object with another object. This method returns a positive number if this object is greater, 0 if it is equal and negative if it is lower.
Check the API for the Comparable interface and the compareTo method.

Then use the sort method of the Collections class that is static and takes as argument your ArrayList.
Check the API for the classes: java.util.ArrayList , java.util.Collections, java.lang.Comparable
If you don't know the links for the API's let me know

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just count how many braces you have opened and how many you have closed. Make sure that when you open a brace you must close. So don't open a brace, start writing and then after lots of code try to remember where to close it.
What you should do is whenever you open something, immediately close it and then write the code inside it. That also includes parenthesis. Also this is also possible:

{
  {
  }

  {
  }
}

Meaning that when you try to close the braces you must make sure that all the other braces inside it are closed
One last tip: When you open a new brace write it a <tab> or a few spaces to the right than the previous brace:

{
  {
  }
  
  {
    {
    }
  }
}

That way you can monitor better what you open and close

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The java way to do it is to create a class with attributes: CountryName, CountryID
Then create a method that runs the select-query, gets those values from the DB and puts them inside a Vector or ArrayList of that class and then of course return it.
Since you have the results you can do them whatever you want.
It is better to have separate classes that do stuff with the database and return the results. Then use those methods/results in any way you want. Don't mix inside the code queries that get the results and then manipulate them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It would be if you use one for-loop instead of 3. You could have 3 boolean variables inside the for-loop taking values true or false depending on the current character. And at the end check if all of them are true

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you importing any of the packages that these things are?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What did you try to do? and what errors do you get?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where exactly do you get that NullPointerException because I don't think that people will find it easy reading your whole code.
And it is probably because you are using an object that has not been instantiated. Use the "new" word.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Instead of a second frame use a dialog box. Read in this JOptionPane the static methods that begin with show...(...) .

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will never get inside the while loop because you set count=0 and you don't know what x or y will be. Since you are setting x to be you starting number try this:

int x;
int y;
int div=2;
int count=0;

System.out.println ("Enter the starting point N:");
x = user.nextInt();
System.out.println ("Enter the ending point M:");
y = user.nextInt();

[B]count=x+1;[/B]

while (count<y){
//your code here

//in the end:
count++;
}

or try this:

for (int i=x+1;i<y;i++) {

}

By the way what kind of algorithm will you use?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is the one I use

BufferedReader USERIN = new BufferedReader (new InputStreamReader(System.in));
String s=USERIN.readLine();

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since the switch can only use char or integer, you have two solution:
Parse what you are reading to an integer or a char:
Integer.parseInt(input); for integers or for chars:

if (input.length()==1) char ch=input.charAt(0);
  else {//error}

Make sure that you entering valid values ( use try {}catch() {} )

Or use if () {} else if () {} statements instead of switch with input.equals("") inside the if( )

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have read with more attention your post and I think that when you get the salary you can print it with a '$' at the beginning. I don't know if this is what you want because it sounds to easy:
String salary="20.00";
System.out.println("$"+salary);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Personally I have no idea what are you talking about. If you want to change a String to int then use:
String s="2";
int i=Integer.parseInt(s);

The rest of your post don't make any sense

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Instead of Arete use this.x=x;
Arete.someVariable is used when the variable is static

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is it because you haven't declared a constructor with 3 doubles as arguments? Or somehow your class can't "see" the constructor because you haven't import the BoneNode class?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hey I just asked for help, you dont want to help dont answer!!! So easy!!! Many people have problems with some things and it doesnt mean they are more stupid then others!!! I dont like this module and its none of your bussines how I want to pass it and if I will pass it so put your noses where they belong and dont comment me!!!

Answer what????? You didn't even asked a single question!!!! All you said is that you are having problems with one of your courses. Are we supposed to predict your homework and do it for you?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Contact you and say what? You are the one who is supposed to post your code and ask questions in order to get help. How are we supposed to give answers when we don't know what you want. And it is better to post you question here where everybody can see it and answer it, than expect the answer from one or two who will have you e-mail.
Even if we can see your mail here, why send you our replies through it and not this forum? what would be the point of this forum then?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

FileWriter write = new FileWriter("CropSystemDatabase.txt", true );

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And the last System.out.println(); outside of the second while loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi and welcome

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Probably because there isn't such constructor.
API for Byte object
API for Short object
The values in the parenthesis are not treated as byte and short but as int. I haven't try this and I don't know if it will work so don't blame me, but try:
Byte b = new Byte( (byte)3 );
Short s = new Short( (short)34 );

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Nothing is necessary. You can write anything you want in any way you want. In the end it is experience that will tell you when it is better to use servlet to handle the request from the jsp file or just just handle it in the same page by setting action in the form tag to be:
<form action="" ....> If you need to use and declare a lot of methods in order to use them then you use servlets. Or in some cases you can have more than one jsp (whose requests have a common behavior) to go in ONE servlet, handle the request, and then depending on the results you can have more than one selections as in which jsp to go next.
If you need to submit a form and then just display the results in the same page, then one jsp that submits to itself is enough.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest creating a class with attributes the ones you have described in your post:

Trip date (Date)
Start destination (String)
Ending destination (String)
Mileage (double)
Cost (double)

Then create in another class methods for writing and reading files the above information taken from the classes. (The floppy disk is just another file. Instead of typing C:/somefile... you can type A:/somefile... so don't let this write to floppy scare you)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok then, sorry about my comments concerning the second loop.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didn't have time to post the solution in my previous post, so here it is:

String hrname="(";
for(int k=0;k< my_arr.length-1 ;k++)
{
  hrname+="'"+my_arr[k]+"',";
}
if (my_arr.length!=0) {
  hrname+="'"+my_arr[my_arr.length-1]+"'";
}
hrname+=")";
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi ABhi,
Try Like this...

String hrname="(";
for(int k=0;k<my_arr.length;k++)
{

  hrname+="'"+my_arr[k]+"',";
}
hrname+=")";

for(int i=0;i<my_arr.length;i++)
{
query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";

}

Sorry to break this to you but what you wrote is totally wrong and you are going to do serius damage to the kid who asked for help:

To start with:the first for-loop will end with the command: hrname+="'"+my_arr[k]+"',";
Meaning that after the loop the command: hrname+=")"; will generate this String:
hrname = " ...... ',) " . As you can see the comma before the parenthesis will generate an sql error.

The second for-loop is completely unnecessary. You don't use the index i, and you simply assign to the variable query the same String over and over again.
I think that you don't need the loop and only the assignment:

String query = "select * from my_table where HR=(select max(HR) from my_table where FirstName not in "+hrname+")";
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I agree with you guys(Ezzaral, masijade). I have seen many threads here where people just post the code, the line the error is and the message the compiler gives. But the compiler explicitly says what EXACTLY is the problem. It says the line and explains the problem and sometimes says what it needs to be done to fix it. Don't they know how to read? In most cases the answer to those threads would be repeating the compiler's message.
Nowadays there are IDE's that show where the error is, with messages before even compiling (NetBeans) AND with code completion. This is so much easier than my time where I had to write FORTRAN code using UNIX vi editor and compile it at UNIX. Today kids don't want to put any real effort.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know, there are many ways to do things. Just try it to see if ti will work for you.