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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with this program! I am stuck

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
follow-ups here
 
    Bookmark Topic Watch Topic
  • New Topic