MaryT Tsele

Greenhorn
+ Follow
since Oct 30, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by MaryT Tsele

Hello Everyone.
I am new in java and intend taking the exam sometime next year early. Should I take the 1.4 or 1.5. Are they still offering the 1.4 exams or not. And can someone please tell me what is the difference between someone holding 14. and 1.5 or even 1.3 for that matter.Is it about being certified or about which version you got the certification on.If someone has an older version, does it mean that they have to upgrade every time a newer version comes? Please explain.
I agree with Jeroen, the only way you can learn is to attempt doing it. Write something so that we know exactly where you need help. Writting you code is not going to get you any where. So please try and start by writing code that will ask the user for imput even if is not date of birth, it can be a number,may be once you start you wont be that stuck and we will defenately know where to help.
[ December 12, 2006: Message edited by: MaryT Tsele ]
11 years ago
Hi Jide

Welcome to the ranch.

You might want to use a switch statement to alternate between your keys.If your calculator GUI has a textfield, which will be the only textfield.Create the methods for add,minus,multiply and divide,do your calculations in this methods by getting the value from the textfield,then in your case:key(specify the key to be pressed) call the methods you have created. I hope this will help.Feel free to reply if you are still confused.
Good luck.
11 years ago
Hi Bear.

Thank you for attending to my question.And please accept my appology for not using the forum.

The �results� is a collection of data that I am getting out of the database using the ff method from a class called UserDAO. So I have another class which is called RoleDAO which retrieves the roles for the users from the database in the same way as the UserDAO class. I need to put the output of both classes(results and roleResults) on the same jsp page.

[code:]
public class UserDAO {

public Collection getAllUsers(){

Session session = SessionUtil.currentSession();
Criteria criteria = session.createCriteria(User.class);
criteria.addOrder(Order.asc("username"));
Collection result = criteria.list();
return result;
}
}
[code:]

Class for Roles:

[code:]
public class RoleDAO {

public Collection getRoles(){

Session session = SessionUtil.currentSession();
System.out.println("Staring the session");
Criteria criteria = session.createCriteria(Role.class);
criteria.addOrder(Order.asc("roleName"));
Collection roleResult = criteria.list();
return roleResult;
}
}
[code:]
11 years ago
JSP
Hi guys.
I am a new programmer still learning java.Is it possible to use the logic:iterate tag twice in the same JSP.I have used it to retrieve data from the database as follows.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:form action="/User.do?action=add">
<h2>List of users</h2>
<table width="40%" border="3" >
<tr>
<th>UserId</th>
<th>Username</th>
<th>Password</th>
<th>Action</th>
<th>Action</th>
</tr>
<logic:iterate id="elem" name="results" type="za.co.johnboy.vo.UserVO">
<tr>
<td align="right"><bean:write name="elem" property="userId"/></td>
<td><bean:write name="elem" property="username"/></td>
<td align="right"><bean:write name="elem" property="password"/><br></td>
<td><a href="User.do?action=update&userId=<bean:write name='elem' property='userId'/>">[Update]</a></td>
<td><a href="User.do?action=delete&userId=<bean:write name='elem' property='userId'/>">[Delete]</a></td>
</tr>
</logic:iterate>
<tr>
<td colspan="6" align="center">
<html:submit value="Add User"/>
</td>
</tr>
</table>
</html:form>
Now I need to iterate through a different class in order to get the output on the same page. Please help.
11 years ago
JSP

Originally posted by pascal betz:
Hi

first: you might want to look at the java.util.List and (one of the implementations java.util.ArrayList); unless required you should use these classes instead of Vector (Vector is synchronized, ArrayList is not. Butboth iomplement the List itnerface).

But your problem still stays :-)
Iterating over a List is possible in two ways:
- use the index
- use the iterator

if you check out the API doc of List you will find the methods to get elements out of a List using the index of the item.

also in the API you will find the Iterator interface which can also be used to iterate over a List.

btw: in your example code there is just one element in your Vector: a String[] (and i assume you want to have two items beeing the two names)

lets see if this gets you further....

pascal



Thank you Pascal and Svend
I tried using the ArrayList, it worked fine, but I am not sure why I put the line Object names = (Object) iter.next(); in the for loop. It sort of popped out, and I decided to put Object and the code worked, please explain.
And I also did the vector one, it also works but throws an exception after printing the contents. please help.

Check code for Array List:
***************************************************************************
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Test2 {
private String name1 = "kim";
private String name2 = "Mary";

public Test2(){
ArrayList array = new ArrayList();
array.add(name1);
array.add(name2);

for (Iterator iter = array.iterator(); iter.hasNext() {
Object names = (Object) iter.next();
System.out.println(names);
}

}
public static void main( String[ ] args ){
new Test2();

}
}
*************************************************************************
Check the coe for Vector:

import java.util.Vector;

public class Test{
private String name1 = "kim";
private String name2 = "Mary";
private Vector vec ;

public Test(){
vec = new Vector();
vec.addElement(name1);
vec.addElement(name2);

for(int i=0;i <=vec.size();i++){
System.out.println(vec.elementAt(i));
}
}
public static void main( String[ ] args ){
new Test();

}
}
throws this exception:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at Test.<init>(Test.java:15)
at Test.main(Test.java:19)
kim
Mary
Exception in thread "main"
11 years ago
Hello guys, I am new in Java and would like to have some advice on iterating and printing the contents of a vector.Below is a code of what I have done.

import java.util.Vector;

public class Test{
private String []names = {"Mary","kim"};
private Vector vec ;

public Test(){
vec = new Vector();
vec.add(names);
for(int i=0;i <= vec.size();i++){
//I need to print the contents of vec System.out.println("");
}
}
public static void main( String[ ] args ){
new Test();

}
}
11 years ago