javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all in the code you have posted you write this:

String queryString = "INSERT INTO lesson1(Name,Description)" + "VALUES (?, ?)";

And at the error:

String queryString = "INSERT INTO lesson1(Name,Description)" + "VALUES ("?", "?")";

So which one is deployed? Because the first is correct. Also I believe you are missing a submit button or I didn't look closely

Also I trust that the MyStatement extends the PreparedStatement.


And one last thing when you solve your problem, delete the entire file and start all over. Because you do not write java inside jsp apart for the minimum needed to display the data (a for loop) and do minor calculations. Database access is not minor calculations.

Have the form submit to a servlet, do all the calculations there: Open connection, insert values and then according to the results you will direct to the appropriate page.
Your jsp should have only the form and an if statement that will determine whether to display any messages or not depending on the results. But the actions will take place in the servlet where you will get the result and send it to the jsp.

In order to accomplish the above I strongly suggest to read the post at the top of this forum. It has everything you will need.

http://www.daniweb.com/forums/thread141776.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why don't you use this tag, like everybody else:

<form method="post" action="" name="" >
   <input type="password" name="password">
</form>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming that I understood correctly and you need to know the type of your variable.

Then if it is an Object try this:

String obj = "asd";

        System.out.println(obj);
        System.out.println(obj.getClass());
        System.out.println(obj.getClass().getName());

It will print:

asd
class java.lang.String
java.lang.String

If it is a primitive type, I have tried this and it worked. It converts the primitive type to its object type:

int i = 0;
        Object obj = i;

        System.out.println(obj);
        System.out.println(obj.getClass());
        System.out.println(obj.getClass().getName());

It prints:

0
class java.lang.Integer
java.lang.Integer

If this doesn't cover you, give more details

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is what you have:

boolean stop = false;
{
Scanner input = new Scanner(System.in );
	System.out.print( "Enter Employee's Name or stop to exit program: " );
		String empName = input.nextLine(); // employee name

if ( empName.equals("stop")) {
		System.out.println( "Program Exited" );
		stop = true;
} else {
      while (hourlyRate <= 0) 
				{...
				}
	while (hoursWorked <= 0) 
				{....
				}
	}
}

In the same way you repeat the code when the user enters a negative value:

while (hoursWorked <= 0)
{....
}

You will have to repeat the entire code until the user enters stop. You already have a boolean that you set it from false to true. So use another while in which you will put the whole code I have posted it and use that boolean variable inside the while statement

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi Friends,

Any body please send me a complete java project on
"Hospital Management System" or "Government Health care System".

Please provide me in detail to <<snipped email address>>

Also, even if we wanted to give you anything, there is no way anyone could write such a program because you provide no explanation what the project should do .
What this "Hospital Management System" is supposed to do??
It took take from 1 week to 1 year to build this depending on the requirements. So don't expect to get anything with such demands, because you demanded a project, you didn't ask for help

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

in any case if you can be of assistance.

The answer is Yes; we can be of assistance, provided of course he follows the rules of DaniWeb :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

in any case if you can be of assistance.

Of course we can be of assistance. Why else you think we are in this forum.

The answer to your question is Yes!

Now, mark this thread as solved and start a new one, with a real question and some code if possible.
Also read the forum rules. We don't give complete code by request, only help with existing code or we give ideas and examples.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is a problem from the site www.mod-x.co.uk that he is trying to solve... he is meant to solve it himself lol but he is trying to get you guys to solve it... he has downloaded the .jar file and used a decompiler to get the code and has no clue about how to program java :-)

STOP CHEATING!

Now that you mentioned it, when someone writes all this piece of code and doesn't know what this thing is: Exception in thread "main" java.lang.NoSuchMethodError: main then there is certainly something strange

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi jhonnyboy .
you can use "j2e_enterprise" software , which converts .jar file to .exe file . Download it and try it , actually it's perfect for me .

