Загрузка данных


class Animal {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void makeSound() {
        System.out.println("Животное издает звук");
    }
}

class Dog extends Animal {
    public Dog(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Собака: Гав!");
    }
}

class Cat extends Animal {
    public Cat(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Кошка: Мяу!");
    }
}

public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog("Бобик");
        Cat cat = new Cat("Мурка");

        System.out.println(dog.getName());
        dog.makeSound();

        System.out.println(cat.getName());
        cat.makeSound();
    }
}




class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void introduce() {
        System.out.println("Меня зовут " + name);
    }
}

class Student extends Person {
    private String group;

    public Student(String name, int age, String group) {
        super(name, age);
        this.group = group;
    }

    @Override
    public void introduce() {
        super.introduce();
        System.out.println("Я учусь в группе " + group);
    }
}

public class Main {
    public static void main(String[] args) {
        Student student = new Student("Иван", 20, "ИС-42");
        student.introduce();
    }
}




class Device {
    protected String brand;
    protected String model;

    public Device(String brand, String model) {
        this.brand = brand;
        this.model = model;
    }

    public void showInfo() {
        System.out.println(brand + " " + model);
    }
}

class Computer extends Device {
    protected int ram;

    public Computer(String brand, String model, int ram) {
        super(brand, model);
        this.ram = ram;
    }

    public void work() {
        System.out.println("Компьютер работает");
    }

    @Override
    public void showInfo() {
        super.showInfo();
        System.out.println("ОЗУ: " + ram + " ГБ");
    }
}

class Laptop extends Computer {
    private int batteryCapacity;

    public Laptop(String brand, String model, int ram, int batteryCapacity) {
        super(brand, model, ram);
        this.batteryCapacity = batteryCapacity;
    }

    public void charge() {
        System.out.println("Ноутбук заряжается");
    }

    @Override
    public void showInfo() {
        super.showInfo();
        System.out.println("Батарея: " + batteryCapacity + " мАч");
    }
}

class DesktopComputer extends Computer {
    private int powerSupply;

    public DesktopComputer(String brand, String model, int ram, int powerSupply) {
        super(brand, model, ram);
        this.powerSupply = powerSupply;
    }

    public void turnOn() {
        System.out.println("Компьютер включен");
    }

    @Override
    public void showInfo() {
        super.showInfo();
        System.out.println("Блок питания: " + powerSupply + " Вт");
    }
}

class Smartphone extends Device {
    private double screenSize;

    public Smartphone(String brand, String model, double screenSize) {
        super(brand, model);
        this.screenSize = screenSize;
    }

    public void call() {
        System.out.println("Звонок...");
    }

    @Override
    public void showInfo() {
        super.showInfo();
        System.out.println("Экран: " + screenSize);
    }
}

public class Main {
    public static void main(String[] args) {
        Laptop laptop = new Laptop("ASUS", "TUF", 16, 5000);
        DesktopComputer pc = new DesktopComputer("MSI", "Gaming", 32, 750);
        Smartphone phone = new Smartphone("Samsung", "S24", 6.2);

        laptop.showInfo();
        laptop.charge();

        System.out.println();

        pc.showInfo();
        pc.turnOn();

        System.out.println();

        phone.showInfo();
        phone.call();
    }
}