can you tell me why we create constructor?
We use/call constructors to create instances of objects. In that way we can call the methods of the class.
We define different constructors for different functionality based on their arguments.
can you tell me why we create constructor?
We use/call constructors to create instances of objects. In that way we can call the methods of the class.
We define different constructors for different functionality based on their arguments.
This is a java forum. What you wrote is javascript
When do you want the validation to happen? When you click the submit button?
An easy way would be to have a button(type="button") and an onclick event:
<input type="button" value="Click" onclick="validate();" />
Then define a validate
function, inside it use javascript to take the values of the fields you want to validate and if successful submit the form.
You will find good tutorials here:
http://www.w3schools.com/default.asp
private While w; public static void main(String[] args) { w = new While(); } public While() { printLoop(); doSomethingElse(); etc. }
The Code that you wrote jon.kiparsky, will not compile. Please don't post code that you haven't tested.
Also it is better to learn to call methods after initializing an object through the constructor.
The code posted by tong1 is a very good advice:
public static void main(String args[]) {
While w= new While();
w.printLoop();
}
How are we suppose to know what is wrong? Do you get any errors?
Also at the toString method you do correctly this:
public String toString(){
StringBuffer sb = new StringBuffer();
for(int i = 0; [B]i < this.count[/B]; i++)
sb.append(items[i] + ", ");
return sb.toString();
}
You use the count as the top limit at the for loop. You need to do the same for the other methods.
Also since the count is private, you need a get method (not a set method because you don't want others to change its value). The value of count needs to change only inside the class, so correctly you had it to be private.
But I would do this:
In the class:
private int count = 0;
public int getCount() {
return count;
}
System.out.println("The list.count: " + list.getCount());
If you try to use the List class in another java program then you wouldn't be able to call the: list.count
You can read the employee id and set it to a javascript variable like this:
var empId = "<%= request.getParameter("EmployeeID") %>";
I don't know your logic but subtracting the id by one will not always get you the previous employee. You can not expect that the ids will always be sequential.
When you go to that page you need a way to know the previous and next id.
You need to know all the ids from the database when you go to that page for the first time. Then when you go next or previous, when the page loads, you have the current id, so just find the previous and next, and use those values.
when you submit the form, what is the action attribute. Maybe you need when each button is clicked to submit to a different jsp page. From there you will need to retrieve the data from request:
<a href="retreive.jsp?EmployeeID=<%=previousId%>">Previous</a>
<a href="retreive.jsp?EmployeeID=<%=nextId%>">Next</a>
You will also need to post more code and stop confusing java with javascript
Because this is null:
request.getParameter("txtname")
Try to learn first jsp before attempting such code. You need to use javascript.
And don't do that:
<% out.println(....); %>
Use <%= ....%> . It is the right way.
I have never tried what you want to do but a quick look at the API will get you what you want.
Have you tried looking at the API of the JButton class. If you look at the constructor there is one that accepts an Icon. If you search the page for a setIcon method you will find the class: AbstractButton. JButton extends that class and has access to all of its methods.
If you look at its API you will find several setIcon methods that your JButton instance can call.
Also you will find a setUI method.
Do a little digging and tell us what you have found.
The error says: test.java (at line 3)
What code do you have at lines 1,2 ?
Have you posted the entire code?
What java version are you using? Scanner is available at 1.5 and later
yes..or maybe someone who knows the codes for this program
No one is going to give you the code unless you show some code of your own; more specifically, what have you done so far?
Try to print the query, and then take it the way it is and run to an sql editor:
String q="select order_num from Order where recev_fname='"+itemn+"'";
System.out.println("Qeury: "+q);
What errors do you get?
Also it is good to declare this: BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
outside the for loop.
Also you'd better add this in order to know what was the problem:
catch(Exception e)
{
System.out.println("Problem with the program: "+e.getMessage());
}
There shouldn't be any problem with NetBeans or any other IDE. The code not working rarely has anything with the IDE.
If you have some code that you can't get to work just post it with specific questions.
But first read some tutorials on how to read data from database (and store them into objects).
Then read about JTable and how to display values.
Then use the values from the object and display them at the JTable
You do this: crt.CusDetails.derCusData and this: crt.derCusData.derCusData
What type are the crt, CusDetails, derCusData.
Is CusDetails inside the MyShoppingCartNew like an inner class? If yes then you don't need that.
That is not how you call methods:
crt.CusDetails.derCusData(String fname,String sname,String phone,String email,String address1,String street,String address3,String area,String ddate,String dtime)
Your error is very basic and has nothing to do with jsp or web programming. I don't want to sound harsh but if you can't fix this error then you go back to learn better the basics.
In case in was an honest mistake that you just missed and didn't correct it even if you knew the answer then that is ok.
It is up to you to decide what you need:
crt.CusDetails.derCusData(fname,sname,phone,email,address1,String street,address3,area,ddate,dtime)
Also after that line you do this:
int crt=crt.getcost();
That is no correct either. You declare an int: crt, and you have above another variable with the same name: crt.CusDetails
WRIGHT A PROGRAM IN C WHICH REQUEST SCORES STORES THEM IN AN ARRAY , THEN IT CALCULATES THE MEAN, Deviations FROM MEAN, STD DEVIATION AND THEN IT PRINTS THE THREE(MEAN, AVERAGE, DEVIATIONS, STD DEVIATION.)
Don't yell( meaning don't use capitals) we are not DEAF.
Also start a new thread.
Also this is a java forum not a C forum.
Also post some code. Don't expect someone to give you the answer. If you don't know where to start, explain specifically what is your problem
In One jsp have the form with all the fields and a submit button:
<form [B]action="two.jsp"[/B] name="someName">
.....
<SELECT name="month">
<OPTION selected value="01">1</OPTION>
<OPTION value="02">2</OPTION>
</SELECT>
.....
<input type="submit" value="I authorised this transaction">
</form>
And in the other jsp:
two.jsp
String monthSelected = request.getParameter("month");
what is a school time table project. explain further and post your requirements
Check the API of the ArrayList class. There is a remove method that you can use.
Or you can use the Vector class that is similar to the ArrayList. Check their APIs to find a method "remove" that is suitable for you.
Why should we write such program. I have no use for that, and I am not interested in finding the longest substring in two given strings that is common to both. Some things are better left unknown.
If you want to find the longest substring in two given strings that is common to both then show some effort by posting some code and ask your question in a better manner.
I didn't understand much your response, but are you saying that you take the value from the text area and you add those "junk values" (%20) ?
If I understood correctly, why do you do this?
Why it is saved like this:
a%20b%20c%20d
How to you send the values and how you retrieve them?
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/math/BigInteger.html
//BigInteger(String val)
//Translates the decimal String representation of a BigInteger into a BigInteger.
BigInteger bi1 = new BigInteger("123123414123412341241243");
If you look at that link you will find the methods that do what you want. Create 2 BigInteger objects and then call the methods you want:
BigInteger bi1 = new BigInteger("123123414123412341241243");
bi1.method(<argumnets>);
That still doesn't matter since the line
db2Crns=testDB2Connect.getDb2LoggedInCrns();
would screw everything up if the method getDb2LoggedInCrns returns a raw list.public class Tester { public static void main(final String[] args) { List<Integer> ints = new ArrayList<Integer>(); ints = getList(); ints.get(0).intValue(); // KABOOM!!! } private static List getList() { List<String> strings = new ArrayList<String>(); strings.add("HI"); return strings; } }
Which is why, in one of my previous posts I asked for the code of the method he is calling:
Can you post what that method does? getDb2LoggedInCrns
And then I asked for the signature since the poster didn't post any code after my initial request.
I am still waiting for ashwiniku's response about the method he is calling that returns that list.
db2Crns.get(i) returns a String and you are trying to cast it to an Integer hence the error. Use Integer.parseInt for parsing an integer from a string.
But 'db2Crns' is declared like this:
ArrayList<Integer> db2Crns=new ArrayList<Integer>();
Can you post the signature of the getDb2LoggedInCrns method?
Is it like something this?
public ArrayList<Integer> getDb2LoggedInCrns () {
..
}
or
public ArrayList getDb2LoggedInCrns () {
..
}
Just look at the API of the class BigInteger. Use the constructor to create the object and use the methods it has for adding, subtracting, ....
BigInteger bi1 = new BigInteger("123123414123412341241243");
Have you tried looking at the BigInteger class:
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/math/BigInteger.html
Have you looked at the link I provided?
What is the point of making questions if you don't bother to read people's answers?
Posting the error message that you get, would help a lot.
At that line you call:
db2Crns=testDB2Connect.getDb2LoggedInCrns();
does it return an ArrayList that has correct values inside?
I don't believe you should get an error. Can you post what that method does? getDb2LoggedInCrns
Have you tried looking at the BigInteger class:
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/math/BigInteger.html
The error is very clear:
java.lang.String cannot be cast to java.lang.Integer
You are trying to cast a String object to an Integer. That cannot be done. They are not of the same type.
The error tells you at what line of your file that happened, so you can correct it.
Don't expect us to count all that code line by line, until we find the line where the error occurred:
com.kotak.autoblocknb.transaction.Transaction.main(Transaction.java:38)
Then use a separate String variable. In the for loop concatenate all the elements of the array into that String variable and then display that variable.
Initialize it outside the for loop. Give it value in the for loop. Then after the loop display it.
strArray += array[k] + ", ";
From what I see you have your select tags inside a for loop?
That would mean that the html generated will have more than one <select> tag.
If you use the request.getParameter, it will always return the first value.
But you send at the request many <select> "items" with name nextTask and newStatus.
So I would suggest to use the method that returns an array of value.
If I remember:
String [] nextTask = request.getParameterValues("nextTask");
I am not sure about the method. Check the API for the method that returns an array of Strings.
Another thing you could do is this:
<input type="hidden" name="numOfItems" value="<%=numOfItems%>" >
<select name="nextTask_<%=i%>">
And:
int numOfItems = Integer.parseInt(request.getParameter("numOfItems "));
for (int i=0;i<numOfItems ;i++) {
String nextTask = request.getParameter("nextTask_"+i);
}
Maybe you should convert the char that you get to an int.
Convert this: '2' to the int 2.
Instead when you do this:
int i = '1';
You are not setting the int 1 but the ASCII value of the character '1' which is something else.
Try something like this:
Add = Integer.parseInt( String.valueOf(Given_Id.charAt(i)) );
It looks like its in the constructor for JFrame.
I find it hard to believe that that code could throw such exception. Don't forget that the line numbers you get from the errors have nothing to do with the line numbers that appear in the post. You shouldn't rely that a line of code here is at the exact line in the poster's java file
At errors you get it says this:
at JFrameDemo.main(JFrameDemo.java:8)
What does it say at the line 8 of the file JFrameDemo.java. Something there is null
You have 2 for loops one inside the other. And if you omit the code inside them you get something like this:
for (count=0;count<11;count++) {
for (count=0;count<frequency.length;count++) {
}
}
You are using the same variable to access two entire different arrays. And the fact that they might have the same length doesn't mean anything. When the inner loop finishes execution the count would have the value of frequency.length. Then its value will increase because of the outer loop and since it is not lower than 11 the outer loop will exit.
Try using this code from now on:
int[] array = new int[11];
for (int count=0;count<[B]array.length[/B];count++) {
array[count]
....
for (int k=0;k<[B]frequency.length[/B];k++) {
frequency[k]
}
}
Never hard code numbers.
Also another error:
input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ");
num = Integer.parseInt(input);
while (num < 0 || num > 99)
{
JOptionPane.showMessageDialog( null, "Must be between 0 and 99",
"ERROR!", JOptionPane.ERROR_MESSAGE );
num = Integer.parseInt(input);
input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ");//Suggested by professor Imroz.
}
num = Integer.parseInt(input)
input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ")
If the number is not between 1,99 then you should ask the user for a new number. But you first use the same input, which would be wrong, and then you ask for a new input.
Imagine entering -10, (input="-10", num=-10)
You go inside the while and after the …
Do you know how to use try-catch?
You can call the Integer.parseInt(String) method and if it throws an exception then it is not an int.
i badly need this before july 21,
Start a new post, use code tags, and give more explanations. What is wrong with your code? What is your question?
It should be && instead of ||
And why do you use the + It is not necessary.
Also you don't need this:
(uInput1 > uInput2 || uInput1 > uInput3)? +uInput1: +uInput2
If the uInput1 is not the max, then why do you assume that the uInput2 is the max?
Use simple if-else if-else statements
i am php developer , do i need java knowledge before learning jsp , if yes why so?
Yes, you do need java, because JSPs are basically html code with java inside. You need to know calling methods, creating custom classes, creating instances of those classes.
You cannot just start writing jsp code without knowing java because there is not such thing as jsp code.
In the WordCheck constructor you have it backwards. You are suppose to set the value of the class attribute wordsUsed. Instead you change the argument and the wordsUsed attribute of the WordCheck never takes value and it is null.
Also what is the purpose of the condition method ? It will always return the argument, so I don't see a purpose there. In the for loop it will always return true and the loop will never end
Good luck with that
properties is an array. It doesn't have these methods:
printPropertyDetails, addProperty.
For printing loop the array and take each Property object from the array and print that.
As for adding you need to do what you do at the beginning of your program. You have the count variable. So add the next property there and increase it:
if (num == 1) {
if (count<properties.length) {
properties[count] = new Property("ID", "description", "location", 0.0);
count++;
} else {
System.out.println("properties is full");
}
}
I post reply for those persons whose pc could dispaly chinese and who can understand chinese ,not u who can only code in english! u r not internet men,but me!
byebye daniweb.com!
And what if someone has a problem and expects an answer. Does he have to know Chinese to get that answer otherwise he's screwed ?!
The descriptions are very clear. Just create separate classes for each part. For the account part just create the Account class.
In the main call those constructors to create what is asked. You will need a menu for that.
If you must have One account per Customer then you may use a Hashtable where the key would be the CustomerID and the value the Account object of that customer.
From your thread we fail to understand what exactly is your question and where is your problem
The error is very clear:
symbol : variable lengh
from the errors that you get. Learn how to read them and give it a try, before posting here
It says it cannot find the symbol lengh. Check your book or the tutorial you took the code from. It should say length