/
pandapo777
/
JavaStepik
Обзор
Документация
Войти
/
pandapo777
/
JavaStepik
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
OOP/src/test/Main.java
251 строка
11 KB
pandapo777
ДЗ интерфейсы
06 апр 2025, 00:20
06 апр 2025, 00:20
56ecf60
Код
Авторство
О чём код?
package test; import box.Box; import box.WeightBox; import examples.*; import inheritance.Cat; import inheritance.Lion; import shapes.Rectangle; import shapes.Shape; import shapes.Triangle; import java.util.ArrayList; import java.util.Collection; //TIP Для <b>запуска</b> кода нажмите <shortcut actionId="Run"/> или // щелкните значок <icon src="AllIcons.Actions.Execute"/> в боковой области. public class Main { public static void main(String[] args) { // //TIP Нажмите <shortcut actionId="ShowIntentionActions"/>, поместив каретку на выделенный текст // // чтобы увидеть, как GIGA IDE предлагает исправить это. // System.out.printf("Hello and welcome!"); // // for (int i = 1; i <= 5; i++) { // //TIP Нажмите <shortcut actionId="Debug"/>, чтобы начать отладку кода. Мы установили одну <icon src="AllIcons.Debugger.Db_set_breakpoint"/> точку останова // // для вас, но вы всегда можете добавить еще, нажав <shortcut actionId="ToggleLineBreakpoint"/>. // System.out.println("i = " + i); // } // Box.Box box1 = new Box.Box(); // box1.height = 10; // box1.length = 10; // box1.width = 10; //// double volume1 = box1.height * box1.length * box1.width; // double volume1 = box1.getVolume(); // System.out.println(volume1); // box1.showVolume(); // Box.Box box2 = new Box.Box(); //// Box.Box box3 = box2; // box2.height = 20; // box2.length = 20; // box2.width = 20; //// box3.width = 0; //// double volume2 = box2.height * box2.length * box2.width; // double volume2 = box2.getVolume(); // System.out.println(volume2); // box2.showVolume(); //Создать класс "Человек" имя, возраст, вес. Создать три человека. Высчитать средний возраст // examples.Person person1 = new examples.Person(); // person1.name = "Viktor"; // person1.age = 35; // person1.weight = 76; // // examples.Person person2 = new examples.Person(); // person2.name = "Andrew"; // person2.age = 5; // person2.weight = 9; // // examples.Person person3 = new examples.Person(); // person3.name = "Ewan"; // person3.age = 45; //// person3.weight = 106; // double averageAge = (double) (person1.age + person2.age + person3.age) / 3; // System.out.println(averageAge); //Создать класс Собака имя, порода и вес. Написать метод, который возвращает описание собаки // examples.Dog dog1 = new examples.Dog(); // dog1.nickname = "Whilmor"; // dog1.breed = "Shepherd"; // dog1.weight = 24; // dog1.speed = 4; // System.out.println(dog1.getDog()); // dog1.showDog(); // dog1.run(); //Добавить скорость и метод бежать. int speed = 3, run, run, run // Создать класс прямоугольник с двумя полями длина и ширина // 1-й метод параметризированный устанавливает значение длины и ширины // 2-й метод без параметров возвращает площадь прямоугольника // examples.Rectangle rectangle1 = new examples.Rectangle(); // rectangle1.setDimensions(12, 12); // rectangle1.showSquare(); // Создать класс работник поля имя, должность, зарплата. Создать конструктор, // в котором все эти поля буддут проинициализированы. // Добавьте метод showInfo, который выводит всю эту информацию в консоль // examples.Worker worker = new examples.Worker("Виктор", "Бухгалтер", 150_000); // worker.infoWorker(); // System.out.println(examples.MyMath.multiple(12.2 , 15.7)); // System.out.println(examples.MyMath.multiple(12)); // System.out.println(examples.MyMath.multiple(12, 15,16)); System.out.println(Math.sqrt(144)); Box box = new Box(); System.out.println(box.getVolume()); // Создайте класс монстр, у него есть три поля кол-во рук, кол-во глаз, кол-во ног // Три конструктора // 1. Без параметров, он устанавливает всем полям значение 2 // 2. Будет принимать только один параметр // 3. Будет принимать кол-во рук, кол-во глаз, кол-во ног // метод "голос" // examples.Monster monster = new examples.Monster(5); //// // // monster.voice(3); // monster.voice(3, "Aaaaaaaaa..."); // monster.voice(); // Box.Box current = new Box.Box( 12, 10, 10); // Box.Box another = new Box.Box( 10); // int result = current.compare(another); // System.out.println(result); Box current = new Box(10); // Box.Box another = new Box.Box(current); Box another = current.copy(); // another.setDimens(20, 20, 20); // Box another1 = current.increase(); // current.showVolume(); // another.showVolume(); // another1.showVolume(); // // Person person = new Person(28, "John"); // person.setAge(1); // person.setName("IRINA"); // System.out.println("Name: " + person.getName() + "\nAge: " + person.getAge()); // // System.out.println(MyMath.length(12)); // System.out.println(MyMath.area(12)); // // System.out.println(MyMath.sum(10, 11, 12, 13, 14, 15)); // Collection // String[] employees = getEmployees(); // String[] newArray = new String[employees.length + 1]; // for (int i= 0; i < employees.length; i++){ // newArray[i] = employees[i]; // } // newArray[newArray.length - 1] = "James"; // // employees = newArray; // employees[0] = null; // String[] newestArray = new String [employees.length - 1]; // for(int i = 0, j = 0 ; i < employees.length; i++){ // String employee = employees[i]; // if (employee != null){ // newestArray[j] = employee; // j++; // // } // } // employees = newestArray; // // // for(String employee : employees){ // System.out.println(employee); // } // // // } // private static String[] getEmployees(){ // String[] employees = new String[5]; // employees[0] = "John"; // employees[1] = "Olivia"; // employees[2] = "Emma"; // employees[3] = "Max"; // employees[4] = "Nick"; // return employees; // } ArrayList employees = getEmployees(); employees.add("James"); employees.remove("Olivia"); employees.remove(0); for (Object employee : employees) { System.out.println(employee); } ArrayList<Integer> numbers = new ArrayList<>(); for(int i = 0; i < 5; i++){ numbers.add(i); } for (int number : numbers) { System.out.println(number); } ArrayList<String> intNames = new ArrayList<>(); for(int i = 0; i < 5; i++){ intNames.add((numbers.get(i)) + " - " + employees.get(i)); } for (String intName : intNames){ System.out.println(intName); } // String s = "This is John. He is 27 years old"; // String name = s.substring(8, 12); // System.out.println(name); // String a = s.substring(20, 22); // System.out.println(a); // int age = Integer.parseInt(a); // Person person = new Person(age, name); // System.out.println(person.getAge() + person.getName()); Cat cat = new Cat(); Lion lion = new Lion(); System.out.println(cat.isCanEatPerson()); System.out.println(lion.isCanEatPerson()); lion.eat(); cat.eat(); //У нас есть класс Box, у которого есть поля длина, ширина и высота. Также есть различные конструкторы. // Я вам предлагаю создать наследника этого класса. Это будет весовая коробка. У нее будут все те же поля, // но также добавится дополнительное поле вес. В этом классе создайте все те же конструкторы, которые есть // в родительском классе, и добавьте к ним одно поле вес. Чтобы эти конструкторы работали точно так же, // при этом присваивали новое значение вашей переменной с весом. Кроме этого, в родительском классе добавьте метод showInfo. // Этот метод будет выводить всю информацию о коробке. Длина, ширина и высота. А в дочернем классе переопределите этот метод так, // чтобы он выводил не только длину, ширину и высоту, но также информацию о весе коробки. Я вам даю время поставить видео на паузу // и сделать эту задачу самостоятельно. WeightBox weightBox1 = new WeightBox(12, 12, 12, 12); WeightBox weightBox2 = new WeightBox(13, 13); weightBox1.showInfo(); weightBox2.showInfo(); Triangle triangle = new Triangle(); triangle.showPerimeter(); Rectangle rectangle = new Rectangle(); rectangle.showPerimeter(); } private static ArrayList<String> getEmployees() { ArrayList<String> employees = new ArrayList(); employees.add("John"); employees.add("Olivia"); employees.add("Emma"); employees.add("Max"); employees.add("Nick"); employees.add("Viktor"); return employees; } }