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

Specification: Write a class called Account that represents a user account. The

ID: 3800725 • Letter: S

Question

Specification: Write a class called Account that represents a user account. The class contains two instance variables: userName (a String), and phoneNumber (a String). Write a constructor that initializes these. Write getName(), getNumber(), and setNumber(). Also, write a toString() method. Then, write a class ComputerAccount that extends Account by adding two instance variables: login (a String), and password (a String). Write a constructor that initializes all instance variables. Use super() to invoke the parent's constructor. Write a set and get method for both of these. Also, include a method goodPassword() that tests if the password is secure and returns true or false. For ComputerAccount, a secure password consists of eight or more characters and includes both upper and lowercase letters. Include a tostring() method. Although not really a good idea, have toString() include both the login and the password. Then, write a class SecureAccount that extends ComputerAccount. For SecureAccount include a goodPassword() method that requires the password to be have all of the characteristics required for ComputerAccount, but in addition has at least one digit. Of course, use super in this method. The charAt() method of String and the isUpperCase(), isLowerCase(), and isDigit() methods of class Character will be useful. Running: Test and play with your classes from the BlueJ interface. You don't need a main method. What to turn in Turn in just the files Account.java, ComputerAccount.java and SecureAccount.java. Don't turn in the entire BlueJ project.

Explanation / Answer

// Account.java

class Account
{
String userName, phoneNumber;

Account(String n, String p)
{
userName=n;
phoneNumber=p;
}

public String getName()
{
return userName;
}
public void setName(String n)
{
userName=n;
}
public String getNumber()
{
return phoneNumber;
}
public void setNumber(String n)
{
phoneNumber=n;
}



  
}

// ComputerAccount.java


class ComputerAccount extends Account
{
String login, password;

ComputerAccount(String n, String p, String l, String pwd)
{
super(n,p);
login=l;
password=pwd;
}
public String getLogin()
{
return login;
}
public void setLogin(String n)
{
login=n;
}
public String getPassword()
{
return password;
}
public void setPassword(String n)
{
password=n;
}

public boolean goodPassword()
{
char[] c;
boolean u=false, l=false;
if(password.length()>=8)
{
c=password.toCharArray();
for(int i=0; i<c.length; i++)
{
if(Character.isUpperCase(c[i])) // if uppercase letter found
u=true;
else if(Character.isLowerCase(c[i])) // if lowercase letter found
l=true;
}

if( u && l) // if uppercase and lowercase both are true
return true;
else return false;
}
  
else return false;
}
public String toString()
{
return userName+" "+phoneNumber+" "+login+" "+password;
}
}

//SecureAccount.java

class SecureAccount extends ComputerAccount
{
SecureAccount(String n, String p, String l, String pwd)
{
super(n,p,l,pwd);
}

public boolean goodPassword()
{
char[] c;
boolean d=false, u=false, l=false;
if(password.length()>=8)
{
c=password.toCharArray();
for(int i=0; i<c.length; i++)
{
if(Character.isDigit(c[i]))
d=true;
else if(Character.isUpperCase(c[i]))
u=true;
else if(Character.isLowerCase(c[i]))
l=true;
}

if(d && u && l)
return true;
else return false;
}
  
else return false;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote