import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int option;
User myUser = new User();
System.out.print("Enter username: ");
myUser.setUserName(input.nextLine());
System.out.print("Enter password: ");
myUser.setPassword(input.nextLine());
System.out.print("Enter email: ");
myUser.setEmail(input.nextLine());
do {
System.out.println("Choose what to do : ");
System.out.println("1. Print current information.");
System.out.println("2. Change password.");
System.out.println("3. Exit.");
System.out.print("Your option: ");
option = input.nextInt();
switch(option) {
case 1: System.out.println("Your user's information: ");
myUser.printInfo();
break;
case 2: myUser.changePassword();
break;
}
} while (option != 3);
}
}
class User {
private String userName;
private String password;
private String email;
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassword(String password) {
this.password = password;
}
public void setEmail(String email) {
this.email = email;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
public void printInfo() {
System.out.println("Username : " + getUserName());
System.out.println("Password : " + getPassword());
System.out.println("Email : " + getEmail());
}
public void changePassword() {
Scanner input = new Scanner(System.in);
String newPassword;
System.out.println("Enter new password: ");
newPassword = input.nextLine();
while (newPassword.equals(password)) {
System.out.println("Error. Enter a new password: ");
newPassword = input.nextLine();
}
password = newPassword;
}
}
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int option;
User myUser = new User();
System.out.print("Enter username: ");
myUser.setUserName(input.nextLine());
System.out.print("Enter password: ");
myUser.setPassword(input.nextLine());
System.out.print("Enter email: ");
myUser.setEmail(input.nextLine());
do {
System.out.println("Choose what to do : ");
System.out.println("1. Print current information.");
System.out.println("2. Change password.");
System.out.println("3. Exit.");
System.out.print("Your option: ");
option = input.nextInt();
switch(option) {
case 1: System.out.println("Your user's information: ");
myUser.printInfo();
break;
case 2: myUser.changePassword();
break;
}
} while (option != 3);
}
}
class User {
private String userName;
private String password;
private String email;
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassword(String password) {
this.password = password;
}
public void setEmail(String email) {
this.email = email;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
public void printInfo() {
System.out.println("Username : " + getUserName());
System.out.println("Password : " + getPassword());
System.out.println("Email : " + getEmail());
}
public void changePassword() {
Scanner input = new Scanner(System.in);
String newPassword;
System.out.println("Enter new password: ");
newPassword = input.nextLine();
while (newPassword.equals(password)) {
System.out.println("Error. Enter a new password: ");
newPassword = input.nextLine();
}
password = newPassword;
}
}