javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What the 3 variables of LProp stand for? If they are the 2 bool values and the which method to call then have an if statement checking what is the 3rd input and call appropriately the reight method AND, NOT, ... with the first 2 arguments

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you sent a sample of you java code, because I don't understand what you mean when you say:

My way of coding is more simpler than the public boolean and public void.

but in the class file it's everything in the java file but with a symbol. So thinking smart i decided to make everything different

How different?

I used a simple logic code of commands and public void starters and public boolean starters

Can you provide some code?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I assume that the other program (GUI) has a list of classes. Do you know the elements of those classes as well as their methods. If the main GUI page has a constructor you call it with the appropriate data that you get from your program.
If the elements of the GUI are public you can 'set' their values, after you have called the constructor of the program in your main:

In general how you set values:

JTextField field = new JTextField();
field.setText("New Text");

In your main:

OtherProgramGUI gui = new OtherProgramGUI();
gui.field.setText("New Text");

gui.setVisible(true);

If all of the elements and the methods are private then you have a problem

PoovenM commented: Thank you for the awesome suggestion :) +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have a Form input field in my JSP:

<input name="nickname"  type="text" value="<%= NameClass.getInfo() %>" />

How do I make sure this data is escaped correctly to be able to show quotes and apostrophes. I tried slash in front (name=\"nickname\") and it didnt work.

I dont have JSF,Struts, JSTL, StringEscapeUtils (from Apache commons) due to restrictions on my Tomcat 4.1.27 container.

Is there something I can use or please advise best way to handle this?

What do you mean escape correctly?
Plus you don't display the 'nickname'. That is the name of the element. Like the variable name of a JTextField in swing.
The real value is the 'value' attribute and you display whatever the NameClass.getInfo() returns.
You use the 'nickname' when you submit the form:

String nicknameValue = request.getParameter("nickname")

It will have whatever the field has. And when the page loads the initial value that will be displayed is the NameClass.getInfo().

If you want apostrophes at the field then (I think this is correct but try it anyway) have the NameClass.getInfo() return this:
"a value"
and do this:
<input name="nickname" type="text" value='<%= NameClass.getInfo() %>' />

And for better responses try the jsp forum.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The name of the file must be the same as the name of the class and as the name of the constructor. That is why in java terminology we don't say 'file' but 'class'

Is the name of the file: EmployeeSystem ?

Then this :

public class EmployeeDirectorySystem  {

  public EmployeeDirectorySystem()  {  

  }
}

Should be:

public class EmployeeSystem {

  public EmployeeSystem ()  {  

  }
}

Or change the name of the file

Plus next time say the line where the error happens as well as the full message of the compiler

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
mport java.util.Scanner;
public class ClockDemo {

public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the Current time Hours: ");
int currHours = keyboard.nextInt();

System.out.println("Enter the Current time Minutes: ");
int currMin = keyboard.nextInt();

TimeAT current = new TimeAT(currHours, currMin);
}

The same way read hours and minutes to create an alarm TimeAT, and use these 2 objects as arguments for the Clock constructor

The TimeAT takes 2 int arguments and the Clock takes 2 TimeAt arguments. So you will need to create 2 TimeAT instances, meaning that you will need to read 4 int values from the keyboard

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter value:");
String input = keyboard.readLine();

System.out.println("Value entered: "+input);

int i = Integer.parseInt(input); //if an integer was given

You might want to check the Scanner class. I don't really use but I have seen a lot of people use it in this forum.

Scanner sc = new Scanner(System.in);
int i = sc.nextInt();

As you can see it is simpler

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Write a Clock class which uses TimeAT class objects to store the current time and an alarm time. The Clock class should have 3 constructors:
- A no-arg constructor
- A constructor which takes one TimeAT object as an argument and sets the current time
- A constructor which takes two times objects as arguments and sets both times

class Clock {
 private TimeAT currentTime=null;
 private TimeAT alarm=null;

 public Clock () {
   currentTime = new TimeAT();
   alarm = new TimeAT();
 }

  public Clock (TimeAT currentTime, TimeAT alarm) {
   this.currentTime = currentTime;
   this.alarm = alarm;
 }

  public Clock (TimeAT currentTime) {
   this.currentTime = currentTime;
   this.alarm = new TimeAT();
 }

}

Now write get, set methods with the right arguments and the right return types according to the above. If you are not familiar with the 'this' keyword then you cal also do this:

public Clock (TimeAT curr, TimeAT al) {
   currentTime = curr;
   alarm = al;
 }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you have provided with java code, we could help, even if the code was wrong.
But if you have written it in another language, what do expect us to do? Write the entire application just to tell you that: Yes, it works in java!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thats ok after getting the data from the database i need to display the values in text fields. I mean when i select the username in drop down all the information of that perticular user should be displayed in the text.......which is nothing but getting user info...so wat i have to do?

What is your problem? Getting the data from DB or displaying them? Because displaying them is easy. Just call the setText() method of the JTextFields you have. It you want JTextArea call the append() method.
If it is JSP then use: <%= variable%> to display the value of variable in HTML

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the assignment is very wrong. The idea is to learn OOP. As other have understood your teacher should have said to create an object Student with the elements required and have an array of Students.

The way your code is written I would suggest all of your arrays will habe size 5.

grades[5] : you will store the average as a char
names[5] : the names of the 5 students
score1[5] : the score of Test 1 for the 5 students
score2[5] : the score of Test 2 for the 5 students
score3[5] : the score of Test 3 for the 5 students
score4[5] : the score of Test 4 for the 5 students

Anyway here is your code with my suggestions on reading and checking the scores:

for (int index=0; index < names.length; index++)
	{	
	names [index] = JOptionPane.showInputDialog(null,"Enter student's name: " + 
	(index + 1) + ": ");

       boolean correct=false;
       
        while (!correct) {
           double dScore = JOptionPane.showInputDialog(null,"Insert Score 1 for student "
  + index +": " );
           if (dScore  >= 0.0 && dScore  <= 100.0){
              score1[index] = dScore;
              correct = true;
           } else {
              JOptionPane.messageDialog(null,"Error try again");
           }
         }

correct=false;
while (!correct) {
           double dScore = JOptionPane.showInputDialog(null,"Insert Score 2 for student "
  + index +": " );
           if (dScore  >= 0.0 && dScore  <= 100.0){
              score2[index] = dScore;
              correct = true;
           }
}

correct=false;
while (!correct) {
           double dScore = JOptionPane.showInputDialog(null,"Insert Score 3 for student " …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Next time be more clear about what is your problem. From what I understood you don't know how to get and use the username from the comboBox?

If yes assume that you have a String username variable. For getting the value from a comboBox that has String elements do this:

String username = comboBox.getSelectedItem().toString() ;

Then create in a seperate class a method that take as argument that username and calls your query

class DBManager {
   public void/*or whatever you want to return*/ method(String username) throws SQLException {
 // code here
  }

And call it with argument what you get from the comboBox.

String username = comboBox.getSelectedItem().toString() ; 
DBManager dbM = new DBManager();
try {
  dbM.method(username);
} catch (Exception e) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And remove the System.exit(0), it will terminate the program

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming you something like this:

public class Calculator {

public static void main (String args[]) {
   String exp = JOptionPane.showInputDialog("Enter mathematical expression: ");
   exp = infixToPostfix(exp);
   JOptionPane.showMessageDialog(null,"Postfix expression: " +"\n"+ exp);
}

  public static String infixToPostfix (String infix) {

  (some codes here).........

  else {
    JOptionPane.showMessageDialog(null, "Invalid expression.");
    System.exit(0);
  }

}

You cannot return back to main, one the last command is executed the program ends and you don't need the System.exit(0)

try using a while loop that repeats the call to your method and when you enter a specific input exit the while.

boolean cont = true;
while (cont) {
String exp = JOptionPane.showInputDialog("Enter mathematical expression: ");
if (exp.equels("EXIT")) {
   cont=false;
} else {
   exp = infixToPostfix(exp);
   JOptionPane.showMessageDialog(null,"Postfix expression: " +"\n"+ exp);
}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I thought that he was trying to understand how the switch statements works. But now that you mentioned it the question looks a lot like a question from a test

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
int i=0;
switch (i) 
{
  case 1:
      System.out.println("Value 1");
      break;
case 2:
      System.out.println("Value 2");
	break;
}

The code checks 'i''s value. When it finds a case that has that value, it executes what is under it.
So the above code will print: "Value 1". Then break will be executed and it leave the switch. If you ommit break, then it will go to print the next 'case'. It will not make a check at each case:

int i=0;
switch (i) 
{
  case 1:
      System.out.println("Value 1");
case 2:
      System.out.println("Value 2");
	break;
}

The above will print:
"Value 1"
"Value 2"
And then break. If you add default, it will be executed if no case is found with the number at the switch

int i=3;
switch (i) 
{
  case 1:
      System.out.println("Value 1");
case 2:
      System.out.println("Value 2");
	break;
default:
      System.out.println("Default");
}

Will print: "Default"
Again with this all of them will be printed, since the break is missing:

int i=1;
switch (i) 
{
  case 1:
      System.out.println("Value 1");
case 2:
      System.out.println("Value 2");
default:
      System.out.println("Default");
}

"Value 1"
"Value 2"
"Default"

Now you don't need brackets at the switch, case. It will execute anything that is below it until it finds break

int i=1;
switch (i) 
{
  case 1:
      System.out.println("Value 1");
//command 1
//command 2
//.......
      break;
case 2:
      System.out.println("Value 2");
default:
      System.out.println("Default");
}

Meaning that you can add anything you want at "command 1" even a second switch/case

peter_budo commented: Been fooled by silly request, but provide great work +10
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you allowed to use these classes provided by java:
java.util.Vector
java.util.ArrayList ?
If yes then things are much easier

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually adiel224 even forgot to close the bracket :D

This will not compile:

public void update(....){
//complete here
.....

This will:

public void update(....){
//complete here
//.....
}

And that is the only help you will get after such post

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are doing nothing from what I suggested. You just wrote some commands without even knowing what they do. If you knew what they did you could just followed my advice and have a much better code.

You took the class a whole year and this was the best you could do?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you get the number of tosses write if statements checking the validity of the information.

You must have variables where you count the successes and the failures

Then use a for-loop to print the:

"Enter toss #"+i+ "output: "

followed by the command for reading from the console.
Once you read the 'h' or 't', call a method that randomly calculates a coin toss. Then compare the value calculated with the one entered and increment one of the above variables if it was successful or not.
Then continue with the loop the same code,

At the end print the results.

The Math.random() generates a random number between 0 and 1. Use this to get a random coin-toss (if it is 0 - 0.5 the 'h' or if it is 0.5-1.0 't')

For reading from the console:

BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
String input = keyboard.readLine();

pseudocode

N = get number of tosses

  for (i=1 to N) {
print: Enter toss #i output:
get toss from console
calculate random toss
compare them
update score variables 
  }
print the results
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The second window will have a conwstructor that will take as argument the first window:

public Frame2 (Frame1 f1)

The Frame1 (first window) will have variables that will take value from the second window when you click 'Add'. When you click 'Add' from the second window you will give values to the f1 variables. These variables could be type JTextField so at first they will be blank and then after 'Add' they will display what you get from second window

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If there isn't, why don't you create one, and post it on the Internet for others to take it. Isn't this what you are asking from the others?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all static methods are called this way: BankAccount.setName(accountName)
I hope that your methods are not static.

Second with this code, you create 2 new instances, when you need 1. You will need to have 1 instance and modify its values.

for(i = 1; i < totalAccounts; i++) {


	accountName = JOptionPane.showInputDialog("What is the name for the this account?: ");
	BankAccount ba1 = new BankAccount(i, 0, accountName);

	deposit = JOptionPane.showInputDialog("What is the balance for the this account?: ");
	BankAccount ba1 = new BankAccount(i, deposit, accountName);

        }

Second of all the set methods are supposed to be void and this should be wrong:
BankAccount ba1 = BankAccount.setName(accountName)

This is the right way:

void setName(String accountName) {
this.accountName = accountName;
}

Now of with the code:

With this code you create new instances: ba1, and you do nothing with them. Perhaps you should add them to an ArrayList as you progress:

ArrayList list=new ArrayList();

for(i = 1; i < totalAccounts; i++) {


	accountName = JOptionPane.showInputDialog("What is the name for the this account?: ");

//You don't need to create this instance and then create again a new one	
//BankAccount ba1 = new BankAccount(i, 0, accountName);

	deposit = JOptionPane.showInputDialog("What is the balance for the this account?: ");
	BankAccount ba1 = new BankAccount(i, deposit, accountName);

list.add(ba1);
        }

Now the list will have each bank account. If I understood correct, you want to loop through and modify them. Then do this:

for(i = 0; i < …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all static methods are called this way: BankAccount.setName(accountName)
I hope that your methods are not static.

Second with this code, you create 2 new instances, when you need 1. You will need to have 1 instance and modify its values.

for(i = 1; i < totalAccounts; i++) {


	accountName = JOptionPane.showInputDialog("What is the name for the this account?: ");
	BankAccount ba1 = new BankAccount(i, 0, accountName);

	deposit = JOptionPane.showInputDialog("What is the balance for the this account?: ");
	BankAccount ba1 = new BankAccount(i, deposit, accountName);

        }

Second of all the set methods are supposed to be void and this should be wrong:
BankAccount ba1 = BankAccount.setName(accountName)

This is the right way:

void setName(String accountName) {
this.accountName = accountName;
}

Now of with the code:

With this code you create new instances: ba1, and you do nothing with them. Perhaps you should add them to an ArrayList as you progress:

ArrayList list=new ArrayList();

for(i = 1; i < totalAccounts; i++) {


	accountName = JOptionPane.showInputDialog("What is the name for the this account?: ");

//You don't need to create this instance and then create again a new one	
//BankAccount ba1 = new BankAccount(i, 0, accountName);

	deposit = JOptionPane.showInputDialog("What is the balance for the this account?: ");
	BankAccount ba1 = new BankAccount(i, deposit, accountName);

list.add(ba1);
        }

Now the list will have each bank account. If I understood correct, you want to loop through and modify them. Then do this:

for(i = 0; i < …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try posting part of the code, and try putting a System.out.println() in the mouseclicked event before you call the function.

Personally I prefer actionEvents for just clicking

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The concept of stack is not unique in java. It applies not only in the programming world but everywhere, so I will explain the basic concept.

When you put items in a stack you place each one of them after the other. But when you try to take these items from the stack you can only take the last one you entered not the first. If you have a stack of plates you put one on top of the other, but you cannot take the one at the bottom (the one you put first), you must take the one at the top, which was the one you placed last.

In java, you can store objects in a stack the same way. Assume you call push several times:

push("AAA")
push("BBB")
push("CCC")

when you call the pop command you will get the value: "CCC". If you call pop again you will get the "BBB". You will be getting the items in the opposite order you put them


Now if you use an ArrayList and do this:

add("AAA")
add("BBB")
add("CCC")

And then try to get the values with method get(int i) , you will have the values in the order placed in them:
"AAA"
"BBB"
"CCC"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The second method, cboStart.addItem(1) also works just fine because auto-boxing will make the conversion to an Integer object for you.

OK, good to know.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem is in the evaluatePostfix method, as the error says.
Probably because the program goes to else if { ... } and you try to do a
int op1 = stack.pop()
If the stack is empty how can you pop something from it?
First check if the stack has values before calling pop. I am not very familiar with the Stack class but here is the API:
Stack
There is an empty() method that checks if the stack is empty or not

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What puneetkay is trying to say is that you must first read the input from the console and then do the calculations, not the other way around

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

cboStart.addItem(new Integer(1));
boStart.addItem(new Integer(2)); // and so one to 12
cboStart.addItem(1);
cboStart.addItem(2); // and so one to 12

Use any of these two methods.

Regards,
PuneetK

The: cboStart.addItem(new Integer(1)) will add Integer objects to the ComboBox and you will have to cast them to Integer when you get the values.
I Think the second is wrong since if I remember correctly the addItem() method takes Objects as arguments.

Better user this:

for (int i=1;i<=12;i++) {
    cboStart.addItem(new Integer(i)); //Integer objects in the ComboBox
}

or

for (int i=1;i<=12;i++) {
    cboStart.addItem( String.valueOf(i) ); //String objects in the ComboBox. Need to be casted to String when getting the values
}

It is not smart to write 12 lines of code when you can simply use a for-loop. What if [I]daniel50096230[/I] wanted to add to a ComboBox numbers for 1 to 31? It would be stupid to write this 31 times:

cboStart.addItem(new Integer(1))
cboStart.addItem(new Integer(2)) ...
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

To tell you the truth, after your post I decided to give a quick look at the code, and you know what, I don't agree with the way anything is written there.

It looks like, that kid should be more careful when copying others people code. If you don't understand it, you can't tell if it is correct

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

By the way, I don't agree with the way the ParserException is written. This is not the right way to extend the Exception class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you don't know java why are you starting with gui when you don't know even the basics of the language?
Start by writing simple console programs and learn how to use classes, extending them . . .

stephen84s commented: Exactly +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Another mistake that you made, hence the third different post so you will not confuse them is that you don't close the ResultSet, the pstm and the conn.

public boolean validateUser(String username, String password) {
        Connection conn = ConnectDB.getConnection();
        
        //write the query, executed, and return if the user can login or not
        try {
            pstat = conn.prepareStatement("select username,password from user 
where username= ? and password = ?");

            pstat.setString(1,username);
            pstat.setString(2,password);
            rs = pstat.executeQuery();

            if(!rs.next() && rs.getRow() == 0) {
                result = false;
            }
            else{
                result = true;   
            }
        }
        catch (Exception ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            throw ex;
        } finally {
             if (rs!=null) rs.close();
            if (pstat!=null) pstat.close();
           if (conn !=null) conn.close();
        }
        return result;
    }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your real problem is this:

public boolean validateUser(String username, String password) {
        Connection conn = ConnectDB.getConnection();
        
        //write the query, executed, and return if the user can login or not
        try {
            pstat = conn.prepareStatement("select username,password from user where username='"+ username + "' and password = '"+password+ "'");

            pstat.setString(1,username);
            pstat.setString(2,password);
            rs = pstat.executeQuery();

            if(!rs.next() && rs.getRow() == 0) {
                result = false;
            }
            else{
                result = true;   
            }
        }
        catch (Exception ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
        }
        return result;
    }
}

You catch the exception but you return the result (true or false) like nothing happened. You need to indicate to the one who called the method that something went wrong. If you simple print the error and then return the user will think that the password was wrong even though you had an exception. Try this:

public boolean validateUser(String username, String password) throws Exception {
        Connection conn = ConnectDB.getConnection();
        
        //write the query, executed, and return if the user can login or not
        try {
            
        }
        catch (Exception ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            throw ex;
        }
        return result;
    }
}

And now this:

do{
                loop = false;

                if(!canLogin) {
                    JOptionPane.showMessageDialog(null, "Wrong Username or Password, try again", "Warning !!!", JOptionPane.WARNING_MESSAGE);
                    jTextField1.setText("");
                    jPasswordField1.setText("");
                    loop = true;
                    break;
                } //end of if
                else {
                    JOptionPane.showMessageDialog(null, "Welcome, you can use the program ...", "Welcome", JOptionPane.WARNING_MESSAGE);	
                } //end of else
            } //end of do
            while (loop);

If the login is wrong you set …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read this post

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 = ?"
);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As the error says you have probably forgot to put somewhere a ")"

And if you can't debug something that simple or you don't know how to pass arguments, what are you doing writing that complex code (for you skills)?

How many programs that are executed from console have you written?
If you have written enough you should be able to fix this or at least understand that a line where the error has happened is required and not the entire code.
If not then you are moving too fast

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

wont let me do anything like that, first methode has to be
public static void main(String [] args);
it wont allow me to have anything but variables above it, no methods nothing.
wont even allow me to have a methode without a 'type' such as
public static unnamed();

/

That is because i wrote this:

public printMyName() {

}

When I should have written this:

public void printMyName() {

}

It was a simple mistake and you should have been able to correct it and not say that it cannot be done


Add a System.out.println("") at the begining of the mainmenu() method and see if it is called:

public static void mainmenu(String playername) {
   Sytem.out.println("mainmenu method called with: "+playername);
}

Does the playername printed? :

System.out.println("hello " + playername)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is an example for your problem followed by a link from this forum:

Static:

class Test {
public static printMyName() {
  System.out.println("My name IS  NEO");
}

public static void main(String [] args) {
   printMyName();

   //or

   Test.printMyName();

   //both will work
}
}

Non Static:

class Test {
public printMyName() {
  System.out.println("My name IS  NEO");
}

public static void main(String [] args) {
   Test test = new Test();
   test.printMyName();
}
}

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

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Which class has the main method?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where are you having problems.
For reading command line I use something like this:

BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter set of values:")
String input = keyboard.readLine();

If you enter:
3 4
Then the String input will have this value: "3 4"
So you can do something like this:

import java.io.*;

class IsRecSquare
{
	static int count;
	public static void main(String [] args)
	{
	
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

		do
		{

			System.out.println("Enter set of values:")
                        String input = keyboard.readLine().trim();
                        if (input.length != 0) {
                        //code for parsing input into 2 int numbers length and height
//use: StringTokenizer or String.split(), or (String.indexOf with String.subString())
                                 if (length == height) {
                                       count++;
                                  }
                        } 

		} while (!input.equals(""));
	
		System.out.println("The number of squares are : " + count);
	}
}

Of course you will add the necessary try-catch block

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No you haven't tried what I have suggested. See the code for reading from the file, using BufferedReader and readLine()

Alex Edwards commented: Incredibly patient! +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can have the <form> action be empty:
<form action="" ....>
If you do that you will be redirected in the same page. Then at the beginning of the page before you start displaying any GUI check if the form was submitted and if it was do your validation and if it is correct redirect to the page you want.
Or else continue displaying the rest of the page

<%
String phone=request.getParameter("phone");
String user=request.getParameter("user");
if ((phone!=null)&&(user!=null)) {
if (phone.trim().length()==0) {
   //error message
} else if (user.trim().length()==0) {
  //error message
} else {
   //do something with user and phone ....
   //maybe use javascript to do the redirect
%>
<!-- I am not sure about this, you might want to check it out on your own at the site that I provide -->
<script>
window.open(....)
</script>
<%
}
}
%>  

<body>

</body>

OR

you can send the <form> action to a servlet, do the validation there and then redirect to the page you want. Code at the servlet to decide where you want to go:

RequestDispatcher dispatcher =
    request.getRequestDispatcher(address);
  dispatcher.forward(request, response);

OR

much better solution than the other two, use javascript, without submitting the form
instead of submit use a button, and do:

<input type="button" value="Submit" onclick="validate()">

Then in the <head> tag write the validate() method using javascript and if all are correct submit the form

<form name="form1" action="someURL">

use: document.form1.submit()

For all the comments about javascript use:

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I presume that by back button you are referring to a browser and you have implemented that with JSPs.

In that case when the username and password are correct, save the username in the session before you redirect to the next page. Then when you go to the next page (and every page) always take the username from the session and check if it is not null.
When you logout remove the username from the session, so when you hit the back button and try to get the username from the session it will be null. Then you can redirect the user to the login page

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't know how many line the file will have so doing this is wrong:

inREAD = new FileReader(inFILE);
inBUFF = new BufferedReader(inREAD);
String BUFF = new String();
 
for(int lines=0; lines<24; lines++){
   BUFF = "";
   BUFF = inBUFF.readLine();
}

You assume that the file will have 24 lines but in general you will not know that. If the file has no more lines the inBUFF.readLine() will return null. And it will keep returning null for as long the loop runs. If you file has 3 lines the first 3 loop runs will give the values you want but the rest BUFF = inBUFF.readLine() will be null

So you use this:

String line = br.readLine(); //get the first line and check if it is null

while (line!=null) { if it is not null then the file has lines

//at the end you "read" the NEXT line and go at the beginning of the loop. If it is null means that there are no more lines and it does not enter the loop
line = br.readLine();
}

Since you don't know the exact size of the file you cannot use a fixed array:

public static String[] START = new String[23];

With the ArrayList you can add as many elements you want. If the file 1000 line the loop will run 1000 times and add to the ArrayList 1000 new items.
With the array you can only add 23 items, the size of the array.


javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After reading more carefully the rest of the thread I think you were trying to do this:
Read each line: <number> <String> <String>
If yes then combine this with the previous code:

ArrayList<Integer> routelength=new ArrayList<Integer>(); //I don't think you can store primitive types in the ArrayList
ArrayList<String> start=new ArrayList<String>();
ArrayList<String> finish=new ArrayList<String>();

//after reading the line within the while loop:
while(line!=null) {
  line=line.trim();

  String [] lineTokens = line.split(" ");

  if (lineTokens.length!=3) {
    System.out.println("Wrong line format");
  } else { 

     try {
        routelength.add(new Integer( lineTokens[0] ));
        start.add( lineTokens[1] )
        finish.add( lineTokens[2] );
     } catch (NumberFormatException nfe) {
        System.out.println("First token of line not a number");
     }

  } 

  line=br.readLine();
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For reading lines from a file:

BufferedReader br=null;
try {
            br = new BufferedReader( new FileReader( fileName ) );
           String line = br.readLine();
           
            while (line!=null) {
                  //do something with line
                   //you read each line of the file, You don't know how many lines the file will have



                 //the last command of the while:
                 line = br.readLine();
            } 
           
} catch (IOException e) {
   System.out.println(e.getMessage());
} finally {
       try {
             br.close();
       } catch (Exception e) {
             System.out.println("Could not close file");
               e.printStackTrace();
       }
}

What do you want to do with each line read in the while loop?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<form action="">

...
<input type="text" name="text1" ......>
...

<input type="submit" value="Submit">
</form>

If you don't understand the above, you are doing something wrong.
After you submit the form you will use:
request.getParameter() to take the values into String:

String text1 = request.getParameter("text1");

Then call the method that takes the above values and stores them into the database.

As for the database the is plenty of code to look for in this forum or look for tutorials

This is just an example:
http://www.daniweb.com/forums/post653467.html#post653467

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you created it dynamically using java, then you can the values that you displayed and write a method that take these values and store them in the database.

If the values, are user inputs then use the <form> tag and submit the form to another jsp, take the values (request.getParameter()) and use the above procedure

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Aren't you going to tell us where is the error?
And probably you are using a method that doesn't exist