Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
14 kB
2
Indexable
Never
5. Vacation

package tasks;

import java.util.Scanner;

public class _5_Vacation {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        double budget = Double.parseDouble(scanner.nextLine());
        String season = scanner.nextLine();

        String location = "";
        String accomondation = "";
        double moneySpent = 0;

        if (budget <= 1000) {
            accomondation = "Camp";
            if (season.equals("Summer")) {
                location = "Alaska";
                moneySpent = budget * 0.65;
            } else {
                location = "Morocco";
                moneySpent = budget * 0.45;
            }
        } else if (budget <= 3000) {
            accomondation = "Hut";
            if (season.equals("Summer")) {
                location = "Alaska";
                moneySpent = budget * 0.80;
            } else {
                location = "Morocco";
                moneySpent = budget * 0.60;
            }
        } else if (budget > 3000) {
            accomondation = "Hotel";
            moneySpent = budget * 0.90;
            if (season.equals("Summer")) {
                location = "Alaska";
            } else {
                location = "Morocco";
            }
        }

        System.out.printf("%s - %s - %.2f", location, accomondation, moneySpent );
    }
}

6.Truck Driver

import java.util.Scanner;

public class TruckDriver {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String season = scanner.nextLine();
        double km = Double.parseDouble(scanner.nextLine());

        double levaTokm = 0.00;

        switch (season) {
            case "Spring":
            case "Autumn":
                if (km <= 5000) {
                    levaTokm = 0.75;
                } else if (5000 < km && km <= 10000) {
                    levaTokm = 0.95;
                } else {
                    levaTokm = 1.45;
                }
                break;
            case "Summer":
                if (km <= 5000) {
                    levaTokm = 0.90;
                } else if (5000 < km && km <= 10000) {
                    levaTokm = 1.10;
                } else {
                    levaTokm = 1.45;
                }
                break;
            case "Winter":
                if (km <= 5000) {
                    levaTokm = 1.05;
                } else if (5000 < km && km <= 10000) {
                    levaTokm = 1.25;
                } else {
                    levaTokm = 1.45;
                }
                break;
        }
        double result = (km * levaTokm) * 4;
        double resultAfterTax = result - (result * 0.10);

        System.out.printf("%.2f", resultAfterTax);
    }
}

7. School Camp:

package W03ConditionalStatementsAdvanced;

import java.util.Scanner;

public class A07SchoolCamp {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String season = scanner.nextLine();
        String groupType = scanner.nextLine();
        int countStudents = Integer.parseInt(scanner.nextLine());
        int countNights = Integer.parseInt(scanner.nextLine());

        String sportsType = "";
        double nightsCosts = 0;

        if (countStudents < 10) {
            switch (season) {
                case "Winter":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 9.60;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Gymnastics";
                                break;
                            case "boys":
                                sportsType = "Judo";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 10;
                        sportsType = "Ski";
                    }
                    break;

                case "Spring":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 7.20;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Athletics";
                                break;
                            case "boys":
                                sportsType = "Tennis";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 9.50;
                        sportsType = "Cycling";
                    }
                    break;

                case "Summer":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 15;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Volleyball";
                                break;
                            case "boys":
                                sportsType = "Football";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 20;
                        sportsType = "Swimming";
                    }
                    break;
            }
        } else if (countStudents < 20) {
            switch (season) {
                case "Winter":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 9.60 * 0.95;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Gymnastics";
                                break;
                            case "boys":
                                sportsType = "Judo";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 10 * 0.95;
                        sportsType = "Ski";
                    }
                    break;

                case "Spring":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 7.20 * 0.95;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Athletics";
                                break;
                            case "boys":
                                sportsType = "Tennis";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 9.50 * 0.95;
                        sportsType = "Cycling";
                    }
                    break;

                case "Summer":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 15 * 0.95;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Volleyball";
                                break;
                            case "boys":
                                sportsType = "Football";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 20 * 0.95;
                        sportsType = "Swimming";
                    }
                    break;

            }
        } else if (countStudents < 50) {
            switch (season) {
                case "Winter":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 9.60 * 0.85;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Gymnastics";
                                break;
                            case "boys":
                                sportsType = "Judo";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 10 * 0.85;
                        sportsType = "Ski";
                    }
                    break;

                case "Spring":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 7.20 * 0.85;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Athletics";
                                break;
                            case "boys":
                                sportsType = "Tennis";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 9.50 * 0.85;
                        sportsType = "Cycling";
                    }
                    break;

                case "Summer":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 15 * 0.85;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Volleyball";
                                break;
                            case "boys":
                                sportsType = "Football";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 20 * 0.85;
                        sportsType = "Swimming";
                    }
                    break;
            }
        } else {
            switch (season) {
                case "Winter":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 9.60 * 0.50;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Gymnastics";
                                break;
                            case "boys":
                                sportsType = "Judo";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 10 * 0.50;
                        sportsType = "Ski";
                    }
                    break;

                case "Spring":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 7.20 * 0.50;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Athletics";
                                break;
                            case "boys":
                                sportsType = "Tennis";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 9.50 * 0.50;
                        sportsType = "Cycling";
                    }
                    break;

                case "Summer":
                    if (groupType.equals("boys") || groupType.equals("girls")) {
                        nightsCosts = countNights * countStudents * 15 * 0.50;
                        switch (groupType) {
                            case "girls":
                                sportsType = "Volleyball";
                                break;
                            case "boys":
                                sportsType = "Football";
                                break;
                        }
                    } else if (groupType.equals("mixed")) {
                        nightsCosts = countNights * countStudents * 20 * 0.50;
                        sportsType = "Swimming";
                    }
                    break;
            }

        }
        System.out.printf("%s %.2f lv.", sportsType, nightsCosts);
    }
}

8.Point on rctangle border:

package dopalnitelni_zadachi;

import java.util.Scanner;

public class _3_ConditionalStatementsAdvanced_08PointOnRectangleBorder {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        double x1 = Double.parseDouble(scanner.nextLine());
        double y1 = Double.parseDouble(scanner.nextLine());
        double x2 = Double.parseDouble(scanner.nextLine());
        double y2 = Double.parseDouble(scanner.nextLine());
        double x = Double.parseDouble(scanner.nextLine());
        double y = Double.parseDouble(scanner.nextLine());

//        x1 < x2 и y1 < y2

        if ((x == x1 || x == x2) && (y >= y1 && y <= y2)) {
            System.out.printf("Border");

        } else if ((y == y1 || y == y2) && (x >= x1 && x <= x2)) {
            System.out.println("Border");

        } else {
            System.out.println("Inside / Outside");
        }
    }
}

10. Multiply by 2:

import java.util.Scanner;

public class MultiplyBy2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double i=0;
        while (i>=0) {
            i = Double.parseDouble(scanner.nextLine());
            if (i>=0) System.out.printf("Result: %.2f\n", i*2);
        }
        System.out.println("Negative number!");
    }
}
Leave a Comment