2014-01-09 2 views
0

У меня есть 4 класса. TaxiCo, Vehicle, Taxi and Shuttle.
Я сделал такси и челнок, чтобы наследовать от класса автомобиля .. так что теперь вместо того, чтобы добавлять автобус и добавить такси, я просто хочу, чтобы иметь возможность добавить автомобиль .. но я получаю сообщение о том, что автомобиль-конструктор в классе не может быть применен дать типы .. я не знаю, что случилось, как и все, что я сделал это изменить способ добавить такси, который работал хорошо ..не можете добавить машины в список массива

Taxi Co класс

import java.util.*; 
public class TaxiCo 
{ 
    // The name of this company. 
    private String companyName; 
    // The name of the company's base. 
    private final String base;  
    // The fleet of taxis. 
    private ArrayList<Vehicle> VehicleFleet; 
    // A value for allocating taxi ids. 
    private int nextID; 
    // A list of available destinations for shuttles. 
    private ArrayList<String> destinations; 

    /** 
    * Constructor for objects of class TaxiCo. 
    * @param name The name of this company. 
    */ 
    public TaxiCo(String name) 
    { 
     companyName = name; 
     base = "base"; 
     VehicleFleet = new ArrayList<Vehicle>(); 
     nextID = 1; 
     destinations = new ArrayList<String>(); 
     fillDestinations(); 
    } 

    /** 
    * Record that we have a new Vehicle. 
    * A unique ID will be allocated. 
    */ 
    public void addVehicle() 
    { 
     Vehicle vehicle = new Vehicle(base, "Vehicle #" + nextID); 
     taxiFleet.add(vehicle); 
     // Increment the ID for the next one. 
     nextID++; 
    } 

    /** 
    * Return the Vehicle with the given id. 
    * @param id The id of the Vehicle to be returned. 
    * @return The matching Vehicle, or null if no match is found. 
    */ 
    public Vehicle lookup(String id) 
    { 
     boolean found = false; 
     Vehicle Vehicle = null; 
     Iterator<Vehicle> it = VehicleFleet.iterator(); 
     while(!found && it.hasNext()) { 
      Vehicle = it.next(); 
      if(id.equals(Vehicle.getID())) { 
       found = true; 
      } 
     } 
     if(found) { 
      return Vehicle; 
     } 
     else { 
      return null; 
     } 
    } 

    /** 
    * Show the status of the Vehicle fleet. 
    */ 
    public void showStatus() 
    { 
     System.out.println("Current status of the " + companyName + " fleet"); 
     for(Vehicle Vehicle : VehicleFleet) { 
      System.out.println(Vehicle.getStatus()); 
     } 
    } 

    /** 
    * Put all the possible shuttle destinations in a list. 
    */ 
    private void fillDestinations() 
    { 
     destinations.add("Canterbury West"); 
     destinations.add("Canterbury East"); 
     destinations.add("The University"); 
     destinations.add("Whitstable"); 
     destinations.add("Herne Bay"); 
     destinations.add("Sainsbury's"); 
     destinations.add("Darwin"); 
     destinations.add("Keynes"); 
    } 
} 
+0

Вы можете разместить 'main' метод? – Christian

+0

1) Чтобы лучше помочь, опубликуйте [SSCCE] (http://sscce.org/). Обратите внимание, что документ рассматривается и обсуждается на [этот вопрос] (http://meta.stackexchange.com/q/214955/155831), приветствуются вклады. 2) Всегда копировать/вставлять вывод ошибок и исключений. –

+0

1 момент добавит его внизу – Emperial

ответ

2

в addVehicle() методом из TaxiCo класса, вы передаете 2 String s к конструктору, в то время как вы определили его только с параметром 1 String.

public void addVehicle() 
{ 
    Vehicle vehicle = new Vehicle(base, "Vehicle #" + nextID); // BAD! Calling with 2 Strings 
    taxiFleet.add(vehicle); 
    // Increment the ID for the next one. 
    nextID++; 
} 

Вы должны изменить его, так что вы передаете в качестве параметра только 1 String. Что-то вроде:

Vehicle vehicle = new Vehicle("Just one STRING!"); 

Edit: Вы также делаете это с Taxi конструктора в методе addTaxi

+0

Я не понимаю, что вы имеете в виду .. если я прохожу только одну строку, он все равно не работает – Emperial

+0

Вы получаете другую или ту же ошибку? Пожалуйста, отредактируйте сообщение с трассировкой стека. – Christian

+0

ах, не волнуйся :) Я понял это наш :) У меня есть еще один вопрос tho .. для getStatus в классе автомобилей .. Мне нужно, чтобы он возвращал сообщение, если такси бесплатно .. но я мог бы управлять им .. может вы мне помогаете? – Emperial

Смежные вопросы