stephen84s 550 Nearly a Posting Virtuoso Featured Poster

do you know why he is banned?

Well you can find the formal reason and the conspiracy theory both on this thread :- http://www.daniweb.com/forums/thread183273.html

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

(this reminds me rashakil fol, where is he now do you know?)

I am guessing he is still banned.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

The question is how do I go about splitting the strings? I know there is a split method but I'm not sure how to use it.

Its as simple as :-

String[] splitString = book[i].split("-");

Look here for more details.

But beware of the "-" in "Addision-Wesley", even that "-" will be used for splitting, So either you will need disallow the user from using "-" in the original Strings or you will need to manually replace the "-" with some other marker when you concatenate them and then replace that marker with "-" when you want to again display it later after applying the split() method.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Give us the complete URL on how you are calling it,

Is it like this : http://localhost:8080/<project-name>/myServlet
Also can you access "index.jsp" ?

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

The problem is occurring where you are constructing your SQL query you need to show us that code, for us to trace the error.

Also Just for your Information, in case one of the values you wish to insert inside your database contains problem characters like the single quote ('), I advise you use the "PreparedStatement" as shown below:-

String name = "abc'jhd";
.
.
Connection con = DriverManager.getConnection(.....);
PreparedStatement ps = con.prepareStatement("INSERT INTO student(name) values (?)");
ps.setString(1,name);
ps.executeUpdate();
.
.
.
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

AFAIK you cannot pass values assigned to variables in Javascript to your Server Side JSP pages without putting the actual values inside some form fields viz. the "input" element (eg hidden fields, text fields etc) or "select" element etc.
Either that our you can pass them as part of the invoking URL eg http://xxxxxx/page.jsp?value1=ccc&value2=vvvv....

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

I cannot see a main() method in the code that you have posted, also you have not made your JFrame visible using the setVisible(boolean) method.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

How to get the value from a hashtable irrespective of its case...

Would you care to mention what does your Hashtable contain or do I have to find that out from my crystal ball.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

not stalking at this stage, a little bit curiousity..

You mean preparing to stalk. ;)

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Now referring to your import statements (Although jasimp has already given you the solution for finding the classes you made with "importing" them).
You import the classes and not the .java files, (unlike including the header files in C or C++).

A simple example is show below, here I am including the Hashtable class present in the java.util package. Also observe the second import statement where using the wildcard "*", I am including all the packages present in the java.awt package.

import java.util.Hashtable;
import java.awt.*;
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Actually i dont understand why people dont want to show their faces in the forum?
we can take Dani as an example, she is the most preminent one and she does not need to hide her face.

If I am not wrong the cscgal profile does have her picture in it.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

>might as well be the geek lounge where the rep points wouldn't affect me
Perhaps I should slap you with a Keep It Pleasant infraction. You're not invincible here either, slick. ;)

Damn !!! of all the people in daniweb I pick the only SuperMod for my gloating.

** Puts tail between the legs and runs away **

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Amazing. Visiting the Geeks' Lounge is like sitting in a room full of children.

Well we have to vent out our life's frustrations somewhere (or at someone) :P, might as well be the geek lounge where the rep points wouldn't affect me

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Naah !!! For a guy who plays tit for tat with Bad Reps his IQ is too low to understand that.

Now because of the ambiguity I just want to mention 'his' = "serkan sendur".

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Stop calling him Rashakil fool, maybe he will stop the 'war of words' too!

Naah !!! For a guy who plays tit for tat with Bad Reps his IQ is too low to understand that.

Rashakil Fol commented: Sorry, I don't understand what you're saying. -2
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

I need to select a file and highlight it without selection

This has gotten me confused, is the second part not contradicting the first ???

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Guess what I found a direct API which does this conversion, although I do not know how it works :-
http://www.artofsolving.com/opensource/jodconverter

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Please dnt joke .... u r from mumbai?? me tooo.. we can talk on the issue if u dnt mind ... please send the code sample.

You're from Bombay that nice to know, but that does not mean I am going to spoon feed you any code. My first post in the thread links to the iText library and the Apache POI site, go visit them and you will find quite a few code samples there.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

can you please help me with sample code that have both apache POI and itext used say for eample reading an excel and converting it into pdf. please hurry ....

Yeah before that transfer a million dollars to my account !!!

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

i am pretty sure you got that backwards there stephen.

"For example I would enter 12345 and 1 2 3 4 5 would be returned."

