aspose file tools*
The moose likes Beginning Java and the fly likes help with this program! I am stuck Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

help with this program! I am stuck

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76
I want to create 10 Instances and loop though them, if there is a match for password and username..I print the details of the user....here is the program that I wrote! that I want to fix to be able to compplete it's task.

import java.util.Scanner;
/**
* Person details
* @author valoyi
*
*/
public class Person {

private String name;
private String surname;
private String address;
private String username;
private String email;
private int password;
/**
* default contractor.
*/
public Person(){}
/**
* A contractor to initialize all the parameters.
* @param name
* @param surname
* @param address
* @param username
* @param email
* @param password
*/
public Person(String name,String surname,String address,String username,
String email,int password){
this.name = name;
this.surname = surname;
this.address = address;
this.username = username;
this.email = email;
this.password = password;
}
/**
* get the name.
* @return name.
*/
public String getName(){
return name;
}
/**
* get the name.
* @param name
*/
public void setName(String name){
this.name = name;
}
/**
* get the surname
* @return
*/
public String getSurname(){
return surname;
}
/**
*
* @param surname
*/
public void setSurname(String surname){
this.surname = surname;
}
/**
*
* @return
*/

public String getAddress(){
return address;
}
/**
*
* @param address
*/
public void setAddress(String address){
this.address = address;
}
/**
*
* @return
*/
public String getUsername(){
return username;
}
/**
*
* @param username
*/
public void setUsername(String username){
this.username=username;
}
/**
*
* @return
*/
public String getEmail(){
return email;
}
/**
*
* @param email
*/
public void setEmail(String email){
this.email = email;
}

public int getPassword(){
return password;
}
/**
*
* @param password
*/
public void setPassword(int password){
this.password = password;
}

/**
*
* @return
*/
public String toString(){
return "Name=" + getName() + "Surname="+ getSurname()
+ "Address=" + getAddress()+ "Username="+ getUsername()
+ "email="+ getEmail() + "password="+getPassword();
}






/**
* main method
* @param args
*/
public static void main(String[] args) {
// Create the first object of the person class.
Person object1= new Person("Donnald","Funy","Sandton","valoyivd","hello",100);
//
Scanner kbInteger = new Scanner(System.in);
Scanner kdString = new Scanner(System.in);
//give the user three attempts to enter the right password and username.
for(int j=1 ; j<=3 ; j++)
{
// password must be a combination of integers.
System.out.println("Enter password :");
int k = kbInteger.nextInt();

// username must be a String of characters.
System.out.println("Enter username :");
String kc = kdString.nextLine();
// compare the username and password to see if it is valid.
if(k==object1.password && kc.equals(object1.username) ){
System.out.println("Welcome");
System.out.println(object1);
break; }

else{
System.out.println("Incorrect password or username");

}

}}}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40071
    
  28
You aren't that far out. Please tell us what you think is going wrong with your application, and why.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11500
    
  16

follow-ups here


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with this program! I am stuck