(URI) Média 3 - Solução
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
class Main {
public static final int MAX = 4;
public static void readGrades(Scanner sc, float[] grades) {
for (int i = 0; i < MAX; i++) {
grades[i] = sc.nextFloat();
}
}
public static float getAverage(float sumGrades, int div) {
DecimalFormat df = new DecimalFormat("0.0");
return Float.parseFloat(df.format(sumGrades/div));
}
public static void printAnswer(Scanner sc, float average) {
System.out.println("Media: " + average);
if (average >= 7.0) {
System.out.println("Aluno aprovado.");
}
else if (average < 5.0) {
System.out.println("Aluno reprovado.");
}
else {
System.out.println("Aluno em exame.");
float newGrade = sc.nextFloat();
average = getAverage(average+newGrade, 2);
System.out.println("Nota do exame: " + newGrade);
if (average >= 5.0) {
System.out.println("Aluno aprovado.");
}
else {
System.out.println("Aluno reprovado.");
}
System.out.println("Media final: " + average);
}
}
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
float[] grades = new float[MAX];
readGrades(sc, grades);
float sumGrades = grades[0]*2 + grades[1]*3 + grades[2]*4 + grades[3];
float average = getAverage(sumGrades, 10);
printAnswer(sc, average);
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
import java.util.*;
import java.text.DecimalFormat;
class Main {
public static final int MAX = 4;
public static void readGrades(Scanner sc, float[] grades) {
for (int i = 0; i < MAX; i++) {
grades[i] = sc.nextFloat();
}
}
public static float getAverage(float sumGrades, int div) {
DecimalFormat df = new DecimalFormat("0.0");
return Float.parseFloat(df.format(sumGrades/div));
}
public static void printAnswer(Scanner sc, float average) {
System.out.println("Media: " + average);
if (average >= 7.0) {
System.out.println("Aluno aprovado.");
}
else if (average < 5.0) {
System.out.println("Aluno reprovado.");
}
else {
System.out.println("Aluno em exame.");
float newGrade = sc.nextFloat();
average = getAverage(average+newGrade, 2);
System.out.println("Nota do exame: " + newGrade);
if (average >= 5.0) {
System.out.println("Aluno aprovado.");
}
else {
System.out.println("Aluno reprovado.");
}
System.out.println("Media final: " + average);
}
}
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
float[] grades = new float[MAX];
readGrades(sc, grades);
float sumGrades = grades[0]*2 + grades[1]*3 + grades[2]*4 + grades[3];
float average = getAverage(sumGrades, 10);
printAnswer(sc, average);
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment