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");
}
}}}