I was assuming that is some mistake my the O.P. cause that "split()" method of python too does not operate in that manner but I could be wrong.
Thats the reason why instead of using his first post I quoted his Python post.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Coming from python, to split a string i would do 'string.split(" ")'
and it would split 123 into 1 2 3
I don't know .length, or .charAT, or what that even is
I do not know what I should use to traverse through the string and split it by each space, I know this is simple, but for some reason can't figure it out.

In Java too its just the same thing :-

String alpha = "A B C 1 2 3";
String beta[] = alpha.split(" ");

The values is "beta" would be the following :-

beta[0]="A"
beta[1]="B"
beta[2]="C"
beta[3]="1"
.... I suppose you get the drift.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Just observe the following code snippet:-

if(send = true) 
  cout <<"You have passed the exam!\n";
else if (send = false)
  cout <<"You have failed the exam.\n";

Watch both the conditions carefully you have used only a single "=" instead of "==" to test for equality.
BTW some compilers in this situation would complain of "Possible incorrect assignment".

Also there is no need for passing the second argument "pass" to your grading function, instead just declare a local variable in the "grading()" function and return its value.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

I am not sure then what to initialize my String output to. I am lost.

Ehh !!! Its your program you tell me what you wanted to be printed instead of "null" !!!

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

If you carefully check the following piece of code :-

String output = null;
String menu = null;
Scanner keyboard = new Scanner (System.in);
System.out.print("\nEnter your taxable income amount: $");
do {
  taxAmount = keyboard.nextInt( );	// Stores the chosen movie.
  validInput = true;
  if ( (taxAmount < 50000) ) {
    System.out.print ("\n(You must an amount greater than or equal to $50,000): $");
    validInput = false;						 
  }
}while(!validInput);
			
// A method call to displayMenu
displayMenu (menu, validEnter, enter, output);
			
// A method to call to computeIncometax
computeIncometax (taxAmount, enter, tax1, tax2, tax3, tax4, tax5, tax6, taxfinal1, taxfinal2, taxfinal, alphatax, betatax);
			
// A method to call to displayFinal
displayFinal (taxAmount, output, taxfinal);

From the start to the end when you call the method displayFinal(). the variable "output" is never initialized (Apart from being initialised to null at declaration time), which is why "null" is getting printed.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster
String myString = Integer.toString(enter);
			
return enter;
return output;

You completely missed the point I was trying to say. I had told you to package both those values into a String array and return a reference to that array back to the calling method, like here :-

String[] arrayOfValues = { output, Integer.toString(enter)};
return arrayOfValues;

Also you will have to modify the return type of your method to accommodate that.
BTW didn't the compiler complain about unreachable code ???

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Show us what you tried ?

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

I need both the 'output' and 'enter' to be returned back to the calling method but one is a String and one is an int

You have many options here one is create a new class which has those two as its member properties and return a reference to this object from that method.
Second is put them both inside a "String" array of size "2" and return a reference to that array from the method and in the calling function extract the values from the array. For ex in the method you could have :-

String[] arrayOfValues = { output, Integer.toString(enter)};

And in the caller method you could extract the values from the "String" array as :-

output = arrayOfValues[0];
enter = Integer.parseInt(arrayOfValues[1]);

Next you could also return a Properties (or some other classes part of the Collections Framework ) object with the appropriate name value pairs mapped in it.

olgratefuldead commented: Very helpful +1
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Give us more information on what libraries are you trying to use in that applet and what platform are you trying to run this on. I have a strong **feeling** you are not on windows or not using the Sun JRE (of course I could be wrong).

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

@vishalsnc

Drop the IM speak this is not a chat room, and try to read the rules and search the forums before you post anything.

cn u pls mail me some examples if u have ..

What do you think does the Sticky which Peter has linked to contain ???

nw hw to convert that to MVC2 pattern..
like which files are to be made and hw the content is to be seperated n all..

There is no magic bullet or a step by step guide which you can follow and "Viola !!! your application has been converted to MVC2". Peter has linked you a good example with proper explanations. Think over it and redesign your classes and JSPs with MVC2 and the example as a reference in mind.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

If you use the showInputDialog() method, it either returns the String that was entered in the text field or else "NULL" if cancel was pressed, So in case you wish a User to force some input and not press Cancel, you could simple put it in a do-while loop like this:-

