This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Newbie validation with textfile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie validation with textfile " Watch "Newbie validation with textfile " New topic
Author

Newbie validation with textfile

alexiel davis
Greenhorn

Joined: Sep 14, 2004
Posts: 4
I am newbie in java ..so I need some help in validation in java...

surname = b.readLine();
if (surname != null && surname != surname1)
then fileOut.write(surname, 0, surname.length());//write in file
else System.out.println(" exisiting users or no users");

for example, I am creating a new customer, so I try to read and write input...when I try to validate for the customer name,i am searching whether if the same person exist...

how do they know that I am trying to refer my surname 1 as the existing value in text file?Any suggestion or ideas to enlighten me?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
First, take a peek at String.equals(). String1 == String2 does not do what you need here.

Second, tell us where you got the list of existing names. You have one to test against in surName1 but you're likely to have a bunch of existing names. Maybe your program looks like this:

Understanding line #1 will help you form line #3.
[ September 15, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
alexiel davis
Greenhorn

Joined: Sep 14, 2004
Posts: 4
What I was trying to do..
1. Prompt for the cust value like firstName.
2. Try to validate when I get my value. Write into the file and then I can generate the custid using treemap
3. When I try to validate the first value like firstname, I meet my first problem.How can I get to validate when the object is not created
if (firstName != null && firstName != firstName// how to compare to data in file when I don't know what to use to compare with the input(firstName).

So I guess that the only way I will know about the value that is stored in the Customers container is by using the get(CustID) method in the treemap. If it returns null,then the Customer does not exist in the container. Do I sound reasonable?
alexiel davis
Greenhorn

Joined: Sep 14, 2004
Posts: 4
I wrote the following code using the treemap to generate ID customer,put it to the treemap and try to validate the customer details. Unfortunately before I can even validate the customer details...i meet some prob with generating the ID...

public class Customer extends Account
{private String ID; //declare instance variable for customer record
Customer( String ID, ....)//constructor to create customer obj
this.ID = ID;.......//construct new customer record with details
then.....
public void createCust() throws IOException
{System.out.print("Your new ID: " + ID); //hope to show that createCust() method is being run it will show that a new ID is created
try{
if (TreeMap.size()== 0) //if there is no key-value in the treemap
ID = "000000";//then ID will be 000000
else
new Customer ID = TreeMap.lastkey() + 1;//if there is key-value then this new ID = the last key of the treemap + 1(e.g 000000 + 1 = 1
} catch (IOException ioe) {
System.out.println("IO error trying to give you your customer id!");
System.exit(0);
CustomerMap.put(ID, Customer); // associate ID with the collection of customer obj...
}

Right now I don't really know whether I have problem in logical reasoning or did I wrote the code wrongly...can someone help me to point out my error and teach me how should i go about it?Thanks...
Abhi Raj
Greenhorn

Joined: Sep 08, 2004
Posts: 7
I'm not sure if I completely understand but :

public class Customer extends Account
{
private String Id; // instance variable for customer record
ArrayList currentIds;

static
{
//Load all Ids in from file -> currentIds
}

// Private so can only create a customer using createCustomer()
private Customer(String _Id)
{
Id = _Id;
// Write new customer to file + add id to list
}

// Create customer with given id
public void createCustomer(String ID) throws
{
// Search list for ID - if it exists already,
throw exception
// otherwise create the Customer
}

// Create customer with own generated id
public void createCustomer()
{
// Generate an id not already in the list
// create customer
}


};
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie validation with textfile
 
Similar Threads
Java to PseudoCode
Conversion help plz!!!
CMT
B&S Booking a Record
reading from one file, calculating, writing to another...