mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Update sonarqube findings
This commit is contained in:
@@ -37,7 +37,7 @@ public class Problem11 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
//This is the grid of numbers that we will be working with
|
||||
protected static String FILE_NAME = "files/Problem11Grid.txt";
|
||||
protected static String fileName = "files/Problem11Grid.txt";
|
||||
protected static ArrayList<List<Integer>> grid;
|
||||
//Instance variables
|
||||
protected List<Integer> greatestProduct; //Holds the largest product we have found so far
|
||||
@@ -50,11 +50,11 @@ public class Problem11 extends Problem{
|
||||
}
|
||||
//Operational functions
|
||||
//Read numbers from file into grid
|
||||
private void readFile(){
|
||||
private static void readFile(){
|
||||
if(grid != null){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -37,7 +37,7 @@ import com.mattrixwv.ArrayAlgorithms;
|
||||
public class Problem13 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
protected static String FILE_NAME = "files/Problem13Numbers.txt";
|
||||
protected static String fileName = "files/Problem13Numbers.txt";
|
||||
protected static ArrayList<BigInteger> nums; //Holds the numbers that are being summed
|
||||
//Instance variables
|
||||
protected BigInteger sum; //The sum of all the numbers
|
||||
@@ -50,11 +50,11 @@ public class Problem13 extends Problem{
|
||||
}
|
||||
//Operational functions
|
||||
//Read number from file into nums
|
||||
private void readFile(){
|
||||
private static void readFile(){
|
||||
if(nums != null){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Problem18 extends Problem{
|
||||
|
||||
//Variables
|
||||
//Static variables
|
||||
protected String FILE_NAME = "files/Problem18Pyramid.txt";
|
||||
protected String fileName = "files/Problem18Pyramid.txt";
|
||||
protected static ArrayList<ArrayList<Integer>> list; //The list to hold the numbers in
|
||||
//Instance variables
|
||||
protected ArrayList<Location> foundPoints; //For the points that you have already found the shortest distance to
|
||||
@@ -83,7 +83,7 @@ public class Problem18 extends Problem{
|
||||
if(list != null){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.List;
|
||||
public class Problem22 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
protected static String FILE_NAME = "files/Problem22Names.txt";
|
||||
protected static String fileName = "files/Problem22Names.txt";
|
||||
//Holds the names that will be scored
|
||||
protected static ArrayList<String> names = new ArrayList<>();
|
||||
//Instance variables
|
||||
@@ -59,7 +59,7 @@ public class Problem22 extends Problem{
|
||||
if(!names.isEmpty()){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.List;
|
||||
public class Problem42 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
protected static String FILE_NAME = "files/Problem42Words.txt";
|
||||
protected static String fileName = "files/Problem42Words.txt";
|
||||
protected static ArrayList<String> fileWords = new ArrayList<>();
|
||||
//Instance variables
|
||||
protected ArrayList<String> triangleWords;
|
||||
@@ -51,7 +51,7 @@ public class Problem42 extends Problem{
|
||||
if(!fileWords.isEmpty()){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Problem67 extends Problem18{
|
||||
//Setup the list of numbers to check
|
||||
public Problem67(){
|
||||
super();
|
||||
FILE_NAME = "files/Problem67Pyramid.txt";
|
||||
fileName = "files/Problem67Pyramid.txt";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Problem8 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
//The 1000 digit number to check
|
||||
protected static String FILE_NAME = "files/Problem8Number.txt";
|
||||
protected static String fileName = "files/Problem8Number.txt";
|
||||
protected static String number;
|
||||
//Instance variables
|
||||
protected String maxNums; //Holds the string of the largest product
|
||||
@@ -47,11 +47,11 @@ public class Problem8 extends Problem{
|
||||
}
|
||||
//Operational functions
|
||||
//Read number from file into number
|
||||
private void readFile(){
|
||||
private static void readFile(){
|
||||
if(number != null){
|
||||
return;
|
||||
}
|
||||
File file = new File(FILE_NAME);
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
try{
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.mattrixwv.project_euler.exceptions.Unsolved;
|
||||
public class Problem9 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
protected int GOAL_SUM = 1000; //The number that we want the sum of a, b, and c to equal
|
||||
protected int goalSum = 1000; //The number that we want the sum of a, b, and c to equal
|
||||
//Instance variables
|
||||
protected int a; //The size of the first side
|
||||
protected int b; //The size of the second side
|
||||
@@ -59,18 +59,18 @@ public class Problem9 extends Problem{
|
||||
|
||||
|
||||
//Loop through all possible a's
|
||||
while((a < GOAL_SUM) && !found){
|
||||
while((a < goalSum) && !found){
|
||||
b = a + 1; //b must be larger than a
|
||||
c = Math.sqrt((a * a) + (double)(b * b)); //Compute the hyp
|
||||
|
||||
//Loop through all possible b's for this a
|
||||
while((a + b + c) < GOAL_SUM){
|
||||
while((a + b + c) < goalSum){
|
||||
++b;
|
||||
c = Math.sqrt((a * a) + (double)(b * b));
|
||||
}
|
||||
|
||||
//If the sum == 1000 you found the number, otherwise go to the next possible a
|
||||
if((a + b + c) == GOAL_SUM){
|
||||
if((a + b + c) == goalSum){
|
||||
found = true;
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TestProblem11 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem11.grid = null;
|
||||
RandomAccessFile file = new RandomAccessFile(Problem11.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(Problem11.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -81,7 +81,7 @@ public class TestProblem11 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem11.grid = null;
|
||||
Problem11.FILE_NAME = "/a";
|
||||
Problem11.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TestProblem13 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem13.nums = null;
|
||||
RandomAccessFile file = new RandomAccessFile(Problem13.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(Problem13.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -79,7 +79,7 @@ public class TestProblem13 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem13.nums = null;
|
||||
Problem13.FILE_NAME = "/a";
|
||||
Problem13.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TestProblem18 extends TestProblemBase{
|
||||
|
||||
@Override
|
||||
public void verifyReset(){
|
||||
assertEquals("files/Problem18Pyramid.txt", problem.FILE_NAME);
|
||||
assertEquals("files/Problem18Pyramid.txt", problem.fileName);
|
||||
assertEquals(new ArrayList<>(), problem.foundPoints);
|
||||
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
||||
assertEquals(0, problem.actualTotal);
|
||||
@@ -74,7 +74,7 @@ public class TestProblem18 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem18.list = null;
|
||||
RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(problem.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -89,7 +89,7 @@ public class TestProblem18 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem18.list = null;
|
||||
problem.FILE_NAME = "/a";
|
||||
problem.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -69,7 +69,7 @@ public class TestProblem22 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem22.names = new ArrayList<>();
|
||||
RandomAccessFile file = new RandomAccessFile(Problem22.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(Problem22.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -84,7 +84,7 @@ public class TestProblem22 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem22.names = new ArrayList<>();
|
||||
Problem22.FILE_NAME = "/a";
|
||||
Problem22.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TestProblem42 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem42.fileWords = new ArrayList<>();
|
||||
RandomAccessFile file = new RandomAccessFile(Problem42.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(Problem42.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -78,7 +78,7 @@ public class TestProblem42 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem42.fileWords = new ArrayList<>();
|
||||
Problem42.FILE_NAME = "/a";
|
||||
Problem42.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TestProblem67 extends TestProblemBase{
|
||||
|
||||
@Override
|
||||
public void verifyReset(){
|
||||
assertEquals("files/Problem67Pyramid.txt", problem.FILE_NAME);
|
||||
assertEquals("files/Problem67Pyramid.txt", problem.fileName);
|
||||
assertEquals(new ArrayList<>(), problem.foundPoints);
|
||||
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
||||
assertEquals(0, problem.actualTotal);
|
||||
@@ -69,7 +69,7 @@ public class TestProblem67 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem67.list = null;
|
||||
RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(problem.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -84,7 +84,7 @@ public class TestProblem67 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem67.list = null;
|
||||
problem.FILE_NAME = "/a";
|
||||
problem.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TestProblem8 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem8.number = null;
|
||||
RandomAccessFile file = new RandomAccessFile(Problem8.FILE_NAME, "rw");
|
||||
RandomAccessFile file = new RandomAccessFile(Problem8.fileName, "rw");
|
||||
file.getChannel().lock();
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
@@ -81,7 +81,7 @@ public class TestProblem8 extends TestProblemBase{
|
||||
problem.reset();
|
||||
|
||||
Problem8.number = null;
|
||||
Problem8.FILE_NAME = "/a";
|
||||
Problem8.fileName = "/a";
|
||||
|
||||
assertThrows(InvalidParameterException.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TestProblem9 extends TestProblemBase{
|
||||
@Test
|
||||
public void testSolve_notFound(){
|
||||
problem.reset();
|
||||
problem.GOAL_SUM = 1;
|
||||
problem.goalSum = 1;
|
||||
|
||||
assertThrows(Unsolved.class, () -> {
|
||||
problem.solve();
|
||||
|
||||
Reference in New Issue
Block a user