String StudentClass = null;
do {
  StudentClass = (String)JOptionPane.showInputDialog(null, "What class is " + 
      "\nthe new student in?", "Info", JOptionPane.PLAIN_MESSAGE, 
      null, possibilities, "IB Compter Science");
   System.out.println(StudentClass);
}while(StudentClass == null);

However if you use showOptionDialog method, and pass the "possibilities" array for the "options", you would get three buttons with their corresponding headings as specified in the Array.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

In case you do not want your user to press "Cancel" in a JOptionPane dialog, you can actually get rid of that button altogether using the JOptionPane.showOptionDialog()

<EDIT> Cleaned some of my errors.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

From what I see, unlike the rest of the variables (mass, diameter and names which are all arrays) surfaceGravity is just a normal variable.

Hence the following for loop:-

for (int y = 0; y < 9; y++) {
  surfaceGravity = (((6.67E-11) * (mass[y])) /(Math.pow(diameter[y] / 2, 2)));
  System.out.printf("%25.2f\n", surfaceGravity);
}

Actually does nothing but print the values of surfaceGravity from 0-9.
However the value of surfaceGravity variable are overwritten in the next iteration of the for loop. i.e. for the first iteration your loop calculates and stores the value of surface gravity for the first planet in variable "surfaceGravity", in the second iteration the we calculate the surface gravity for the second planet and store in the variable "surfaceGravity" (as a result the value for the surface gravity for the first planet is lost, overwritten by this new value) this goes on till the nineth planet (which is where the "for" loop terminates hence its value is not overwritten), and hence "surfaceGravity" has the value for only of the nineth planet.

My suggestion from the way your program has been designed is move the call to the "printResults()" method inside the second last "for" loop in your main.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Please avoid chat speak or Sms speak its against the forum rules and doesn't even sound professional.

Also define what you mean by "doesn't work". Give us sample data of the tables and what you want the "SELECT" to actually display.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

@stephen84s : Yes but in this case, what happens if he inputs the number of adult tickets to be 110 ? You still ask him for the number of child tickets, which since he has already jumped the maximum count is wrong on our part. If he enters the no. of adult tickets to be greater than 100 he should be warned of the limitation there itself rather than proceeding.
Take a look at this post for a solution.

Yeah thats correct, but I assumed the thread starter will figure out what additional checks to put, so I just pointed out where to put his checks.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

The following loop itself could be modified to perform this check you need :-

do {
  System.out.print("\nHow many adult tickets? ");
  atickets = keyboard.nextInt( );
  System.out.print("How many children's tickets? ");
  ctickets = keyboard.nextInt( );
  positive = true;
// Defines the invalid  boundaries (but true by definition).
// add the new condition with an "||" in this "if" condition itself
// or use another if block
  if ( (atickets < 0) || (ctickets < 0))	 {
    System.out.println("\n(You must pick a positive number): ");
    positive = false;										 
  }				
}while(!positive);

To the "if" condition just add ((atickets+ctickets) > 100) with an "||" operator, so even when the sum of the two is greater than 100 it will prompt the user the enter them again. You will however need to modify your error message to reflect exactly why the user has to input the "aticket" and "cticket" values again taking into account the new case.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Since you are already getting an exception, can you print out the exact StackTrace of what is being thrown up at you. java.lang.NullPointerException s occur when you are trying to invoke a method/access a property etc on an object reference set to Null.

For e.x. the following code snippet would throw a NullPointerException on the second line.

String alpha=null;
alpha = alpha.substring(1); // Calling a method on an object 
                            // reference set to nul
stephen84s 550 Nearly a Posting Virtuoso Featured Poster
java -jar "/home/viber/JAVAFINAL/dist/JAVAFINAL.jar"

Now I see the reason for the problem. I am guessing your username is "viber" on your computer and you are running this application is user "viber" and your O.S is Unix/Linux based.

Now when you create the "txt" file what path have you hardcoded in your program ? Does it create the file in the current directory or have you hardcoded the some path inside "/home/viber", eg "/home/viber/sample.txt".
If you have not done the latter the problem is just of simple file permissions on your Linux / Unix box. By default a normal user is not allowed to create or edit files inside the "/", only the "root" user can create/edit/delete any file he wants.
If any other user in Linux wishes to create/edit/delete files in any folder other that his "home", you will need to grant him permissions on the folder explicitly using either the chown,chgrp or by adding that user specifically to some group and allowing that group to access to modify the contents of that folder.

