Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These is the instruction(PLEASE HELP ME RUN) 02. Second Assignment The FacebookUser Class Were going to make a small change to the UserAccount class from

These is the instruction(PLEASE HELP ME RUN)

02. Second Assignment The FacebookUser Class

Were going to make a small change to the UserAccount class from the last assignment by adding a new method:

public abstract void getPasswordHelp(); 

This method is abstract because different types of user accounts may provide different types of help, such as providing a password hint that was entered by the user when the account was created or initiating a process to reset the password. Next we will create a subclass of UserAccount called FacebookUser. The FacebookUser class needs to have the following fields and methods in addition to what is in UserAccount:

Fields:

String passwordHint ArrayList friends 

Methods:

void setPasswordHint(String hint) void friend(FacebookUser newFriend) void defriend(FacebookUser formerFriend) ArrayList getFriends() 

The friend method should add the FacebookUser argument to the friends ArrayList (if that FacebookUser is already in the friends list, display an error message), and the defriend method should remove the FacebookUser argument from that ArrayList (if that FacebookUser is not in the friends list, display an error message). The getFriends method should return a copy of this users friends create a new ArrayList with the same FacebookUsers in it as this users friends. Do not return the friends ArrayList directly, since this violates the principle of encapsulation. The getPasswordHelp method should display the passwordHint. The FacebookUser class should also implement the Comparable interface. FacebookUsers should be sorted alphabetically by username, ignoring capitalization. (Hint: notice that the toString method returns the username of the UserAccount.) Finally, write a driver program that creates several FacebookUsers and demonstrates the user of the setPasswordHint, friend, defriend, getFriends, and getPasswordHelp methods. Also, put the FacebookUser objects into an ArrayList,

sort them (see the jar file for this topic for help on this), and print them out in sorted order.

This is my code please help fix:

//Facebook driver

import java.util.ArrayList; import java.util.Collections; import java.util.List;

public class facebookDriver1 {

public static void main(String[] args) { // TODO Auto-generated method stub FacebookAccount account1= new FacebookAccount("Venessa Black","fl11"); FacebookAccount account2=new FacebookAccount("Jack Lord","Flyon"); FacebookAccount account3=new FacebookAccount("Daniel MStar","Straight"); FacebookAccount account4=new FacebookAccount("Noah Ark","Flatscreen"); System.out.println(" ");

account1.setPasswordHint("bestfriends name"); account1.get_Help(); account1.friend(account2); account1.friend(account3); account1.friend(account4);

System.out.println("Venessa's friends"+account1.getFriends());

account1.defriend(account2); account1.defriend(account2);

ArrayListfriends=new ArrayList(); friends.add(account1); friends.add(account2); friends.add(account3); friends.add(account4); System.out.print("Unsorted"); for(FacebookAccount faceBook:friends) {System.out.println(" friends FacebookAccount:"+faceBook); } Collections.sort(friends); System.out.print("Sorted :"); for(FacebookAccount facebook:friends) { System.out.println("friends FacebookAccount:"+facebook); } System.out.println(" "); } }

//Facebook Account

import java.util.ArrayList;

public class FacebookAccount extends UserAccount implements Comparable {

String passwordHint;

private ArrayListfriendoffriend;

public FacebookAccount(String username, String password) {

// TODO Auto-generated constructor stub

super(username,password);

passwordHint="";

friendoffriend=new ArrayList();

}

public void setPasswordHint(String bigHint) {

// TODO Auto-generated method stub

this.passwordHint=bigHint;

}

public void get_Help() {

// TODO Auto-generated method stub

System.out.println("Password hint:"+passwordHint);

}

public void friend(FacebookAccount newFriend) {

// TODO Auto-generated method stub

if(friendoffriend.contains(newFriend)) {

System.out.println(newFriend+"Is already a frend.");

}else {

friendoffriend.add(newFriend);

}

}

public ArrayList getFriends() {

// TODO Auto-generated method stub

return new ArrayList(friendoffriend);

}

public void defriend(FacebookAccount newFreind2) {

// TODO Auto-generated method stub

if(friendoffriend.contains(newFreind2)) {

friendoffriend.remove(newFreind2);

}else {

System.out.print(newFreind2+"is not my friend");

}

}

@Override

public int compareTo(FacebookAccount o) {

// TODO Auto-generated method stub

return this.toString().toLowerCase()

.compareTo(other.toString().toLowerCase());

}

@Override

public void getPasswordHelp() {

setPasswordHint(passwordHint);

System.out.print("Password hint:"+passwordHint);

}

}

UserAccount

public class UserAccount {

private String username;

private String password;

private boolean active;

public UserAccount(String username, String password) {

// TODO Auto-generated constructor stub

this.username=username;

this.password=password;

active=true;

}

public boolean checkPassword(String password) {

boolean passwordMatch;

if (password.equals(this.password)) {

passwordMatch = true;

} else {

passwordMatch = false;

}

return passwordMatch;

}

public void deactivateAccount() {

active = false;

}

public boolean isactive() {

return active;

}

@Override

public int hashCode() {

final int primevalue = 31;

int output = 1;

output = primevalue * output + (active ? 1231 : 1237);

output = primevalue * output

+ ((password == null) ? 0 : password.hashCode());

output = primevalue * output

+ ((username == null) ? 0 : username.hashCode());

return output;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

UserAccount other = (UserAccount) obj;

if (username == null) {

if (other.username != null)

return false;

} else if (!username.equals(other.username))

return false;

return true;

}

@Override

public String toString() {

return "Username: " + username + " ";

}

// end UserAccount

public void getPasswordHelp() {

// TODO Auto-generated method stub

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science Project Ideas In Health Care Volume 1

Authors: Zemelak Goraga

1st Edition

B0CPX2RWPF, 979-8223791072

More Books

Students also viewed these Databases questions

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago