Advertisement
gazievDima

Untitled

Feb 22nd, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package com.homework11;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class TaskThree {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. List<Box> box = new ArrayList<>();
  11. box.add(new Box( new Orange(15,3)));
  12. box.add(new Box(new Apple(13, 4)));
  13. box.add(new Box(new Orange(17, 2)));
  14. box.add(new Box(new Orange(13, 1)));
  15. box.add(new Box(new Apple(8, 3)));
  16.  
  17. box.get(0).
  18.  
  19. }
  20.  
  21. }
  22.  
  23.  
  24. package com.homework11;
  25.  
  26. public class Box <T>{
  27.  
  28. T typeNameFruit;
  29.  
  30. public Box(T typeNameFruit) {
  31. this.typeNameFruit = typeNameFruit;
  32. }
  33.  
  34. //получаем вес коробки
  35. public int getWeight(T obj) {
  36. return 0;
  37.  
  38. }
  39.  
  40. //сравниваем коробки
  41. public boolean compare(T obj) {
  42. return false;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. package com.homework11;
  49.  
  50. public class Fruit {
  51.  
  52. private Integer quantityFruit;
  53. private Integer weightFruit;
  54.  
  55. public Integer getWeightFruit() {
  56. return 0;
  57. }
  58.  
  59. public Integer getQuantityFruit() {
  60. return quantityFruit;
  61. }
  62.  
  63. public Fruit(Integer quantityFruit, Integer weightFruit) {
  64. this.quantityFruit = quantityFruit;
  65. this.weightFruit = weightFruit;
  66. }
  67.  
  68. }
  69.  
  70.  
  71.  
  72. package com.homework11;
  73.  
  74. public class Apple extends Fruit {
  75. public String id = "testVariable";
  76.  
  77. public Apple(Integer quantityFruit, Integer weightFruit) {
  78. super(quantityFruit, weightFruit);
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement