Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.org.apache.bcel.internal.generic.ATHROW;
- import javax.swing.*;
- import java.net.StandardProtocolFamily;
- import java.util.ArrayList;
- public class Autosalloni {
- private String emri;
- protected ArrayList<Automjeti> automjetet;
- public Autosalloni(String e) throws AutoException {
- if (e == null || e.trim().isEmpty())
- throw new AutoException("Emri i autosallonit nuk duhet te jete i brazet!");
- emri = e;
- automjetet = new ArrayList<Automjeti>();
- }
- public void shtoAutomjetin(Automjeti a) throws AutoException {
- if (a == null || automjetet.contains(a))
- throw new AutoException("Automjeti null ose egziston ne arraylist");
- automjetet.add(a);
- }
- public class Kombi extends Automjeti implements Tempomati {
- private int nrUlesve;
- public Kombi(String p, int c, int nr) throws AutoException {
- super(p, c);
- if (nr < 5)
- throw new AutoException("Kombi duhet te ket se paku 5 ulese!");
- nrUlesve = nr;
- }
- public int getNrUlesve() {
- return nrUlesve;
- }
- public boolean eshteAutomatik() {
- return false;
- }
- public boolean kaTempomat() {
- return false;
- }
- public String toString() {
- return super.toString() + "numri i ulseve" + nrUlesve + " nuk eshte automatik dhe nuk ka tempomat!";
- }
- }
- static class SportsCar extends Automjeti {
- private int maxShpejtsa;
- public class SportsCar(String p,int c,int max) throws AutoException{
- super(p,c);
- if(max < 260 || max > 360)
- throw new AutoException("Shpejtsia max duheet te jet mes 260 dhe 360");
- maxShpejtsa = max;
- }
- public int getMaxShpejtsa(){
- return maxShpejtsa;
- }
- public boolean eshteAutomatik(){
- return false;
- }
- public String toString()
- {
- return super.toString()+" me shpejtsi "+maxShpejtsa+" nuk eshte automatik!";
- }
- }
- public Automjeti mjetiMeIShpejte(){
- Automjeti temp = null;
- for(Automjeti a: automjetet){
- if(a instanceof SportsCar){
- SportsCar sc = (SportsCar)a;
- if(temp == null || ((SportsCar)temp).getMaxShpejtsa() < sc.getMaxShpejtsa()){
- temp = (Automjeti)sc;
- }
- }
- return temp;
- }
- public Automjeti meIKushtueshmiMeNgjyre(String ngj){
- Automjeti tmep = null;
- for(Automjeti a: automjetet){
- if(a instanceof Limo && ((Limo)a).getNgjyra().equalsIgnoreCase(ngj)){
- Limo l = (Limo)a;
- if(temp == null || l.getQmimi() > ((Limo)temp).getQmimi())
- temp = (Automjeti)l;
- }
- }
- return temp;
- }
- }
- public static void main(String [] args)
- {
- Autosalloni a = null;
- try {
- a = new Autosalloni("Ubt Cars");
- a.shtoAutomjetin(new Limo("BMW",5600,"Bardhe"));
- System.out.println("Automjeti me i shpejte : \n"+a.mjetiMeIShpejte());
- System.out.print();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement