javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your latest code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Who gave you that ?!
Better star over

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also what will happen if the animalID is 3000? Look at your code. Maybe you need to add some >= to one of the expressions you have in the ifs

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you imported DecimalFormat? import java.text.DecimalFormat;

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is the html code you are displaying at the page:

<a href=\"welcome.jsp\"> </a>

But there is nothing between the <a> </a> , so the link is there and you can click it. The problem is that you don't display anything to show the user where the link is:

<a href=\"welcome.jsp\">Click me</a>

And finally. DON'T DO THAT. Remove the code you have in the welcome.jsp. Put all the database code in a separate class inside a method. Call that method from the jsp. And I would suggest if the login is successful not to show a link that goes to the same page.

From your code you send the username, password to the welcome page, and if the login is successful you again show a link to go to the welcome.jsp. Shouldn't go to the main page?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am not familiar with Derby, so I would like someone else to help if they can.

What I could suggest is this:

Usually I use this method: conn=DriverManager.getConnection(dbURL,username, password); Try to use that, and print the values of the variables you are using to see if the dbURL is correct. Maybe the name of the property in the Properties class is not the one the Derby expects.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At that line something is null:
at model.dao.ConnectDerbyDAO.createTables(ConnectDerbyDAO.java:158)

My guess is the connection. So try to go to that line and print the objects you are using.
Also you need to close the connection, statement in the finally block.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then create instances of the BinaryNode class and construct the tree by giving values to the .left and .right nodes. Then call that method with argument the root node.

For reading input use the Scanner class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If someone could code this program by 5/9/10 it would be great.
Thanks!!

When was this assignment given to you?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One suggestion was to display everything and get the value you want from them according to what was clicked.

But given your questions, it is best to search some tutorials about gui and try simpler things.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public class Agenda1 extends JFrame implements ActionListener {
   searchButton.addActionListener(this);
}

If you want the actionPerformed method to be called when the button is clicked you need to add a class that implements the ActionListener interface:searchButton.addActionListener(this) Agenda1 implements the ActionListener, show you add this.

The method actionPerformed makes sense only if it is implemented by a class that implements the ActionListener. Now when searchButton is clicked the actionPerformed method will execute

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then try to see what is the value of regusername.

<%
String strSessionUser = session.getAttribute("regusername");
System.out.println("strSessionUser:"+strSessionUser );
if (strSessionUser == null) {
%>
  <jsp:forward page="index.jsp?expmsg=Please login" />
<%
}
<%

Maybe what you have in the catch doesn't execute the way you want it because each browser has small differences in the way they handle javascript. ...maybe

Instead of using javascript, you can use the RequestDispatcher class and write java code that redirects.

But most important check what is the value of strSessionUser when you think you should redirect

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

please guide me where it need to decalre as iam new to jsp

This has nothing to do with jsp. It is all basic core java. Which I assume that you already know. When I see this kind of jsp code the only advise I can give is to go back and read some tutorials and practice.

Because I already told you the solution. A solution that should have been understood since you think you are ready for jsps.

As Mr Migagi said: "First learn stand and then fly". And you want to go to the moon

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The fs1, ts2 can not be "seen" at the lines that you get the errors, because they are out of scope. Because of where you have declared them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First show some.
If it is too big, then you need to implemented somewhere where when the method is called you can have access to the elements you want to change.
So I assume If you want to change the grid have the keylistener where the grid is created.
Or if you have it in a separate class, you can have that class which probably implements the KeyListener take as parameter that grid

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't write that kind of code in jsp. Use separate methods and call them from servlets.
Also learn sql because even if you manage to fix the errors the query is wrong.

Also the errors are pretty clear they tell exactly what the error is. And since you are dealing with jsp, means that you should be good and experience enough to correct those errors.

It says it cannot find the 'fs1', because it cannot see it from where you have declared it.

Also how on earth are you executing a query outside a try-catch?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You set panel to null and then you are trying to use it. Maybe after the null you need to create a new one.

Also use equals method to compare Strings:

if (place.getText().equals(" ")) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post code on how you redirect?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You mean display only one element of the array?
You can create an array that has only one element, the element you want to display. But that would make the JList useless since that is not its purpose. Maybe you can change the way you add the JList to the frame, make it a bit wider.
Also if you look at the API there is an example on how to add scrolling to the list.

If you had already thought of that, sorry but that was my thought too.

Another thing would be to make a custom ListModel. Again check the API of the JList

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

Well since the numbers are from 0 to 9, then you can use array of 10 elements:
Contact [] conts = new Contact[10];

So if you "press" the 5 on your phone device then you will get the number:
System.out.println(conts[5])

If you want to store a number at the 8th digit of your phone device then:
conts[8] = new Contact("Name", "phoneNumber")

So create a class Contact (you may choose another name)
Have attributes name and number and you are set.

Search this forum for examples on how to create a menu. Declare the array and

When the user wishes to enter data, ask the position the name and the phone number and put them into that position. (remember the position of array is the phone digit on the device 0-9 array[10])

If the user wants to see the number ask to enter the speed-dial digit which in your case would be the index of the array and print its elements.

If the user wants to search then ask for the name and loop the array until you find a mach with that name and print the data of that contact.

Leave saving for last. Deal with it when you are done with the above.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

when i meant by no output was there was nothing in the destination file.

but when i put that finally statement into the end, it worked!! thanks a ton.

So it seems that the problem was that you weren't closing the writer.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i want
program to find the transpose of the graph G, where the input and the output of the program are represented as adjacency list structure.

pleeeeeeeeeeeeeeees help me

I don't believe this. This is the 3rd time I see thin is the past day!

Don't use this: "pleeeeeeeeeeeeeeees". It is rude!

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

Thanks for nothing daniweb
<<<<<<****** finger. now I will delete my act. have fun *****
I

Even if people tried to explain to you why there was no answer, you wouldn't understand.

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

pllllllllllllllllllllzzzzzzzzzzzzzzzzz help me

Not another:
http://www.daniweb.com/forums/thread281604.html

Don't do that: "pllllllllllllllllllllzzzzzzzzzzzzzzzzz" It is not going to make people change their minds.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API of the String class. There is a method that converts the String into an array of chars.
Now loop that array and see if the first element is equal with the last.
The 2nd with the last -1
The 3rd with the last -2
The 4th with the last -3

If you find something that is not equals then return false.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you explain what the 'mode' is. Out 'Math' is a bit rusty.

And from what I see the code you posted seems to be OK. Are you having any specific problems with that code?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the last else should be an if. Since you say that animal has to be [1000,2999] then it is possible the else to be executed even if that is not true. If ID is 100 for example. You should also have an if for the invalid IDs or put them all in else-if.

Also this will NEVER be true: (animalID <= 3000 && animalID > 7999) If ID = 4000:
animalID <= 3000: (4000<=3000) FALSE
animalID > 7999: (4000>7999) FALSE

But if you do this: (animalID >= 3000 && animalID <= 7999) If ID = 4000:
animalID <= 3000: TRUE
animalID > 7999: TRUE

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello every one i am haveing problem in code i.e whenever i try to write in file it overwrite tthe previous one.I am using this code

 File f=new File("c:\\paul.txt");
       //f.createNewFile();
        BufferedWriter br = new BufferedWriter(new FileWriter(f));
         BufferedReader br1=new BufferedReader (new InputStreamReader(System.in));
         FileReader fr=new FileReader(f);
       //  FileWriter frt=new FileWriter(f);
        // BufferedReader brz=new BufferedReader(fr);

          String text;

         System.out.println("Enter value");
         text= br1.readLine();



          //   br.newLine();
               // br.append(text);
                 br.newLine();
           br.write(text);
           br.flush();
       //  frt.write(text);

         br.close();

end quote.

Start a new thread next time. Always use code tags: Press the code button when you make a new post put code inside.

And mots importantly:
ALWAYS look at the API of the classes you are using. Maybe there is an option that allows you do what you want.

For example why don't you look some of the many constructors of the FileWriter class you are using. One of them might be useful.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So far I have this code. How to fix the following:

(a) Error lines in the method isStraightFlush.
(b) How to add printCard and printDeck to my classes. What should I write in the method?
(c) shuffleDeck crashes if the deck has less than 52 cards. What shouild I do here?
(d) In several methods I have this code which crashes sometimes. How do I fix it?

for (int i = 0; i < cards.length - 1; i++) {
counter[cards.getRank ()]++;
}

a) Read the error messages they are pretty clear. You are not calling the methods correctly. Look how you have declared them and call them like that.

b) Do whatever you want. Usually you print their attributes.

public void printCard() {
  System.out.println("Card: "+suit+" "+rank);
}

With printDeck iterate the array and print each of the cards attributes.

d) Array go from 0 to length-1. So this would be correct: for (int i = 0; i <= cards.length - 1; i++) OR better and more commonly used: for (int i = 0; i < cards.length; i++) Also counter is an array with length 13 -> [0-12]. So the getRank: counter[cards[i].getRank ()] should return something between 0 and 12 not 1 and 13.

c) Try to print the values you are passing as parameters and see what happens. Maybe the random number is for some random cases 52 instead of 51.

Also if you are using:
int random = …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

integer.parseInt()

Completely wrong and read the previous posts. He is already using that method. The problem is that he is passing as argument Strings that are not numbers:
"Antonov, Cessna"

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

The class FileReader could look like this
Here I renamed it to MyFileReader to avoid the confusion with the calss FileReader that is in the package java.io

public class MyFileReader {

    public static void main(String args[]) throws Exception {

        FileReader fr = new FileReader("animal.txt");
        BufferedReader br = new BufferedReader(fr);
        String s;
        while ((s = br.readLine()) != null) {
            Animal animal = null;
            //System.out.println(s);
            String[] info = s.split(",");
            int animalID = Integer.parseInt(info[0]);
            String animalType = info[1];
            double weight = Double.parseDouble(info[2]);
            int cageNumber;
            String name;
            String trainer;
            String owner;
            if (info.length == 5) {
                try {
                    //ZooAnimal
                    cageNumber = Integer.parseInt(info[3]);
                    trainer = info[4];
                    animal = new ZooAnimal(animalID, animalType, weight,cageNumber,trainer);
                    System.out.println(((ZooAnimal)animal).toString());
                } catch (Exception e) {
                    //Pet
                    name = info[3];
                    owner = info[4];
                    animal = new Pet(animalID, animalType, weight,name,owner);
                    System.out.println(((Pet)animal).toString());
                }

            } else {
                animal = new Animal(animalID, animalType, weight);
                System.out.println(animal.toString());
            }

        }
        fr.close();
    }
}

it gives the right out put;
sure other solutions are possible

Hope it helps.

Try not to give away ready solution. And if you do try to explain what you did.
In this post you didn't explain anything. You expect the reader to understand your code and if they don't, he has code that works but does not know what it does and why.
That could be more confusing because in the future when they try to do something similar they wouldn't know how to work around that code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You must take each line the way you do now and extract the data:
> 3000,Monkey,38.6

3000
Monkey
38.6

Then with that data create an Animal instance and print it.
For that there is the split method:

String s = "3000,Monkey,38.6";
String [] tokens = s.split(",");
// tokens array now has: {"3000", "Monkey", "38.6"};
tokens[0] : Id
tokens[1] : Type
tokens[2] : Weight
// its length is tokens.length = 3

So if the line is:
> 5252,Giraffe,130.3,103,Samuel,
The length of the array would be 5.

Use that to determine what kind of object to create an Animal, or a Pet.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi,

i am developing a java application with mysql. i have design a form for input it contains 19 fields to enter and all the values will be stored into mysql. But if i enter any missing field it shows an error " Unable to save for input String"""
String sql = "insert into biodata (name, gender, dob, age, address, city, pincode, state, country, phone, mobile, email) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement stmt =
connection.prepareStatement(sql);

pls help me

Start a new thread and post some code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also if you want that array to be used in another method. Just declare a method that takes as argument an int array and pass it as parameter.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Snice in the inerface it is like this: public void display(ComplexNum a, ComplexNum b) Then the same must be in the class.

