This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 60125
188
  • 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
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
follow-ups here
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!