Advertisement
Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. import com.sun.org.apache.bcel.internal.generic.ATHROW;
  2.  
  3. import javax.swing.*;
  4. import java.net.StandardProtocolFamily;
  5. import java.util.ArrayList;
  6.  
  7. public class Autosalloni {
  8. private String emri;
  9. protected ArrayList<Automjeti> automjetet;
  10.  
  11. public Autosalloni(String e) throws AutoException {
  12. if (e == null || e.trim().isEmpty())
  13. throw new AutoException("Emri i autosallonit nuk duhet te jete i brazet!");
  14. emri = e;
  15. automjetet = new ArrayList<Automjeti>();
  16. }
  17.  
  18. public void shtoAutomjetin(Automjeti a) throws AutoException {
  19.  
  20. if (a == null || automjetet.contains(a))
  21. throw new AutoException("Automjeti null ose egziston ne arraylist");
  22. automjetet.add(a);
  23. }
  24.  
  25. public class Kombi extends Automjeti implements Tempomati {
  26. private int nrUlesve;
  27.  
  28. public Kombi(String p, int c, int nr) throws AutoException {
  29. super(p, c);
  30. if (nr < 5)
  31. throw new AutoException("Kombi duhet te ket se paku 5 ulese!");
  32.  
  33. nrUlesve = nr;
  34. }
  35.  
  36. public int getNrUlesve() {
  37. return nrUlesve;
  38. }
  39.  
  40. public boolean eshteAutomatik() {
  41. return false;
  42. }
  43.  
  44. public boolean kaTempomat() {
  45. return false;
  46. }
  47.  
  48. public String toString() {
  49. return super.toString() + "numri i ulseve" + nrUlesve + " nuk eshte automatik dhe nuk ka tempomat!";
  50. }
  51. }
  52.  
  53. static class SportsCar extends Automjeti {
  54. private int maxShpejtsa;
  55.  
  56. public class SportsCar(String p,int c,int max) throws AutoException{
  57. super(p,c);
  58. if(max < 260 || max > 360)
  59. throw new AutoException("Shpejtsia max duheet te jet mes 260 dhe 360");
  60. maxShpejtsa = max;
  61. }
  62. public int getMaxShpejtsa(){
  63. return maxShpejtsa;
  64. }
  65. public boolean eshteAutomatik(){
  66. return false;
  67. }
  68. public String toString()
  69. {
  70. return super.toString()+" me shpejtsi "+maxShpejtsa+" nuk eshte automatik!";
  71. }
  72.  
  73. }
  74. public Automjeti mjetiMeIShpejte(){
  75. Automjeti temp = null;
  76.  
  77. for(Automjeti a: automjetet){
  78. if(a instanceof SportsCar){
  79. SportsCar sc = (SportsCar)a;
  80. if(temp == null || ((SportsCar)temp).getMaxShpejtsa() < sc.getMaxShpejtsa()){
  81. temp = (Automjeti)sc;
  82. }
  83. }
  84. return temp;
  85. }
  86. public Automjeti meIKushtueshmiMeNgjyre(String ngj){
  87. Automjeti tmep = null;
  88.  
  89. for(Automjeti a: automjetet){
  90. if(a instanceof Limo && ((Limo)a).getNgjyra().equalsIgnoreCase(ngj)){
  91. Limo l = (Limo)a;
  92. if(temp == null || l.getQmimi() > ((Limo)temp).getQmimi())
  93. temp = (Automjeti)l;
  94. }
  95. }
  96. return temp;
  97. }
  98. }
  99. public static void main(String [] args)
  100. {
  101. Autosalloni a = null;
  102. try {
  103. a = new Autosalloni("Ubt Cars");
  104. a.shtoAutomjetin(new Limo("BMW",5600,"Bardhe"));
  105.  
  106.  
  107. System.out.println("Automjeti me i shpejte : \n"+a.mjetiMeIShpejte());
  108. System.out.print();
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement