Moved isNumPrime to MathTools and made Student static
This commit is contained in:
parent
4ccbd6855b
commit
b2d73e9775
|
@ -31,16 +31,16 @@ public class Grades {
|
|||
System.out.printf("%5.1f %5.1f %5d\n", student.notaT, student.notaP, student.notaFinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Student {
|
||||
public double notaT;
|
||||
public double notaP;
|
||||
public int notaFinal;
|
||||
private static class Student {
|
||||
public double notaT;
|
||||
public double notaP;
|
||||
public int notaFinal;
|
||||
|
||||
public Student(double notaT, double notaP) {
|
||||
this.notaT = notaT;
|
||||
this.notaP = notaP;
|
||||
this.notaFinal = (notaT < 7 || notaP < 7) ? 66 : (int) Math.round(0.4 * notaT + 0.6 * notaP);
|
||||
public Student(double notaT, double notaP) {
|
||||
this.notaT = notaT;
|
||||
this.notaP = notaP;
|
||||
this.notaFinal = (notaT < 7 || notaP < 7) ? 66 : (int) Math.round(0.4 * notaT + 0.6 * notaP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package aula03;
|
||||
|
||||
import utils.MathTools;
|
||||
import utils.UserInput;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
@ -14,20 +15,11 @@ public class PrimesSum {
|
|||
|
||||
int sum = 0;
|
||||
for (int i = 0; i <= n; i++)
|
||||
if (isNumPrime(i))
|
||||
if (MathTools.isNumPrime(i))
|
||||
sum += i;
|
||||
|
||||
System.out.printf("A soma dos números primos até %d é %d\n", n, sum);
|
||||
|
||||
sin.close();
|
||||
}
|
||||
|
||||
private static boolean isNumPrime(int n) {
|
||||
if (n == 1)
|
||||
return false;
|
||||
for (int i = 2; i < n; i++)
|
||||
if (n % i == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
package utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MathTools {
|
||||
public static double round(double n, int places) {
|
||||
return (Math.round(n * Math.pow(10, places))) / Math.pow(10, places);
|
||||
}
|
||||
|
||||
public static double random(double minLimit, double maxLimit) {
|
||||
Random rand = new Random();
|
||||
return rand.nextDouble(minLimit, maxLimit);
|
||||
}
|
||||
|
||||
public static boolean isNumPrime(int n) {
|
||||
if (n <= 1)
|
||||
return false;
|
||||
for (int i = 2; i < n; i++)
|
||||
if (n % i == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue