-
-
Save mikekur/5d6eeab0fcab659fb5f8cf3896ba677d to your computer and use it in GitHub Desktop.
QA Auto 14092021 Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
public class Main { | |
public static int max = 100; | |
public static int even; | |
public static int odd; | |
public static void main(String[] args) throws IOException { | |
//Task 1 | |
for(int i = 0; i < 10; i++){ | |
System.out.println("JAVA HOME"); | |
} | |
//Task 2 | |
Man man = new Man(); | |
Woman woman = new Woman(); | |
woman.husband = man; | |
man.wife = woman; | |
//Task 3 | |
System.out.println(min(5,6)); | |
System.out.println((min(-11,-10))); | |
//Task 4 | |
System.out.println(convertToSecond(1)); | |
System.out.println(convertToSecond(2)); | |
// Task 5 | |
System.out.println(multiplicationTable(1)); | |
System.out.println(multiplicationTable(2)); | |
System.out.println(multiplicationTable(3)); | |
System.out.println(multiplicationTable(4)); | |
System.out.println(multiplicationTable(5)); | |
System.out.println(multiplicationTable(6)); | |
System.out.println(multiplicationTable(7)); | |
System.out.println(multiplicationTable(8)); | |
System.out.println(multiplicationTable(9)); | |
System.out.println(multiplicationTable(10)); | |
// Task 6 | |
Apple apple1 = new Apple(); | |
Apple apple2 = new Apple(); | |
apple1.addPrice(100); | |
apple2.addPrice(200); | |
System.out.println(Apple.applesPrice); | |
// Task 7 | |
Human human = new Human(); | |
human.setName("Макс"); | |
System.out.println(human.name); | |
// Task 8 | |
checkSeason(0); | |
checkSeason(1); | |
checkSeason(2); | |
checkSeason(3); | |
checkSeason(4); | |
checkSeason(5); | |
checkSeason(6); | |
checkSeason(7); | |
checkSeason(8); | |
checkSeason(9); | |
checkSeason(10); | |
checkSeason(11); | |
checkSeason(12); | |
checkSeason(13); | |
//Task 11 | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
String text = "The max is "; | |
try { | |
int a = Integer.parseInt(reader.readLine()); | |
int b = Integer.parseInt(reader.readLine()); | |
max = Math.max(a,b); | |
} catch (NumberFormatException e) { | |
System.out.println("It is not a number,shown default max value" ); | |
} | |
System.out.println(text + max); | |
//Task 12 | |
try { | |
int end; | |
int number = Integer.parseInt(reader.readLine()); | |
if(number < 0){ | |
System.out.println("Введите положительное число"); | |
} | |
else { | |
while(number != 0){ | |
end = number % 10; | |
number = number / 10; | |
if( end % 2 == 0){ | |
even ++; // Wiki says zero number is even number | |
} else { | |
odd ++; | |
} | |
} | |
} | |
} catch (NumberFormatException e) { | |
System.out.println("It is not a number, shown default values for Even and Odd" ); | |
} | |
System.out.println("Even: " + even + " Odd: " + odd); | |
//Task 13 | |
int[] array = initializeArray(); | |
int max = max(array); | |
System.out.println(max); | |
} | |
static class Man{ | |
public Woman wife; | |
} | |
static class Woman{ | |
public Man husband; | |
} | |
static int min(int a,int b){ | |
return a > b ? b : a; | |
} | |
static int convertToSecond(int hour){ | |
return hour * 60 * 60; | |
} | |
static String multiplicationTable(int number){ | |
String result = String.valueOf(number); | |
for(int i = 2; i <=10; i ++){ | |
result =result + " " + number * i ; | |
} | |
return result; | |
} | |
static class Apple { | |
public static int applesPrice = 0; | |
public static void addPrice(int applesPrice){ | |
Apple.applesPrice += applesPrice; | |
} | |
} | |
public static class Human{ //Task 7 and Task 9 | |
private String name = "человек"; | |
private int age; | |
private int weight; | |
private int strength; | |
public void setName(String name){ | |
this.name = name; | |
} | |
} | |
public static void checkSeason(int month){ | |
if(month == 1 || month == 12 || month == 2){ | |
System.out.println("зима"); | |
} | |
else if(month > 2 && month <= 5){ | |
System.out.println("весна"); | |
} | |
else if(month > 5 && month <= 8){ | |
System.out.println("лето"); | |
} | |
else if(month > 8 && month <= 11){ | |
System.out.println("осень"); | |
} | |
else { | |
System.out.println("Месяц введен не корректно, введите значение от 1 до 12"); | |
} | |
switch (month) { | |
case 1, 2, 12 -> System.out.println("зима"); | |
case 3, 4, 5 -> System.out.println("весна"); | |
case 6, 7, 8 -> System.out.println("лето"); | |
case 9, 10, 11 -> System.out.println("осень"); | |
default -> System.out.println("Месяц введен не корректно, введите значение от 1 до 12"); | |
} | |
} | |
static class Dog{ | |
private String name; | |
private int age; | |
public int getAge() { | |
return age; | |
} | |
public void setAge(int age) { | |
this.age = age; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} | |
static int[] initializeArray() throws IOException{ | |
ArrayList<Integer> list = new ArrayList<>(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
System.out.println("Type numbers which should be added in the array"); | |
System.out.println("Type \"end\" to exit the cycle"); | |
String value; | |
while(true){ | |
value = reader.readLine(); | |
if(value.equals("end")) break; | |
else{ | |
try{ | |
int number = Integer.parseInt(value); | |
list.add(number); | |
} catch(NumberFormatException e){ | |
System.out.println("It is not a number,please type a number or \"end\""); | |
} | |
} | |
} | |
int[] array = new int[list.size()]; | |
for(int i = 0; i < list.size(); i ++){ | |
array[i] = list.get(i); | |
} | |
return array; | |
} | |
static int max(int[] array){ | |
int max = Integer.MIN_VALUE; | |
for (int i : array) { | |
if (max < i) max = i; | |
} | |
return max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
просмотрел