The Artima Developer Community
Sponsored Link

Java Answers Forum
require some help in java project please?

3 replies on 1 page. Most recent reply: May 21, 2002 3:41 AM by Tarba Dan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
atif

Posts: 2
Nickname: saab
Registered: May, 2002

require some help in java project please? Posted: May 18, 2002 6:02 PM
Reply to this message Reply
Advertisement
Hi??

i have a problem in java...and i'm not quite sure how to solve it, and was wandering if anyone would be able to help me out here...

i have started something but not sure what to do next.
Here is the problem:

Problem 1
A program accepts identification number, first name, last name, and email address of a user. It validates the data as per following specifications:

.identification number ? no blanks, four numerical characters;
.first name ? no blanks, all alphabetical characters;
.last name ? same as for first name;
.email address?
.no blanks;
.only one ?@?character;
,there is at least one word before ?@?, and at least two words after ?@?, both words(following ?@?) joined by ?.?, no space between the words before and after the ?.? character.
Assume that there are maximum of two words following ?@?character, and there are maximum of 25 characters in the email address.

If any of the data item is invalid, program displays an appropriate message to the user and asks for re-entry of that item.
When all data items entered are valid, program creates a password for the user by joining:
.first two characters of first name;
.2nd and 3rd characters of identification
.last three characters from the last name;
in above order.
Password is then relayed back to user. Later then enters this password and program then checks that user has entered the correct password (as created for him/her), and displays the message to the user accordingly.

You do not need to create any special user interface but must utilize string and array processing functions

and here is my source code so far.. if any one helpful enough could fix the program for me that would be much appreciated..thanks
kind regards,
Atif.

public class UserValidation {

//declare variables
private int id;
private String firstname;
private String lastname;
private String email;

private BufferedReader input = new BufferedReader // Handles console input
(new InputStreamReader(System.in));

public int getId() throws IOException{

System.out.println("Input UserID:");

id = Integer.parseInt(input.readLine());

getId();
}
return id;
}

public String getfName(){

return firstname;
}

public String getlName(){
return lastname;
}

public String getEmail(){
return id;
}

public void display(){

System.out.println(" " + getId() + getfName() + getlName() + getEmail());
}

public static void main (String args[]){
UserValidation user = new UserValidation();

user.display();
}
}


Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Re: require some help in java project please? Posted: May 19, 2002 11:41 PM
Reply to this message Reply
You didn't say what your problem was so I modified the code in order to compile and to print the user id
import java.io.*;
 
public class UserValidation { 
 
   //declare variables 
   private int id = 0; 
   private String firstname = ""; 
   private String lastname = ""; 
   private String email = ""; 
 
   private BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); 
 
   
   public UserValidation(int id, String firstname, String lastname, String email){
      this.id = id;
      this.firstname = firstname;
      this.lastname = lastname;
      this.email = email;
   }
 
   //you can throw NumberFormatException to verify if the user entered an integer
   // parseInt throws a NumberFormatException if the argument is not valid 
   public int getId() throws IOException{ 
 
      System.out.println("Input UserID:");    
      id = Integer.parseInt(input.readLine());    
      return id; 
  } 
 
  public String getfName(){ 
     return firstname; 
  }   
 
  public String getlName(){ 
     return lastname; 
  } 
 
  public String getEmail(){ 
     return email; 
  } 
     
  public void display(){ 
     // you must catch the IOException thrown by getId function
     try{ 
        System.out.println("  " + getId() + " " + getfName() + " " + getlName() + "  " + getEmail()); 
     }catch(IOException io){
          
     }
  } 
 
   public static void main (String args[]){ 
        //initialize user data members with an   appropriate constructor or set functions 
        UserValidation user = new UserValidation(1234,"Tarba","Dan","dtarba@yahoo.com"); 
 
        user.display(); 
   } 
}//:~ [/java/

atif

Posts: 2
Nickname: saab
Registered: May, 2002

Re: require some help in java project please? Posted: May 20, 2002 1:37 AM
Reply to this message Reply
hey Dan,
thanks for your reply and for modifying my program..
one other question i wanted to ask you, was how can i do i create the password.. and how do i check for blanks and alphabetical characters for username..

kind regards,
Atif.

Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Re: require some help in java project please? Posted: May 21, 2002 3:41 AM
Reply to this message Reply
The password and the username are strings. You can manipulate strings with the StringTokenizer class.

For example if you have the next string :

"Username and password"
and I want to print the words in this phrase one by one :

  import java.util.StringTokenizer ;
 class Strings {
  public static void main(String[]) args){ 
 
      String str = "Username and password";
      StringTokenizer strTokenizer = new 
                 StringTokenizer(str);
 
      while(strTokenizer.hasMoreTokens())
         System.out.println(strTokenizer.nextToken());
  }
}


The output should be :
Username
and
password

The way you write the password to the disk is your choice. There are a thousand algorithms you can use to crypt the password or you can create one of your own.

I hope this will help. If not, next time include more details about what you're interested.


Tarba Dan

Flat View: This topic has 3 replies on 1 page
Topic: to increment a time function to draw graphs Previous Topic   Next Topic Topic: web browser

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use