Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- НАВРЕМЕ ЗА ИЗПИТ
- import java.util.Scanner;
- public class main {
- static void findStatus(int diff) {
- String status = "";
- if (diff < -30) {
- status = "Early";
- } else if (diff <=0) {
- status = "On time";
- } else if (diff > 0) {
- status = "Late";
- }
- System.out.println(status);
- }
- static void difference(int diff) {
- int hourDiff = Math.abs(diff / 60);
- int minDiff = Math.abs(diff % 60);
- if (diff != 0) {
- if(hourDiff > 0){
- System.out.printf("%d:%02d hours",hourDiff,minDiff);
- }else{
- System.out.printf("%2d minutes",minDiff);
- }
- if (diff>0){
- System.out.print(" after the start");
- }else{
- System.out.print(" before the start");
- }
- }
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int hourOfExam = scan.nextInt();
- int minOfExam = scan.nextInt();
- int hourOfArrive = scan.nextInt();
- int minOfArrive = scan.nextInt();
- int examStart = (hourOfExam * 60) + minOfExam;
- int arrive = hourOfArrive * 60 + minOfArrive;
- int diff = arrive - examStart;
- findStatus(diff);
- difference(diff);
- }
- }
- ПЪТЕШЕСТВИЕ
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double budget = Double.parseDouble(scan.nextLine());
- String season = scan.nextLine();
- double spend = 0;
- if (budget <= 100) {
- System.out.println("Somewhere in Bulgaria");
- if (season.equalsIgnoreCase("summer")) {
- spend = 0.30 * budget;
- System.out.printf("Camp - %.2f", spend);
- }
- if (season.equalsIgnoreCase("winter")) {
- spend = 0.70 * budget;
- System.out.printf("Hotel - %.2f", spend);
- }
- }
- if (budget <= 1000 && budget > 100) {
- System.out.println("Somewhere in Balkans");
- if (season.equalsIgnoreCase("summer")) {
- spend = 0.40 * budget;
- System.out.printf("Camp - %.2f", spend);
- }
- if (season.equalsIgnoreCase("winter")) {
- spend = 0.80 * budget;
- System.out.printf("Hotel - %.2f", spend);
- }
- }
- if(budget > 1000){
- System.out.println("Somewhere in Europe");
- spend = 0.90*budget;
- System.out.printf("Hotel - %.2f",spend);
- }
- }
- }
- ОПЕРАЦИИ МЕЖДУ ЧИСЛА
- import java.util.Scanner;
- public class main {
- static boolean div(double n1, double n2 , char operator){
- if ((operator == '/' || operator == '%') && n2 == 0) {
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double n1 = scan.nextDouble();
- double n2 = scan.nextDouble();
- char operator = scan.next().charAt(0);
- double result = 0;
- if (div(n1,n2,operator) == true){
- System.out.printf("Cannot divide %.0f by zero", n1);
- }
- if (div(n1,n2,operator) == false) {
- switch (operator) {
- case '+':
- result += n1 + n2;
- break;
- case '-':
- result += n1 - n2;
- break;
- case '*':
- result += n1 * n2;
- break;
- case '%':
- result += n1 % n2;
- break;
- default:
- break;
- }
- if (operator == '/') {
- System.out.printf("%.0f / %.0f = %.2f", n1, n2, n1 / n2);
- }
- if (operator != '/') {
- System.out.printf("%.0f %s %.0f = %.0f", n1, operator, n2, result);
- }
- if (operator == '+' || operator == '-' || operator == '*') {
- if (result % 2 == 0) {
- System.out.printf(" - even");
- } else {
- System.out.printf(" - odd");
- }
- }
- }
- }
- }
- БИЛЕТИ ЗА МАЧ
- import java.util.Scanner;
- public class main {
- static double transport(int people, double budget) {
- double transport = 0;
- if (people >= 1 && people <= 4) {
- transport = 0.75 * budget;
- } else if (people >= 5 && people <= 9) {
- transport = 0.60 * budget;
- } else if (people >= 10 && people <= 24) {
- transport = 0.50 * budget;
- } else if (people >= 25 && people <= 49) {
- transport = 0.40 * budget;
- } else if (people >= 50) {
- transport = 0.25 * budget;
- }
- return transport;
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double budget = Double.parseDouble(scan.nextLine());
- String ticketKind = scan.nextLine();
- int people = Integer.parseInt(scan.nextLine());
- double moneyLeft = 0;
- budget -= transport(people, budget);
- if (ticketKind.equalsIgnoreCase("Normal")) {
- budget -= 249.99*people;
- } else {
- budget -= 499.99*people;
- }
- if (budget > 0) {
- System.out.printf("Yes! You have %.2f leva left.", budget);
- }else{
- System.out.printf("Not enough money! You need %.2f leva.",Math.abs(budget));
- }
- }
- }
- ХОТЕЛСКА СТАЯ
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String season = scan.nextLine();
- int nights = Integer.parseInt(scan.nextLine());
- double apartment = 0;
- double studio = 0;
- double studioPrice = 0;
- double apartmentPrice = 0;
- double discountS = 0;
- double discountA = 0;
- if (season.equals("May") || season.equals("October")) {
- studioPrice = 50;
- apartmentPrice = 65;
- } else if (season.equals("June") || season.equals("September")) {
- studioPrice = 75.20;
- apartmentPrice = 68.70;
- } else if (season.equals("July") || season.equals("August")) {
- studioPrice = 76;
- apartmentPrice = 77;
- }
- switch(season){
- case "May":
- case "October":
- if (nights>7){
- discountS = 0.05 * studioPrice;
- }if (nights>14){
- discountS = 0.30 * studioPrice;
- }break;
- case "June":
- case"September":
- if (nights > 14){
- discountS = 0.20 * studioPrice;
- }break;
- default:break;
- }
- if(nights>14){
- discountA = 0.10 * apartmentPrice;
- }
- studioPrice-=discountS;
- apartmentPrice-=discountA;
- studio = studioPrice * nights;
- apartment = apartmentPrice *nights;
- System.out.printf("Apartment: %.2f lv.%n",apartment);
- System.out.printf("Studio: %.2f lv.",studio);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement