Java Fundamentals, Objects, More Exercises: Company Roster
Здравейте колеги. Условието на задачата е:
Define a class Employee that holds the following information: name, salary, position, department, email and age.
The name, salary, position and department are mandatory while the rest are optional.
Your task is to write a program which takes N lines of employees from the console and calculates the department
with the highest average salary and prints for each employee in that department his name, salary, email and age –
sorted by salary in descending order. If an employee doesn’t have an email – in place of that field you should print
“n/a” instead, if he doesn’t have an age – print “-1” instead. The salary should be printed to two decimal places
after the seperator.
Hint: you can define a Department class that holds list of employees.
Test #1:
Input
4
Pesho 120.00 Dev Development pesho@abv.bg 28
Toncho 333.33 Manager Marketing 33
Ivan 840.20 ProjectLeader Development ivan@ivan.com
Gosho 0.20 Freeloader Nowhere 18
Output
Highest Average Salary: Development
Ivan 840.20 ivan@ivan.com -1
Pesho 120.00 pesho@abv.bg 28
Test #2
Input
6
Stanimir 496.37 Temp Coding stancho@yahoo.com
Yovcho 610.13 Manager Sales
Toshko 609.99 Manager Sales toshko@abv.bg 44
Venci 0.02 Director BeerDrinking beer@beer.br 23
Andrei 700.00 Director Coding
Popeye 13.3333 Sailor SpinachGroup popeye@pop.ey
Output
Highest Average Salary: Sales
Yovcho 610.13 n/a -1
Toshko 609.99 toshko@abv.bg 44
------------------------------------------------------------------------------------------------------------------------
Гърми ми тест #4 в judge-a. Линкове към pastebin:
1. Main Class - https://pastebin.com/5Wx2H6Vh
2. Employee Class - https://pastebin.com/rAZDxeYY
3. Department Class - https://pastebin.com/k9ppNcs9
-------------------------------------------------------------------------------------------------------------------------
Някои идеи? Знам че кода е некадърно написан. Нов съм на Джава, а и обекти не съм писал от страшно много време. Нито съм гледал лекцията за обекти, нито съм правил задачи от Lab и Домашна. На домашната направих само 4-та понеже един колега ме помоли и сега тази също. Така че освен грешката в кода, бих се радвал да ми кажете ако има и лошо написан код и да ме поправите.
Благодаря за отговора. Main метода ми е доста интересен. После ще проверя дали няма да стане по този начин.