Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Date;
  3. import java.util.ArrayDeque;
  4. import java.text.SimpleDateFormat;
  5. import java.text.DateFormat;
  6. import java.time.LocalDate;
  7. import java.text.ParseException;
  8.  
  9. interface SomeInterface {
  10. public void input();
  11. public void output();
  12. public double method();
  13. }
  14.  
  15. class Film implements SomeInterface{
  16. private String title, director;
  17. private int releaseYear;
  18. private double cost, profit;
  19.  
  20. public Film(String title, String director, int releaseYear, double cost, double profit) {
  21. this.title = title;
  22. this.director = director;
  23. this.releaseYear = releaseYear;
  24. this.cost = cost;
  25. this.profit = profit;
  26. input();
  27. }
  28.  
  29. public void input() {
  30. if (releaseYear < 0) {
  31. throw new IllegalArgumentException("The year of the creation can not be a negative number");
  32. }
  33. if (cost < 0) {
  34. throw new IllegalArgumentException("The cost can not be a negative number");
  35. }
  36. if (profit < 0) {
  37. throw new IllegalArgumentException("The profit can not be a negative number");
  38. }
  39. }
  40.  
  41. @Override
  42. public String toString() {
  43. return String.format("\nFilm object\nTitle: %s\nDirector: %s\nYear of the release: %d\nCost: %.2f\nProfit: %.2f", title, director, releaseYear, cost, profit);
  44. }
  45.  
  46. @Override
  47. public int hashCode() {
  48. return releaseYear * releaseYear;
  49. }
  50.  
  51. public void output() {
  52. System.out.print( toString() );
  53. }
  54.  
  55. public double method() {
  56. return profit - cost;
  57. }
  58. }
  59.  
  60. class Masterpiece implements SomeInterface{
  61. private String vudMustectva, title, author;
  62. private int creationYear;
  63.  
  64. public Masterpiece(String vudMustectva, String title, String author, int creationYear) {
  65. this.vudMustectva = vudMustectva;
  66. this.title = title;
  67. this.author = author;
  68. this.creationYear = creationYear;
  69. input();
  70. }
  71.  
  72. public void input() {
  73. if (creationYear < 0) {
  74. throw new IllegalArgumentException("The year of the creation can not be a negative number");
  75. }
  76. }
  77.  
  78. @Override
  79. public String toString() {
  80. return String.format("\nMasterpiece object\nVud mustectva: %s\nTitle: %s\nAuthor: %s\nYear of the creation: %d", vudMustectva, title, author, creationYear);
  81. }
  82.  
  83. @Override
  84. public int hashCode() {
  85. return creationYear * creationYear;
  86. }
  87.  
  88. public void output() {
  89. System.out.print( toString() );
  90. }
  91.  
  92. public double method() {
  93. LocalDate date_now = LocalDate.now();
  94. return date_now.getYear() - creationYear;
  95. }
  96. }
  97.  
  98. class Brigade implements SomeInterface{
  99. private Date date;
  100. private int employeesAmount;
  101. private double plan, factVurobitok;
  102.  
  103. public Brigade(String date, int employeesAmount, double plan, double factVurobitok ) throws Exception {
  104. this.date = new SimpleDateFormat("dd/MM/yyyy").parse(date);
  105. this.employeesAmount = employeesAmount;
  106. this.plan = plan;
  107. this.factVurobitok = factVurobitok;
  108. input();
  109. }
  110.  
  111. public void input() {
  112. if (employeesAmount < 0) {
  113. throw new IllegalArgumentException("Amount of employees can not be a negative number");
  114. }
  115. if (plan < 0) {
  116. throw new IllegalArgumentException("Plan can not be a negative number");
  117. }
  118. if (factVurobitok < 0) {
  119. throw new IllegalArgumentException("Fact. vurobitok can not be a negative number");
  120. }
  121. }
  122.  
  123. @Override
  124. public String toString() {
  125. DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  126. return String.format("\nBrigade object\nDate: %s\nEmployees amount: %s\nPlan: %s\nFact. vurobitok: %s", dateFormat.format(date), employeesAmount, plan, factVurobitok);
  127. }
  128.  
  129. @Override
  130. public int hashCode() {
  131. return employeesAmount * employeesAmount;
  132. }
  133.  
  134. public void output() {
  135. System.out.print( toString() );
  136. }
  137.  
  138. public double method() {
  139. return 100 / plan * factVurobitok;
  140. }
  141. }
  142.  
  143.  
  144. public class lab10 {
  145. public static void main(String[] args) throws Exception {
  146.  
  147.  
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement