7. Scolarship
Резултат 93/100. Гърми на Test #14 (Incorrect answer
import java.util.Scanner; public class W2_E7_Scholarship { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double income = Double.parseDouble(scanner.nextLine()); double score = Double.parseDouble(scanner.nextLine()); double wage = Double.parseDouble(scanner.nextLine()); double social_scolar = wage * 0.35; double excel_solar = score * 25; if ((score >= 5.5) & (social_scolar < excel_solar)) { System.out.printf("You get a scholarship for excellent results %.0f BGN", Math.floor(excel_solar)); } else if ((score >= 5.5) & (social_scolar >= excel_solar) | (income < wage) & (score > 4.5)) { System.out.printf("You get a Social scholarship %.0f BGN", Math.floor(social_scolar)); } else { System.out.println("You cannot get a scholarship!"); } } }
Благодаря за обратната връзка.
Бях проспал условието, че студент не може да получава социална стипендия когато income > wage.
Добавих го с оператор '|' в първото условие 100/100.
import java.util.Scanner;
public class W2_E7_Scholarship {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double income = Double.parseDouble(scanner.nextLine());
double score = Double.parseDouble(scanner.nextLine());
double wage = Double.parseDouble(scanner.nextLine());
double social_scolar = wage * 0.35;
double excel_solar = score * 25;
if ((score >= 5.5) & ((social_scolar < excel_solar) | (income > wage))) {
System.out.printf("You get a scholarship for excellent results %.0f BGN", Math.floor(excel_solar));
} else if ((score >= 5.5) & (social_scolar >= excel_solar) | (income < wage) & (score > 4.5)) {
System.out.printf("You get a Social scholarship %.0f BGN", Math.floor(social_scolar));
} else {
System.out.println("You cannot get a scholarship!");
}
}
}
package simpleConditions;
import java.util.Scanner;
public class Scholarships {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double income = Double.parseDouble(scanner.nextLine());
double grade = Double.parseDouble(scanner.nextLine());
double minSalary = Double.parseDouble(scanner.nextLine());
double socScholarship = 0;
double gradeScholarship = 0;
if (minSalary > income) {
if (grade > 4.50) {
socScholarship = minSalary * 0.35;
}
}
if (grade >= 5.50) {
gradeScholarship = grade * 25;
}
if (socScholarship > gradeScholarship) {
System.out.printf("You get a Social scholarship %.0f BGN",
Math.floor(socScholarship));
} else if (socScholarship < gradeScholarship){
System.out.printf("You get a scholarship for excellent results %.0f BGN",
Math.floor(gradeScholarship));
} else {
System.out.println("You cannot get a scholarship!");
}
}
}