hope my reply is helpful
best regards
eng.hosam84

That is the worst advice ever. To encourage someone to go all this trouble, when they already have a jar file that can be run. You are practically destroying the hole concept of writing the program in java.
Just because you don't have an IDE doesn't mean that you cannot run a jar file. IDEs weren't created to run files .jar or .class. Only to make life easier and to boost production.

If you read other similar threads everyone discourage the converting of a .jar into an .exe

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

egee, your code is much better. Just correct the line I told you. I usually use another algorithm but your version is also interested.
I would suggest to use your code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you need to tell us what of mistakes your are having.
Is it compiler or it gives you wrong results and what kind.

We might not be in front a computer with java installed.

As for your error:

The pop method doesn't return a char value but an Object.

Stack.pop() returns an Object. And you are trying to put that value into a char. Since you know that that value is actually a char, you need to convert that Object into a char:

char temp=(Character)s.pop();

Here you turn it into a Character object and java automatically will turn it into a char primitive type.

If you are using an older version of java, you might want to try this:

char temp = ( (Character)s.pop() ).charValue();

Next time you might want to look the API of the classes you are using:

Stack
Character

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thank you for repeating my code. I am sure that after months tanha hasn't solved his problem, but you were the one he was waiting for.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

char c = 'a';
String s = new String("" + c);

It is easier to do this: String s = c + ""; But this is better: String s = String.valueOf(c); I have checked and the latter is faster

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will put it where you read or write a file

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to use BufferedWriter to write to files. And use the newLine() method for changing lines:

BufferedWriter writer = new BufferedWriter(new FileWriter("file"));
writer.write("ABCD");
writer.newLine();


writer.close();

Also for reading this is better:

BufferedReader reader = new BufferedReader(new FileReader(fileName));

String line = reader.readLine();
while(line!=null) {
//do whatever you want with the line



//read the next line
line = reader.readLine();
//continue with the loop
}


reader.close();

Don't forger to close the reader, writer at the end of the reading writing

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First you need to learn how to read and write to files. There are plenty code examples here and tutorials.
You will have a separate class for that with methods like:

public void write(SomeObject [] elements){
}
public SomeObject read() {
}

You will have set,get methods for the file.

The SomeObject will be the object with attributes the number and the subject described in the file.

You better use the split method of the String class in order to split each line and get the number and subject when reading the file

Also search the API for the Comparable interface if you are free to use any method in order to do the sorting. I don't know what algorithm is this: topological sorting algorithm

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That was most probably because when we learnt Java, java.util.Scanner did not exist.
I started learning Java from the 1.4.2 version of the JDK, and Scanner was introduced only in the 1.5 version and since console input is not so widely used by many of us, we opted to stick with good ol' BufferedReader.

Well the book I had was called Java 1.2. I don't remember what kind of java I had because I didn't know about versions but I believe I had Java Version 1.2

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you are saying doesn't make any sense, but you could create a separate class and call the constructor "tatat" inside that class's main method.

But if are not familiar with constructors and using multiple classes from different files in one single main, then you should not been writing swing, even though the NetBeans will auto generate everything for you

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You might want to use the trim method as well.
If the user enters: " 4 * 3 "
Then the trim method will return this: "4 * 3"

String expr = "  4    *    3   ";
expr = expr.trim();
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Neither one. I don't write console applications. :P

I don't write console applications either but when I first begun I knew from my book only the BufferedReader. So since we've seen many students here asking how to read files and input from the console I thought to get other opinions and discuss the topic.

There has to be some reason why someone would choose to use one over the other

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can anyone help me make it say invalid expression when it tries to change an invalid infix expression to a postfix instead of an error coming up.

Can you post again the code where you get the error?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I wrote this example for you:

