hesh 1

gorazd avatar
gorazd
java
02/02/2026 3:10 PM
5.7 KB
59
Indexable
// Следните класи веќе се импортирани, не е дозволено копирање на класи овде, директно користејте ги како кога се достапни во други локални фајлови:
// The following classes are already imported, copying classes here is not allowed, use them directly as when they are available in other local files:

// CBHT, OBHT, MapEntry, SLLNode веќе се импортирани
// CBHT, OBHT, MapEntry, SLLNode are already imported
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.Scanner;

// Овде креирајте ги помошните класи за клуч и вредност
// Исполнете ги барањата од текстот за toString методите
// Дополнително осигурете се дека вашата клуч класа ќе ги имплементира потребните
// hashCode и equals методи

// Create the helper classes for key and value here
// Fulfill the requirements from the text for the toString methods
// Additionally, make sure that your key class will implement the required
// hashCode and equals methods
class Person implements Comparable<Person> {
    // поставете ги потребните полиња овде
    // declare the required fields here
    String name;
    int age;

    // имплементирајте соодветен конструктор
    // implement the constructor
    Person(String n, int a) {
        this.name = n;
        this.age = a;
    }

    @Override
    public String toString() {
        return "<"+name+", "+age+">";
    }
    // имплементирајте ги следните два методи за да работи табелата правилно
    // implement the following two methods to make the table work properly
    @Override
    public boolean equals(Object o) {
        if(this==o) return true;
        if(o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && name.equals(person.name);
    }
    @Override
    public int hashCode() {
        return age * (int) name.charAt(0);
    }
    @Override
    public int compareTo(Person o) {
        // First compare by name, then by age if names are equal
        int nameComparison = this.name.compareTo(o.name);
        if (nameComparison != 0) {
            return nameComparison;
        }
        return Integer.compare(this.age, o.age);
    }
}

class Project {
    int workingTime;
    int salary;

    Project(int wt, int s) {
        this.workingTime = wt;
        this.salary = s;
    }


    @Override
    public String toString() {
        return "<" + workingTime + ", " + salary + ">";
    }
}

public class Solution {
    public static void main(String[] args) {
        // Креирајте ја табелата според барањата
        // Create the table as requested
        Scanner scanner = new Scanner(System.in);
        CBHT<Person, Project> table = new CBHT<Person, Project>(10);

        int n = scanner.nextInt();
        for(int i = 0; i<n; i++){
            String name = scanner.next();
            int age = scanner.nextInt();;
            int time = scanner.nextInt();
            int rate = scanner.nextInt();
            
            Person employee = new Person(name, age);
            Project project = new Project(time, rate);
            
            SLLNode<MapEntry<Person, Project>> existing = table.search(employee);
            if(existing!=null){
                Project existingProject = existing.element.value;
                if(project.salary* project.workingTime > existingProject.salary*existingProject.workingTime)
                    table.insert(employee, project);
            }
            else{
                table.insert(employee, project);
            }
        }
        
        // Прочитајте ги податоците од влезот и пополнете ја табелата
        // Read the input data and fill the table

        // отпечатете ја вашата табела
        // print your table
        System.out.println(table);
    }
}

Editor is loading...
Leave a Comment