mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated sonarqube recommendations
This commit is contained in:
@@ -35,7 +35,7 @@ import com.mattrixwv.project_euler.problems.Problem;
|
||||
public class Benchmark{
|
||||
private Benchmark(){}
|
||||
private static final Scanner input = new Scanner(System.in);
|
||||
private enum BenchmarkOptions{RUN_SPECIFIC, RUN_ALL_SHORT, RUN_ALL, EXIT, SIZE};
|
||||
private enum BenchmarkOptions{RUN_SPECIFIC, RUN_ALL_SHORT, RUN_ALL, EXIT, SIZE}
|
||||
private static final ArrayList<Integer> tooLong = new ArrayList<>(Arrays.asList(15, 23, 24, 35));
|
||||
//The driver function for the benchmark selection
|
||||
public static void benchmarkMenu() throws InvalidResult{
|
||||
@@ -73,12 +73,7 @@ public class Benchmark{
|
||||
//Determines if a value is a valid menu option. Helper for getBechmarkMenuSelection
|
||||
private static boolean isValidMenu(int selection){
|
||||
//Ordinal + 1 because enum starts at 0
|
||||
if((selection > 0) && (selection < (BenchmarkOptions.SIZE.ordinal() + 1))){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
return (selection > 0) && (selection < (BenchmarkOptions.SIZE.ordinal() + 1));
|
||||
}
|
||||
//A helper function for getMenuSelection that turns an integer to a BenchmarkOptions
|
||||
private static BenchmarkOptions getSelection(Integer selection){
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.mattrixwv.exceptions.InvalidResult;
|
||||
|
||||
public class Driver{
|
||||
//An enum to hold the possible menu selections
|
||||
private enum SELECTIONS{SOLVE, DESCRIPTION, LIST, BENCHMARK, EXIT, SIZE};
|
||||
private enum SELECTIONS{SOLVE, DESCRIPTION, LIST, BENCHMARK, EXIT, SIZE}
|
||||
private static final Scanner input = new Scanner(System.in);
|
||||
|
||||
//Drives the program
|
||||
|
||||
@@ -23,7 +23,6 @@ package com.mattrixwv.project_euler;
|
||||
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
@@ -36,12 +35,12 @@ import com.mattrixwv.project_euler.problems.*;
|
||||
public class ProblemSelection{
|
||||
private static final Scanner input = new Scanner(System.in);
|
||||
//Holds the valid problem numbers
|
||||
public static final List<Integer> PROBLEM_NUMBERS = new ArrayList<>(Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
67));
|
||||
protected static final List<Integer> PROBLEM_NUMBERS = Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
67);
|
||||
|
||||
private ProblemSelection(){
|
||||
}
|
||||
|
||||
@@ -110,17 +110,8 @@ public class Problem19 extends Problem{
|
||||
//Add the correct number of days for every month
|
||||
while(currentMonth < month){
|
||||
switch(currentMonth){
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12: numDays += 31; break;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11: numDays += 30; break;
|
||||
case 1, 3, 5, 7, 8, 10, 12: numDays += 31; break;
|
||||
case 4, 6, 9, 11: numDays += 30; break;
|
||||
case 2:
|
||||
if(isLeapYear(currentYear)){
|
||||
numDays += 29;
|
||||
|
||||
@@ -64,6 +64,10 @@ public class Problem32 extends Problem{
|
||||
return (getProduct() == secondSet.getProduct());
|
||||
}
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return (2 * multiplicand) + (3 * multiplier);
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return String.format("%d%d%d", multiplicand, multiplier, getProduct());
|
||||
}
|
||||
|
||||
@@ -105,11 +105,7 @@ public class Problem37 extends Problem{
|
||||
continue;
|
||||
}
|
||||
switch(primeString.charAt(strLoc)){
|
||||
case '0' :
|
||||
case '2' :
|
||||
case '4' :
|
||||
case '6' :
|
||||
case '8' : isTruncPrime = false; break;
|
||||
case '0', '2', '4', '6', '8' : isTruncPrime = false; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user