class Person implements Comparable {

private String name = null;
private int age = 0;

// get, set methods and constructor

public int compareTo(Person other) {
  if (other==null) {
     return 1;	
  }
     if (this.age>other.getAge()) {

         return 1; //something positive

    } else if (this.age<other.getAge()) {

           return -1; //something negative
    } else { // none is greater or lower than the other
          return 0;
    }	
}


//BUT the equals MAY use something else
public boolean equals(Person p) {
   if (p==null) {
      return false;
   }
   if (name==null) {
      return name == p.getName();
   }
   return name.equals(p.getName()); 
}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

compareTo should return an int if you want to override the one inherited by the Comparable interface.

And it doesn't have to have specific value

public int compareTo(Koerper object)
	{
		
	}

It should return a positive number if "this" object is "greater than" the argument "Koerper object"
A negative if it is "smaller than".
And 0 if they are equal. Remember if compareTo returns 0 doesn't mean the the equals method will have to return true. So you don't need to implemented.

Check the API for the comparable interface

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Nevermind I got it from this tutorial:
http://www.deitel.com/articles/java_tutorials/20060408/Arithmetic_InputMismatch_Exceptions/

//create add proper data/calculations to variables
		try
		{
			radius = input.nextDouble();
		}
		catch(InputMismatchException inputMismatchException)
		{
			
}

I believe it is better to read them as Strings and then do the converting.
What will happen if the user enters: >" 2123 "

If you read it as String then:

int i = Integer.parseInt(input.trim())

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to take a look at this post:

http://www.daniweb.com/forums/thread170371.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

but the problem is my 'selection is integer', so how i fix it to string... if i fix it to string.. then the 1,2,3 selection will corrupted..

No your selection is not an integer. 1 is not an integer
this is an integer: 1
this is a String: "1"

String input = read.nextLine();

if (input.equals("1")) {

} else {
....
}

And if you want to turn into an integer:

String input = read.nextLine();
int i = 0;
try {
   i = Integer.parseInt(input);
} catch(NumberFormatException nfe) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to call the read.nextLine() which returns a String, and use Strings to do the checks in the if

Try searching the API for the Scanner because I don't quite remember the method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try and run this:

class Test {

  static void method2(String s, double d) {
     System.out.println("The s argument is: " + s);
     System.out.println("The d argument is: " + d);
  } 

  public static void main(String [] args) {
       method2("asd", 123);
  }
}

void method2(String s, double d) The method2 doesn't return anything: (void) and it takes 2 argument. The first is a String and the second a double.

The values that you pass: method2("asd", 123); Will populate the arguments of the method. LOCALLY.

Meaning that this wrong:

class Test {

  static void method2(String s, double d) {
     System.out.println("The s argument is: " + s);
     System.out.println("The d argument is: " + d);
  } 

  public static void main(String [] args) {
       method2("asd", 123);

// The s exists only inside the method2
       System.out.println("The s argument is: " + s); 
  }
}

But this is right:
TRY and run it:

class Test {

  static void method2(String s, double d) {
     System.out.println("The s argument is: " + s);
     System.out.println("The d argument is: " + d);
  } 

  public static void main(String [] args) {
// Not the variable that "lives inside the method"
       String s = "XXX"; 

       method2("asd", 123);

     System.out.println("The s of the main(String [] args) is: " + s);
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
class Test {
  static void method1() {

  }

  static int method2(String s, double d) {
    return 1;
  } 

  public static void main(String [] args) {
       method1();
       method2("asd", 123);
       int i = method2("asd", 10.00);
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is not much of a question, but a discussion and searching for opinions. I have seen that many use the Scanner class for getting input from the keyboard. Some, like myself, use the BufferedReader.

Why will someone use one over the other?

Or they both do the same thing when it comes something simple as that and their real difference is when it comes to using them for something more complex?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't agree with this:

public int pop2()
    {
    	if(evaltop >= stackArray2.length)
    	{
    		evaltop++;	
    	} 
    	return stackArray2[evaltop--];
    }

Why do increase the index when poping? All you need to check is if (evaltop>=0) If yes then you can safely pop (no ArrayIndexOutOfBoundsException because index is -1)
If no then index is -1 so the stack is empty, so don't do anything. There is no point in increasing the index since you don't put anything in the stack. With the pop you only get the element and decrease the index because you removed an element. That is why you need to check if the index is -1 to make sure that the stack has at least 1 item

Also the String.trim() method removes any trailing blank spaces and turn this String: " " into this: ""

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public void push(char i) 
    {
      stackArray[++top] = i;
    }

Before you push anything in the array you need to check if it is full or not. If the maxsize is 10 and you the above 11 times you will get an exception. Try this:

public void push(char i) {
      top++;
      if (top >= stackArray.length()) {
            top--;
      } else {
          stackArray[top] = i;
      }
 }

Also since you put elements into these 2 arrays: stackArray, stackArray2 the same way:

stackArray[++top] = i
stackArray2[++evaltop] = j

You need their indexes to have the same start:

public Stack(int max) 
    {
      maxSize = max;
      stackArray = new char[maxSize];
      stackArray2 = new int[maxSize];
      top = -1;
      evaltop = -1;
    }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

could you please help me with a java code for connecting a client and a server?

Jesus letsae! Haven't read verruckt24's post. Don't you know how to create a new thread?

This is a dead thread not a make-a-wish well

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to explain what you are trying to accomplish and how because your code doesn't make any sense

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post the implementation of Stack class?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As I said in my previous post:

Double hoursWorked = input.nextDouble()
if (hoursWorkedInWeek <=0.0) {

}

You read the input and put it in: hoursWorked and then inside the if you check the variable: hoursWorkedInWeek

You don't need to be a pro-programmer to realize what you are doing and what you are writing.
You put value in: hoursWorked. Aren't you supposed to know that this is the variable you need to check. From where did the hoursWorkedInWeek come from?? It doesn't have the value you read. So why do you check it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you open a bracket where it is not needed:

Double payRate = input.nextDouble();
System.out.println();{

//Input the  name of the employee
      System.out.printf( "Please enter the employee's  name ('stop' to quit): " );
       employeeName = input.nextLine();
      if (employeeName.equalsIgnoreCase( "stop" ) ) {
         break;}
  
         // prompt and input hours worked
       System.out.println("Please enter hours worked: " );
     Double hoursWorked = input.nextDouble();
      // read value for hours worked
      if(hoursWorked <=0.0){
          System.out.println("Hours worked cannot be negative/zero.");
      }
      else{
      // prompt and input pay rate
      System.out.println( "Please enter pay rate: " );
     Double payRate = input.nextDouble();
      System.out.println();
      if (payRate <=0.0){
          System.out.println("Hourly wage cannot be negative/ zero.");
      } 
      else{
     double weeklyPay = hoursWorked * payRate;
                PrintStream printf = System.out.printf("Weekly pay is $%.2f", weeklyPay);
}
}

I have changed the variables because you do this:

Double hoursWorked = input.nextDouble()
// read value for hours worked
if(hoursWorkedInWeek <=0.0) {


Also you get the error because you ask from the user to enter a number:

System.out.println("Please enter hours worked: " );
Double hoursWorked = input.nextDouble()

And you enter: 'stop'

stephen84s commented: To go this far with him, you really need should be given a much bigger positive rep. +5
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is the point of having these extra brackets:

employeeName = input.nextLine();
  if (employeeName.equalsIgnoreCase( "stop" ) ) {
     System.out.println();
  }
}

Also when the user enters 'stop' you want to break, so put a break int the if.
Also if the user enters negative hourlyWageInDollars he will get the message but then the weeklyPay will be displayed.
You need to add another else after the
if ( hourlyWageInDollars < = 0 ) ,
because the result should be printed if the above is not true, inside the else

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your latest.
Also what are the instructions for the logic.
Do you want to break when you get any error or continue with the next loop?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hey JavaAddict,

I think I am seeing what I am doing wrong.
I need to have my "IF" statements after
my command to input the hours worked and pay rate.

IS that where I went wrong?

Thanks
IKE

Isn't that logical? First you read the input and then you validate it with if-statements.
If you don't get the input what are you going to test in the 'if'

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i need to add tabs dynamically to the tabbedpane every tab will have jtextarea as component i tried this but everytime i click the button the first tab alone is changed..

tabbedpane=new JTabbedPane();
tabbedpane.addtab("new tab",null,textArea,null);

That is because every time you press the button a new JTabbedPane is created replacing the old. You don't need to create a new JTabbedPane only adding.
So declare the JTabbedPane as class attribute outside the methods.
when the button is clicked you will only add to the existing one

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check this part of the code:

String line = null;
Postfix b = new Postfix(line);
				
while((line = reader.readLine()) != null) {
	line.trim();
					
	//b.evaluate();	contents.append(line).append(System.getProperty("line.separator"));
}

You have the b.evaluate in comments. But the point is that when you initialize the object you do it outside the while () where the the line is null:

String line = null;
Postfix b = new Postfix(line);

May I suggest that you put it inside the while:

String line = null;

				
while((line = reader.readLine()) != null) {
	line.trim();
        Postfix b = new Postfix(line);	
	//b.evaluate();	contents.append(line).append(System.getProperty("line.separator"));
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am sorry for the double posting but in case you still don't get it you were supposed to replace the red comments with commands on your own and not just leave them like that.
The input will not be read by itself :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because first you check the hours and the you read them.

And as for the unreachable statement, you didn't copy exactly the code given to you.

This is what was given:

if (name=='stop')
  break;

-read hours

And you wrote:

if ( employeeName.equalsIgnoreCase( "stop" ) ) {
         break;
// read value for hourly wage
         if(hourlyWageInDollars <=0.0 ){
             System.out.println("Hours worked cannot be negative/ zero." );
         }

}

In case you didn't understand the difference, here a simpler version of what you wrote:

if (employeeName.equalsIgnoreCase( "stop" ) ) {
   break;
   System.out.println();
}

You put the command after the break when it should be after the break but outside the if.

Also you DIDN'T read the code given to you, you just copied it. Read again the bold comments in verruckt24's code:


if ( employeeName.equalsIgnoreCase( "stop" ) )
break;
// read value for hourly wage
if(hourlyWageInDollars <=0.0 ){
System.out.println("Hours worked cannot be negative/ zero." );
} else if ()
{
...
}

Also there I hope you know the difference between these 2 following examples:

if () {
   command_1;
   command_2;
}
if ()
    command_1;
command_2;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you even tried to read the advices posted here?

verruckt24's example was quite simple, not to mention it was the solution. All you needed was to replace the comments with the code to read the input (1 line)


- Read the input for the name
- use the 'if' to do the check (if stop: break)
- Read the hours worked
- Check the input (if negative break)
- Read the hourlyWageInDollars
- Check the input (if negative break)
- Since you have reached here, all the data are valid --> do the calculations


PS: I wanted to post the above algorithm but I didn't because it was what verruckt24 said and his code covered what I wanted to say completely, but it seems that we need to repeat ourselves

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does the code that you provided works? Because it seems OK.
What errors do you get?
Also, check the API for the String class. There should be a method for turning a String to upppercase

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will be starting working on perl and java soon..
Can anyone please help, form where to start so that i get the confidence of working on it and i can do hands on.

At the top of this forum there is this easily found post:
http://www.daniweb.com/forums/thread99132.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It isn't working because you never initialized the 'birthDate' variable to the person's birthday.

We posted the same time :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Calendar birthDate = new GregorianCalendar(); Aren't you suppose to set values to that object the input from the user?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if it is just me but I didn't understood anything from your program Could you please change the names of the variables to English?

Thanks.