Eclipse (JUnit4) Kata programming help

Watch
Janjua
Badges: 2
Rep:
?
#1
Report Thread starter 6 years ago
#1
Hey guys can someone please help with this question. If possible can someone code and briefly explain what you have done. I have previously done anagram katas but never this one. I have attempted a few lines of coding (in bold) but still nothing. Thanks a lot.

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
class _KataAssessment {

* Verify whether a given list of Integers contains only square numbers.
*
* For example, if the argument is the following:
*
* [ 1, 4, 9, 16, 25 ]
*
* the method should return <code>true</code>. If the argument is the
* following:
*
* [ 2, 3, 4, 6, 8, 19 ]
*
* the method should return <code>false</code>.
*
*
* @param numbers
* a list of possible square numbers
*
* @return <code>true</code> if all the lists in the argument contain
* anagrams and <code>false</code> otherwise
*/
public static boolean verifySquares(List<Integer> numbers) {
// COMPLETE THIS METHOD
Object verifySquares;
if(verifySquares == numbers );
return true;

return false;
}
}
public class KataAssessment {
private static final List<Integer> EMPTY = new LinkedList<Integer>();
private static final List<Integer> SQUARES = Arrays.asList(1, 4, 9, 16, 25,
36, 64, 81);
private static final List<Integer> NOT_SQUARES = Arrays.asList(1, 2, 3, 5,
6, 7, 8, 10);
private static final List<Integer> MIXED = Arrays.asList(1, 2, 3, 4, 5, 6,
7, 8, 9);
private static final List<Integer> NEGATIVE = Arrays.asList(0, *1, *2, *3,
*4, *5, *6, *7, *8, *9);
@Test
public void testSquares() {
Assert.assertTrue(_KataAssessment.verifySquares(SQUARES));
}
@Test
public void testEmpty() {
Assert.assertFalse(_KataAssessment.verifySquares(EMPTY));
}
@Test
public void testNonSquares() {
Assert.assertFalse(_KataAssessment.verifySquares(NOT_SQUARES));
}
@Test
public void testMixed() {
Assert.assertFalse(_KataAssessment.verifySquares(MIXED));
}
@Test
public void testNegatives() {
Assert.assertFalse(_KataAssessment.verifySquares(NEGATIVE));
}

}
0
reply
VannR
Badges: 21
Rep:
?
#2
Report 6 years ago
#2
Create a while loop that checks whether p, the number in the array, satisfies (p % x) == x, where x is the square root of p. If this is true then p is a square number, and you should create an exit flag, such as setting exit = true, with while condition being exit == false.

EDIT: thought you were looking for arrays without squares. Exit the loop if (p % x) != x.

That's the program logic down for you. I would post in full Java. but I'm a bit rusty.
1
reply
Janjua
Badges: 2
Rep:
?
#3
Report Thread starter 6 years ago
#3
(Original post by VannR)
Create a while loop that checks whether p, the number in the array, satisfies (p % x) == x, where x is the square root of p. If this is true then p is a square number, and you should create an exit flag, such as setting exit = true, with while condition being exit == false.

EDIT: thought you were looking for arrays without squares. Exit the loop if (p % x) != x.

That's the program logic down for you. I would post in full Java. but I'm a bit rusty.
Well thanks for the explanation anyway
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Are you tempted to change your firm university choice on A-level results day?

Yes, I'll try and go to a uni higher up the league tables (49)
28.49%
Yes, there is a uni that I prefer and I'll fit in better (14)
8.14%
No I am happy with my choice (96)
55.81%
I'm using Clearing when I have my exam results (13)
7.56%

Watched Threads

View All