You can learn more about file permissions in Unix here.

Alternatively you could just change your working directory to your "home" i.e. "/home/viber" and execute the JAR file as :-

java -jar JAVAFINAL/dist/JAVAFINAL.jar
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Show me some code, on how you are creating your file, also the exact command how you are executing your jar file.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Define what you mean by "can it doesn't work".

Do you have any errors or exception StackTraces to help us go on ?

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Here is some ready made code for an MP3 playlist.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

I tried the convertion method that bertt's described . bt I can't get the jar that contain the ' import officetools.OfficeFile' can any one please suggest a method to convert HTML to PDF

Thats the reason why his post has received a Bad Rep (RED Mark) and my post which was the actual answer received a Good Rep (Green Mark) if you had cared to observe.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

http://www.javamex.com/

Came across this site a few days ago, although they could make the site a lot more pleasing to the eyes, I found the articles quite informative especially from a beginner point of view.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

i would say lazy student wouldn't even bother posting questions.

Do not be so judgmental, If you hang around here long enough you will see your fair share of them.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

how do I place it in code?

Thats what I meant by try it. Trust yourself a little and take the jump. At most you will get a compile error or a wrong output, the world will not end with that.
The help offered here is more like if your car has a problem we will help you sort it out, but we will not push / drive the car for you.

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Yes, Next time you post wrap your code inside
[code=java] and [/code] tags. Also what do you need help for ? Tell us the problem (compile errors,logic problems etc etc) you are facing and this time please do not give the reason "I am a beginner" for not attempting something.:)

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Hey, but wait!

Doesn't the do- while loop work in a way that it first executes the code and at the end evaluates the boolean? If the boolean is true it should go for another round, if false it should terminate. Right?

If this is correct then my boolean should be correct. If allocated would be smaller than c it would continue, else if equal it should stop?
Is this correct?

Eeep !!! Sorry Confused myself on that one, heres what I think is going wrong.
Now I just went through your code the problem seems to be a tad more deeper than I thought.

You see at the class level itself you have a member called allocated.

private int allocated;

Now let us look closely at your do-while loop.

do{
  int allocated = 0;
  for(int i = 0; ((allocated < c) && (i < n)); i++){
    this.road[i]=binaryGenerator();
    if(this.road[i]==1) {
      allocated = allocated +1;
    }
  }
  System.out.println("T "+ allocated +"  " + c);
} // This is where the scope of the "allocated" variable
  // declared inside the loop ends
while(allocated < c); // The allocated being referred to here is
                                // the one declared at the class level

Now inside you are manipulating the variable "allocated" which is declared inside the do-while block and it is this variables variable that is printed in your System.out.println("T "+ allocated +" " + c); , However thats where the scope of this "allocated" variable ends. In the …

Ezzaral commented: helpful +17
stephen84s 550 Nearly a Posting Virtuoso Featured Poster

"allocated" clearly prints as equal to c

But the condition in your do-while loop is

while(allocated < c)

So definitely it wouldn't stop because technically "allocated" is not less than "c".

If you want it to terminate when "allocated" and "c" are equal also then change the "<" to "<="

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

Dont be so harsch on the poor guy. We all started with such trivialities...

Yes NightStrider, we do all start with such trivialities but the fact that makes us what we are is "What we do about them".

Putting myself in his shoes, I wouldn't have been on a public forum asking for the magic pill which would hardwire all the concepts of Java "for" loop inside my brain, rather I (and most of the others who excel at programming) would spend that extra time reading that Java Reference Book (again and again) or just making up some trivial code snippets and experimenting with them trying out what happens if when you add "X" to your code, remove "Y" from somewhere else and observe what happens and so on, even others(who do not have this appetite) would opt to ask their instructor what to do just as Verruckt suggested.

@nandomendoza

Thank you, I just started learning this stuff.

Just because you are new to Java doesn't give you a license to be unaware of basics like these and not experiment and find out the behaviour of Java on your own. Also the sticky "Starting Java" has numerous resources that are supposed to help beginners like yourself, How many of those did you read before posting this thread ?
When beginners show the effort by writing their code or by showing some effort on research on their own from the web or by citing from their …

stephen84s 550 Nearly a Posting Virtuoso Featured Poster

If you are using a Swing Form to get Input then I would suggest dropping the while loop altogether because your actionPerformed() method will be called whenever your user clicks on the GuessButton and you can perform all the necessary processing then.