Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 02:39 PM
Member
 
Join Date: Jul 2008
Posts: 2
cuellar14 is on a distinguished road
Help on Arrays...
My project consists in an array that adds, finds, deletes lists all the contenst within the array.

Here's the code for my menu but i don't know how to initiate the array or create the mthods to add, find or delete the contents...

I also need to do it using two different classes

Thank you



import java.io.*;
import java.text.*;
import javax.swing.*;

class CuellarProjectArray {

public static void main(String[] args) throws IOException{

String str, company;
int choice, selection;
boolean keepRunning = true;

do {

JOptionPane.showMessageDialog(null, "This program stores customer's information");
str = JOptionPane.showInputDialog(null, "What do you like to do?\n" + "(to add enter 1)\n" + "(to find enter 2)\n" + "(to delete enter 3)");
choice = Integer.parseInt(str);

switch(choice) {

case 1:
company = JOptionPane.showInputDialog(null, "Enter customer information");
break;

case 2:
company = JOptionPane.showInputDialog(null, "Enter customer information");
break;

case 3:
company = JOptionPane.showInputDialog(null, "Enter customer information");
break;

default:
JOptionPane.showMessageDialog(null, "Invalid choice");

}

selection = JOptionPane.showConfirmDialog(null, "Would you like to return to the main menu?", "Confirmation", JOptionPane.YES_NO_OPTION);

keepRunning = (selection == JOptionPane.YES_OPTION);

}while (keepRunning);
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2008, 02:53 PM
Member
 
Join Date: Jul 2008
Posts: 3
anandguna is on a distinguished road
use the for loop and iterate the array values

String a="arul";
for (int i=0;i<arraystring.length();i++)
{
if(a==arraystring[i])
{ System.out.println("match found");

}


}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-25-2008, 03:39 PM
Member
 
Join Date: Jul 2008
Posts: 2
cuellar14 is on a distinguished road
i don't understand how to use that... where would i put it?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-25-2008, 06:10 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
how to initiate the array
type[] name = new type[<size>]; // create an array
name[i] = new type(); // add an element to array at index i


You'll want to change the following to use a method for comparing the two strings in place of using ==
Code:
if(a==arraystring[i])

Last edited by Norm : 07-25-2008 at 06:12 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-25-2008, 10:16 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Hello anandguna
Quote:
Originally Posted by anandguna View Post
use the for loop and iterate the array values
Code:
String a="arul"; for (int i = 0; i < arraystring.length(); i++) if (a == arraystring[i]) System.out.println("match found");
As Norm pointed out, the equality in blue uses to == operator. In Java, if the == operator is used on two variables of object type, like a String for example, then the test will return true if the variables reference the same object. Otherwise false is obtained. Primitive types, like int byte boolean or double, are tested for equality by value, as they are not objects. To test if two strings are equal, use the boolean String.equals(String other) method. For example:
Code:
if (a.equals(arraystring[i])) { System.out.println("match found"); }
Please ask if you want me to explain more, anandguna.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 07-25-2008 at 10:18 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with arrays Jman New To Java 17 07-21-2008 04:34 AM
Arrays bunbun New To Java 1 04-09-2008 04:24 AM
new to arrays jimJohnson New To Java 1 04-08-2008 04:45 PM
2D-Arrays kbyrne New To Java 1 02-08-2008 12:08 AM
arrays help Warren New To Java 6 11-23-2007 09:23 PM


All times are GMT +3. The time now is 02:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org