Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Add industry as a field of the Lead class You can make the type just String or you can define an Enum class for

JAVA

Add industry as a field of the Lead class

You can make the type just String or you can define an Enum class for valid values

This will require you to modify/add functions

Define a new class Rule. It should include:

a String instance variable (field) for the name of the rule

two Predicate instance variables, one for Lead and one for User

these are to determine true/false whether a particular Lead or User matches this rule

Predicate is defined in java.util.function.Predicate

A BiConsumer instance variable for a Lead and a User

This determines what to do if you want to execute this rule with

A method function canApply that takes a Lead and a User and returns true if both satisfy the requirements of the Rule

Use the Predicates to check this

Remember that a Predicate is an object, so you need to call its test(T) method

A method function execute that takes a Lead and a User and executes the Rule if both satisfy the requirements

Call canApply() to test the Lead and User

If the requirements are satisfied, use the BiConsumers accept() to take the correct action

The requirements for the test cases follow. You are encouraged to start running test cases before finishing all of the code. This will help you see if you are on the right track and provide an early check on whether you can write and run the test cases properly.

Define JUnit test cases to check each of the following rules:Any lead can be assigned to any online user

Include cases for both a lead being unassigned and assigned. The assertion should confirm that the lead is not re-assigned

Include a case where no user is online.

By Location, with a Specific User: Leads from a particular country must be assigned to a specific user

It is usually best to start with the good scenario that you would want to run to demo the application to a client. Here, have a lead from the desired country and have the desired user be online

Add cases with leads from the wrong country and with the desired user being offline. The assertions should confirm that assignments are not made

By Industry, with a Group of User: Leads from a particular industry are assigned to one of a group of users

Include cases where there are leads from the desired industry as well as leads from other industries

Include cases with multiple leads that show that leads are assigned to users in a round-robin order

Write code to cover these cases so they pass. [One common error people make when they start with unit tests is to write tests in a way that you know will fail. You want to get all the test cases to pass.]

For the criteria, you can choose to write classes that implement the Predicate and BiConsumer interfaces, or you can write lambdas that satisfy those interfaces, or you can choose a mix of the two approaches.

If you write lambdas, that code is graded as part of the source code vs. the test case code.

You do not need to update the main program to use rules.

To submit, attach both your unit test files and your source files include files even if you didnt make changes. This will make it easier for me to run your test cases in case you used different class or method names. It is probably best to compress the src and, if you have it, the test folder as separate compressed folders so that when downloaded there will not be a naming conflict.

Lead.java

package crm; import java.util.*;

//need to create a list that stores names, email address, and users assigned. public class Lead { private String leadName; private String emailAddr; private String country; private User assignUser; //lead constructor public Lead(String leadName, String email, String country) { this.leadName = leadName; this.emailAddr = email; this.country = country; } //create a getter and setter for each variable //name getter setter// public void setName(String name) { this.leadName = name; } public String getName() { return leadName; } //email getter setter// public void setEmail(String Email) { this.emailAddr = Email; } public String getEmail() { return emailAddr; } //country getter and setter// public void setCountry(String Country) { this.country = Country; } public String getCountry() { return country; } //User getter and setter for the assigning a user to a lead public void setUser(User assignedUser) { this.assignUser = assignedUser; } public User getUser() { return assignUser; }

} USER.java

public class User {

private String name;

private boolean isOnline;

private List assignedLeads;

public User(String name, boolean isOnline) {

this.name = name;

this.isOnline = isOnline;

this.assignedLeads = new ArrayList<>();

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public boolean isOnline() {

return isOnline;

}

public void setOnline(boolean online) {

isOnline = online;

}

public List getAssignedLeads() {

return assignedLeads;

}

AssignLeads.java

public class AssignLeads {

private List leads;

private List users;

public AssignLeads() {

this.leads = new ArrayList<>();

this.users = new ArrayList<>();

}

public void addLead(Lead lead) {

leads.add(lead);

}

public void addUser(User user) {

users.add(user);

}

public void assignLeads() {

for (Lead lead : leads) {

User user = getAvailableUser();

if (user != null) {

user.getAssignedLeads().add(lead);

lead.setAssignedUser(user);

}

}

}

private User getAvailableUser() {

for (User user : users) {

if (user.isOnline() && user.getAssignedLeads().size() < 2) {

return user;

}

}

return null;

}

public void displayLeads() {

System.out.println("Name Country Email Assigned User");

for (Lead lead : leads) {

System.out.println(lead.getName() + " " + lead.getCountry() + " " + lead.getEmail() + " " + (lead.getAssignedUser() != null ? lead.getAssignedUser().getName() : ""));

}

}

public static void main(String[] args) {

AssignLeads assignLeads = new AssignLeads();

Scanner scanner = new Scanner(System.in);

int cmd = -1;

while (cmd != 0) {

System.out.println("0. Quit");

System.out.println("1. Add a lead");

System.out.println("2. Add a user");

System.out.println("3. Assign leads");

System.out.println("4. Display leads");

System.out.print("Please choose a cmd (0-4): ");

cmd = scanner.nextInt();

if (cmd == 1) {

System.out.print("Please enter a name for the lead: ");

String name = scanner.next();

System.out.print("Please enter an email contact for the lead: ");

String email = scanner.next();

System.out.print("Please enter the country where the lead is located: ");

String country = scanner.next();

Lead lead = new Lead(name, email, country);

assignLeads.addLead(lead);

} else if (cmd == 2) {

System.out.print("Please enter a name for the user: ");

String name = scanner.next();

System.out.print("Is the user online? (true/false) ");

boolean isOnline = scanner.nextBoolean();

User user = new User(name, isOnline);

assignLeads.addUser(user);

} else if (cmd == 3) {

assignLeads.assignLeads();

} else if (cmd == 4) {

assignLeads.displayLeads();

}

}

}

}

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

Explain the relationship between thoughts, feelings, and actions.

Answered: 1 week ago