Win a copy of Spring in Action (5th edition) this week in the Spring forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

help with this program! I am stuck  RSS feed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Report post to moderator
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");

}

}}}
 
Marshal
Posts: 61718
193
  • Mark post as helpful
  • send pies
  • Report post to moderator
You aren't that far out. Please tell us what you think is going wrong with your application, and why.
 
lowercase baba
Posts: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
follow-ups here
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!