• 100% Satisfaction Guarantee

LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 12554
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
29751445
LogicPro is online now

# I would like to request LogicPro to answer this question please.HA

### Resolved Question:

HA - count
The learning objective of this question is to illustrate the power of Java inheritance and polymorphism. Your response to this question is in multiple parts. You will submit your answers as specified at the end of this question.
To help you get started and to guide your development efforts for this assignment we have provided scaffolding code. Download and unzip the BlueJ project count.zip. Study the code along with the description below. Edit the code and submit the completed BlueJ project. We have also provided a unit test file to help you check your code.
Now, let us look at the question.
Consider an array of integers as below:
int[] a = {5, 2, -4, 3, 0, -5, 7, 11, 6, 13}
1. Complete the method named count(int[] a) in the class Count. The method should return the number of positive numbers in the array. Thus count(a) should return 7 (not counting the 2 negative numbers and 0).
2. On examining your code for count (your solution to part-a), you will see a test similar to this: if (a>0) {...}. If we were to now ask you to modify the countmethod so that it counted the number of negative numbers, it would be trivial: All that you would have to do is change the greater-than comparison operator (“>”)to the less-than operator (“<”). If we were to ask you to modify the count method to count the number of even numbers (whether positive or negative) then you would modify your code to have a test along the following lines: if (isEven(a)) {...}. Similarly, you could change your code for other types of counting (prime numbers, numbers greater than 10, etc). Note that in each case we can do any type of counting we like but we need to edit the code for the count method. This is a simple example of enhancing the functionality of existing code. For this part of the question, you will write Java code that allows you to enhance the counting functionality without modifying the code of existing methods. You will do this using the power of inheritance and polymorphism.
1. Complete the method countIF that is similar to your implementation of count (from the earlier part of this question) but takes as parameter an object that implements the appropriate test. The signature of countIF is as below:
int countIF( int[] a, Predicate p)
Complete the class Predicate which has just one method that returns true if the parameter is greater than 0:
boolean test(int x){ ... ? ... }
When countIF is invoked with a Predicate object, the behaviour will be as before: Your code will count the number of integers greater than 0 (i.e., the execution would return 7).
2. Now complete the two classes (IsNegative and IsEven) as subclasses of the Predicate class to help you count negative (IsNegative) and even numbers (IsEven).
class IsNegative extends Predicate {...}
class IsEven extends Predicate {...}
Note: IsNegative and IsEven classes should have a test method with the same signature as before: boolean test(int x). Once these classes have been written you will be able to pass in an instance of the appropriate class to countIF to do the testing we need:
1. countIF( a, new IsNegative() )
2. countIF( a, new IsEven() )
The first call above would return 2 for our array. The second call would return 4.
After completing and testing your solution, zip the entire BlueJ folder and submit it. Since your instructor will need all files in the project folder, make sure you zip the entire folder. For this question the names of the BlueJ project, Java class files, and the zip file you submit are given below:
• BlueJ project: count
• Java classes and Interfaces:
o Count.java (this will have two methods: count, and countIF)
o Predicate.java (a Java class with one method test)
o IsNegative.java (extends Predicate)
o IsEven.java (extends Predicate)
o CountTest.java (the unit test file - This file is fully complete. Do not modify this file.)
• Submit: count.zip
Submitted: 2 years ago.
Category: Programming
Expert:  LogicPro replied 2 years ago.
Hi
Welcome

Unzip to a real folder to get BlueJ completed project

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers.

It will ensure that question is for me.

so you can come back and ask me a question anytime.

Remember, if for any reason you are unsatisfied with my answer, we can continue the conversation until you’re satisfied and rate my answer as excellent. I can address follow up questions on original requirements at no extra charge and I’m always here to help.

Thank you for using this site!

Customer: replied 2 years ago.

Hi,

Can you please send this to me on another link as the URL you have sent is blocked.

Regards,

Azhar.

Expert:  LogicPro replied 2 years ago.
ok, I will
Expert:  LogicPro replied 2 years ago.
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 12554
Experience: Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

### What Customers are Saying:

• My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
< Previous | Next >
• My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
• This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex
• Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP
• I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin
• Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther
• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.

• ### ATLPROG

#### Satisfied Customers:

7260
MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Previous | Next >

### ATLPROG

#### Satisfied Customers:

7260
MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

### LogicPro

#### Satisfied Customers:

5514
Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

### lifesaver

#### Satisfied Customers:

936
Several years of intensive programming and application development experience in various platforms.

### ehabtutor

#### Satisfied Customers:

766
Bachelor of computer science, 5+ years experience in software development, software company owner

### Eljon

#### Satisfied Customers:

558
Founder of StockCanvas.com

### Rafael Martins

#### Satisfied Customers:

446
Desktop, Mobile and Web Developer. 7+ years of experience. Creative solutions provider.

### The-PC-Guy

#### Satisfied Customers:

320
Extensive Knowledge in PHP, MYSQL, CSS & Javascript