Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

gettin 6 errors of the same kind....unreported exception Exception /* Chapter 10

ID: 3887248 • Letter: G

Question

gettin 6 errors of the same kind....unreported exception Exception    

/*
Chapter 10: The User Class
Programmer:
Date: September 16, 2017
Filename: User.java
Purpose: To provide a User class to test the Password class
*/

public class User
{
    private String name;
    private Password pswd;

    public User(String aName, String password) throws PasswordException
    {
  name = new String(aName);
  pswd = new Password(password);
}
   public User(String aName, String password, int pswdUses) throws PasswordException
   {
          name = new String(aName);
          pswd = new Password(password,pswdUses);
}
public User(String aName, String password, boolean autoExpirePswd) throws PasswordException
     {
            name = new String(aName);
            pswd = new Password(password,autoExpirePswd);
}

public String getName()
{
  return new String(name);
}

public boolean pswdAutoExpires()
{
  return pswd.getAutoExpires();
}

public boolean pswdIsExpiring()
{
  return pswd.isExpiring();
}

public int getPswdUses()
{
  return pswd.getRemainingUses();
}

public void validate(String password) throws PasswordException
{
  pswd.validate(password);
}

public void changePassword(String oldPassword, String newPassword) throws PasswordException
{
  try
  {
   pswd.validate(oldPassword);
     }
     catch(PasswordExpiredException ex)
     {}

     pswd.set(newPassword);
}

}

Explanation / Answer

As you have not provided with the exact errors and the password class file.. i have created the dummy codes myself to compile the program successfully..

User.java:

public class User {

private String name;

private Password pswd;

public User(String aName, String password) throws PasswordException {

name = new String(aName);

pswd = new Password(password);

}

public User(String aName, String password, int pswdUses)

throws PasswordException {

name = new String(aName);

pswd = new Password(password, pswdUses);

}

public User(String aName, String password, boolean autoExpirePswd)

throws PasswordException {

name = new String(aName);

pswd = new Password(password, autoExpirePswd);

}

public String getName() {

return new String(name);

}

public boolean pswdAutoExpires() {

return pswd.getAutoExpires();

}

public boolean pswdIsExpiring() {

return pswd.isExpiring();

}

public int getPswdUses() {

return pswd.getRemainingUses();

}

public void validate(String password) throws PasswordException {

pswd.validate(password);

}

public void changePassword(String oldPassword, String newPassword)

throws PasswordException {

try {

pswd.validate(oldPassword);

} catch (PasswordExpiredException ex) {

}

pswd.set(newPassword);

}

}


Password.java:

public class Password {

public Password(String password, int pswdUses) {

// TODO Auto-generated constructor stub

}

public Password(String password) {

// TODO Auto-generated constructor stub

}

public Password(String password, boolean autoExpirePswd) {

// TODO Auto-generated constructor stub

}

public boolean getAutoExpires() {

// TODO Auto-generated method stub

return false;

}

public boolean isExpiring() {

// TODO Auto-generated method stub

return false;

}

public int getRemainingUses() {

// TODO Auto-generated method stub

return 0;

}

public void validate(String password) throws PasswordException{

// TODO Auto-generated method stub

}

public void set(String newPassword) {

// TODO Auto-generated method stub

}

}

PasswordException.java:


public class PasswordException extends Exception {

}

PasswordExpiredException.java:

public class PasswordExpiredException extends PasswordException {

}




Please use the methods defined in above files to put your own code.. If you still face issues.. let me know in comments.. also upload your password file.. then i will be able to help you completely.