fork download
  1. abstract class Publication {
  2. int numberOfAuthors;
  3. public Publication(int numberOfAuthors) {
  4. this.numberOfAuthors = numberOfAuthors;
  5. }
  6. public abstract double computeScore();
  7. }
  8.  
  9. class Journal extends Publication {
  10. double impactFactor;
  11. public Journal(int numberOfAuthors, double impactFactor) {
  12. super(numberOfAuthors);
  13. this.impactFactor = impactFactor;
  14. }
  15. @Override
  16. public double computeScore() {
  17. return (impactFactor * 0.5) / numberOfAuthors;
  18. }
  19. }
  20.  
  21. class ConferenceProceeding extends Publication {
  22. boolean isIndexed;
  23. public ConferenceProceeding(int numberOfAuthors, boolean isIndexed) {
  24. super(numberOfAuthors);
  25. this.isIndexed = isIndexed;
  26. }
  27. @Override
  28. public double computeScore() {
  29. return isIndexed ? 0.25 / numberOfAuthors : 0.2 / numberOfAuthors;
  30. }
  31. }
  32.  
  33. class Author {
  34. String name;
  35. java.util.List<Publication> publications = new java.util.ArrayList<>();
  36. public Author(String name) {
  37. this.name = name;
  38. }
  39. public void addPublication(Publication pub) {
  40. publications.add(pub);
  41. }
  42. public double computeScore() {
  43. double total = 0;
  44. for (Publication pub : publications) {
  45. total += pub.computeScore();
  46. }
  47. return total;
  48. }
  49. }
  50.  
  51. class University {
  52. java.util.List<Author> authors = new java.util.ArrayList<>();
  53. public void addAuthor(Author author) {
  54. authors.add(author);
  55. }
  56. public double computeScore() {
  57. double total = 0;
  58. for (Author author : authors) {
  59. total += author.computeScore();
  60. }
  61. return total;
  62. }
  63. }
  64.  
  65. public class Main {
  66. public static void main(String[] args) {
  67. Journal journal1 = new Journal(3, 2.5);
  68. Journal journal2 = new Journal(4, 3.0);
  69. ConferenceProceeding conf1 = new ConferenceProceeding(2, true);
  70. ConferenceProceeding conf2 = new ConferenceProceeding(5, false);
  71.  
  72. Author author1 = new Author("Alice");
  73. Author author2 = new Author("Bob");
  74.  
  75. author1.addPublication(journal1);
  76. author1.addPublication(journal2);
  77. author1.addPublication(conf1);
  78. author1.addPublication(conf2);
  79.  
  80. author2.addPublication(journal1);
  81. author2.addPublication(journal2);
  82. author2.addPublication(conf1);
  83. author2.addPublication(conf2);
  84.  
  85. University university = new University();
  86. university.addAuthor(author1);
  87. university.addAuthor(author2);
  88.  
  89. System.out.println("Score of Author 1: " + author1.computeScore());
  90. System.out.println("Score of Author 2: " + author2.computeScore());
  91. System.out.println("Total score of the University: " + university.computeScore());
  92. }
  93. }
Success #stdin #stdout 0.11s 57756KB
stdin
Standard input is empty
stdout
Score of Author 1: 0.9566666666666668
Score of Author 2: 0.9566666666666668
Total score of the University: 1.9133333333333336