Updated sonarqube recommendations

This commit is contained in:
2022-12-04 15:41:32 -05:00
parent 8e25c9338f
commit 62a8589364
6 changed files with 16 additions and 31 deletions

View File

@@ -35,7 +35,7 @@ import com.mattrixwv.project_euler.problems.Problem;
public class Benchmark{ public class Benchmark{
private Benchmark(){} private Benchmark(){}
private static final Scanner input = new Scanner(System.in); 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)); private static final ArrayList<Integer> tooLong = new ArrayList<>(Arrays.asList(15, 23, 24, 35));
//The driver function for the benchmark selection //The driver function for the benchmark selection
public static void benchmarkMenu() throws InvalidResult{ 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 //Determines if a value is a valid menu option. Helper for getBechmarkMenuSelection
private static boolean isValidMenu(int selection){ private static boolean isValidMenu(int selection){
//Ordinal + 1 because enum starts at 0 //Ordinal + 1 because enum starts at 0
if((selection > 0) && (selection < (BenchmarkOptions.SIZE.ordinal() + 1))){ return (selection > 0) && (selection < (BenchmarkOptions.SIZE.ordinal() + 1));
return true;
}
else{
return false;
}
} }
//A helper function for getMenuSelection that turns an integer to a BenchmarkOptions //A helper function for getMenuSelection that turns an integer to a BenchmarkOptions
private static BenchmarkOptions getSelection(Integer selection){ private static BenchmarkOptions getSelection(Integer selection){

View File

@@ -29,7 +29,7 @@ import com.mattrixwv.exceptions.InvalidResult;
public class Driver{ public class Driver{
//An enum to hold the possible menu selections //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); private static final Scanner input = new Scanner(System.in);
//Drives the program //Drives the program

View File

@@ -23,7 +23,6 @@ package com.mattrixwv.project_euler;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
@@ -36,12 +35,12 @@ import com.mattrixwv.project_euler.problems.*;
public class ProblemSelection{ public class ProblemSelection{
private static final Scanner input = new Scanner(System.in); private static final Scanner input = new Scanner(System.in);
//Holds the valid problem numbers //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, 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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
67)); 67);
private ProblemSelection(){ private ProblemSelection(){
} }

View File

@@ -110,17 +110,8 @@ public class Problem19 extends Problem{
//Add the correct number of days for every month //Add the correct number of days for every month
while(currentMonth < month){ while(currentMonth < month){
switch(currentMonth){ switch(currentMonth){
case 1: case 1, 3, 5, 7, 8, 10, 12: numDays += 31; break;
case 3: case 4, 6, 9, 11: numDays += 30; break;
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 2: case 2:
if(isLeapYear(currentYear)){ if(isLeapYear(currentYear)){
numDays += 29; numDays += 29;

View File

@@ -64,6 +64,10 @@ public class Problem32 extends Problem{
return (getProduct() == secondSet.getProduct()); return (getProduct() == secondSet.getProduct());
} }
@Override @Override
public int hashCode(){
return (2 * multiplicand) + (3 * multiplier);
}
@Override
public String toString(){ public String toString(){
return String.format("%d%d%d", multiplicand, multiplier, getProduct()); return String.format("%d%d%d", multiplicand, multiplier, getProduct());
} }

View File

@@ -105,11 +105,7 @@ public class Problem37 extends Problem{
continue; continue;
} }
switch(primeString.charAt(strLoc)){ switch(primeString.charAt(strLoc)){
case '0' : case '0', '2', '4', '6', '8' : isTruncPrime = false; break;
case '2' :
case '4' :
case '6' :
case '8' : isTruncPrime = false; break;
default: break; default: break;
} }
} }