public String subtract(ComplexNum a, ComplexNum b){
int x=a.getReal()-b.getReal();
int y=a.getComplex()-b.getComplex();
String yst=y +"i";
System.out.println( '(' +x+ ',' + y + ')');
return ( "(" + x + "," + yst + ")" );
}

But you don't have to worry, because the inerface ComplexNum has all the methods you are using in that method.

I would like to add that those methods (add, multiply, ...) need to be static. That's because they do nothing to the state of the class they are in.
The class ComplexNumb has some attributes real, comb and methods that use them (getReal, setReal, ..)
But the other methods don't use those values, they simply add 2 numbers. So they have nothing to do with the instance itself. In one of those, you add two numbers. What happens in there has nothing to do with the values of real, comb of the class itself. The numbers that take as arguments are irrelevant to the rest of the object.

They could be in a separate class and they don't have to be in the interface:

public interface ComplexNum {

public int getReal();
public int getComplex();

public void setReal(int r);
public void setComplex(int c);
}

MathUtil

public class MathUtil {
   public static String add(ComplexNum a, ComplexNum b) {
      int x=a.getReal()+ b.getReal();
      int y=a.getComplex()+b.getComplex();
     String ys =y + "i" ; …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

this code is in the model folder. to adding the type to plane.add method, i have to change the type to int, since in the package folder my type value is int.

honestly, i dont know much about java.. hate it a lot..

What you said, doesn't make much sense. But the answer is the same. In the select box you have these value and you get these value:
"Antonov, Cessna". Those are not numbers. Maybe you need to assign to each one of them an id number. When you get the selected item see which one it is and save that.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You wrote this:

private String[] typeStrings = {"Antonov", "Cessna"};
private JComboBox typeList = new JComboBox(typeStrings);

How is it possible to change this "Antonov" or this "Cessna" into an int ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks
But somewhere else i got a good answer :
using

UIManager.put("OptionPane.yesButtonText", "yeAh")

for example cause to show "yeAh" instead of "yes" for all JOption panes.
So, this is resolved.
But I dont know how to find all of swing.properties keys, however thats another subject ...

Then why don't look the API of the UIManager class. I did and there is a method: getLookAndFeelDefaults. That method returns a UIDefaults object (look the API) which extends the Hashtable (again from the API of the UIDefaults-look at the definition of the class). So it inherits methods that lets you get all the properties. For that you will need to look the API of Hashtable.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The code that you written would work, provided that you have a Student. class. Usually first you write the Student class. So in a separate file on its own, create a Student class with any attributes, methods and constructors you want. Then create student instances and put them in the list:

public class Student {
   // attributes
   
   public Student() {

  }

  //  and more
}

Take a look some tutorials about objects

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

What I am trying to say is The question says when * is entered the program should terminate. if i remove this then how is the program going to end.

If you remove what? The answer has been given to you. in previous posts

And like I said: Using if statements, you can say when you want the loop to stop and what you want to be saved

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then hos is the program going to terminate if * is not entered, which is what the questions ask for

Can you repeat that, I didn't understood it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No you didn't try my suggestion, nor you understood it.
Look at post Number #8

Even without that post, if you don't want to write the '*' then don't write it. You decide what is written and what is not, when you call the methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Isn't there any onw who can help with this question.


Modify the run method so that now the compressed string is not only printed in the output window, but also written to a file called outfile.txt in the project directory. Each compressed string should be on a separate line in the file. When * entered the code should terminate but * should not be written in the file

Post your latest code.

And don't yell. We are not your slaves to run on demand and fix your code. We have jobs and deadlines on our own. We are not forced to answer to you. We do it for free in out own convenience.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is what the question is asking for.

Modify the run method so that now the compressed string is not only printed in the output window, but also written to a file called outfile.txt in the project directory. Each compressed string should be on a separate line in the file. When * entered the code should terminate but * should not be written in the file

the code I posted in the other thread already does that, but you failed to copy it correctly:

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

I would suggest that you initialize the Printer outside of the while. With your way with each loop you crerate a new one and overwrite the old entries. Also it is not very efficient. Have you tried putting the full path of the file?

Also don't forget to close the Printer outside the while

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