Софтуерно Инженерство
Loading...
+ Нов въпрос
s.borisov avatar s.borisov 0 Точки

08. Scholarship

Здравевйте,

По-долу е кода на задачата за стипендиите, но един от тестовете в judge не минава. Някой има ли идея къде може да е проблема?

Поздрави!

Стоян

import java.util.Scanner;

public class Scholarship {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double incomeBGN = Double.parseDouble(scanner.nextLine());
        double avGrade = Double.parseDouble(scanner.nextLine());
        double minSalary = Double.parseDouble(scanner.nextLine());
        double socScholarship = 0;
        double scholarship = 0;
        if (avGrade <= 4.50) {
            System.out.println("You cannot get a scholarship!");
        } else if (avGrade < 5.50) {
            if (incomeBGN < minSalary) {
                socScholarship = Math.floor(0.35 * minSalary);
                System.out.printf("You get a Social scholarship %.0f BGN", socScholarship);
            } else {
                System.out.println("You cannot get a scholarship!");
            }
        } else {
            scholarship = Math.floor(avGrade * 25);
            socScholarship = Math.floor(0.35 * minSalary);
            if (socScholarship > scholarship) {
                System.out.printf("You get a Social scholarship %.0f BGN", socScholarship);
            } else {
                System.out.printf("You get a scholarship for excellent results %.0f BGN", scholarship);
            }
        }
    }
}
Тагове:
0
Programming Basics with Java
skenderskiantonio avatar skenderskiantonio 19 Точки

 В случай, че оценката е повече от или равна на 5.50, не проверяваш дали доходите са по-малко от минималната заплата. Трябва да се добави проверка за това;

import java.util.Scanner;

public class Scholarship {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double incomeBGN = Double.parseDouble(scanner.nextLine());
        double avGrade = Double.parseDouble(scanner.nextLine());
        double minSalary = Double.parseDouble(scanner.nextLine());
        double socScholarship = 0;
        double scholarship = 0;
        if (avGrade <= 4.50) {
            System.out.println("You cannot get a scholarship!");
        } else if (avGrade < 5.50) {
            if (incomeBGN < minSalary) {
                socScholarship = Math.floor(0.35 * minSalary);
                System.out.printf("You get a Social scholarship %.0f BGN", socScholarship);
            } else {
                System.out.println("You cannot get a scholarship!");
            }
        } else {
            scholarship = Math.floor(avGrade * 25);
            if (incomeBGN < minSalary) socScholarship = Math.floor(0.35 * minSalary);
            if (socScholarship > scholarship) {
                System.out.printf("You get a Social scholarship %.0f BGN", socScholarship);
            } else {
                System.out.printf("You get a scholarship for excellent results %.0f BGN", scholarship);
            }
        }
    }
}
0
s.borisov avatar s.borisov 0 Точки

Много благодаря!

0