错误:类型可转换必须实现继承的抽象方法car.rent(java.lang.string,int)

发布于 2025-01-20 15:42:08 字数 3189 浏览 4 评论 0原文

我的程序正在给出实现继承的抽象方法的错误消息。

在其中我应该在主要或类“ CAR”中实现该方法?

每次尝试运行程序时,我都会收到此错误消息

在子程序中显示错误,但我认为它源于主程序或类“ CAR”。

  <Error: The type Convertible must implement the inherited abstract method 
  Car.Rent(java.lang.String, int)>

这是我的子程序,其中错误是:

  public class Convertible extends Car {


 //=========== CONSTRUCTOR ===========//
 /* To instantiate a Convertible object
 * @param code        - The car code of this car
 * @param make        - The maker of this car
 * @param model       - The model name of this car
 * @param openTopTime - The time it takes to open the convertible top (in seconds) */

  private double openTopTime;


  public Convertible( int code, String make, String model, double openTopTime ) {
  super (id, make, model);
  this.openTopTime = openTopTime;
   }

  /* Get the time it takes for the car to open it's convertible top
  * @param renter - The renter's name */
   public double OpenTopTime() {
   return this.OpenTopTime;      
  }
}

和我的主要程序:

  public class CRSMain {


  public static void main(String[] args) {
  CRS crs = new CRS();                         
  String carListFilename = "CarList.txt";     
  
  
  Displayer c = new Displayer ();
  c.Sedan ( cl );
  c.Coupe ( c2 );
  }
  }
   public class Displayer {
   // Write a method that will dynamically display

   public void Show( Car c ) {
   // Calling overriden method.

   Car c1 = new Sedan("1008","Honda","Civic","Good on gas");
  
  
     }
    }


    import java.util.Date;


   public abstract class Car {
   // Global Variables for the car types
   public static final int SEDAN       = 0;
   public static final int COUPE       = 1;
   public static final int CROSSOVER   = 2;
   public static final int CONVERTIBLE = 3;

   private int id;
   private String make;
   private String model;
   private int mileage;
   private boolean isRent;
   private String renter;
   private int allowableDist;
   private Date dueDate;

  //============== Constructor ===============
  /* Default constructor for initiating a Car object */
  public Car() {
  this.dueDate = new Date();
  }

 /* To instantiate a Car object
  * @param id          - The car Id of this car
  * @param make        - The maker of this car
  * @param model       - The model name of this car */
  public Car( int id, String make, String model) {
  this.id = id;
  this.make = make;
  this.model = model;
    }

     //============= Private Methods ===============
     /* May add your own private methods here */   


     //============= Public Methods ================   
  /* Get the Car ID
  * @return - The car code */
  public int GetId() {
   return this.id;    // Dummy return value. Needs to be modified.
 }

 /* Get the car maker
  * @return - The car maker */   
  public String GetMake() {
   return this.make;    // Dummy return value. Needs to be modified.
 }

 /* Get the car model
  * @return - The car model */   
 public String GetModel() {
   return this.model;    // Dummy return value. Needs to be modified.

}

My program is giving an error message of implementing an inherited abstract method.

Where should I implement the method, in my main or the class "Car" ?

I keep getting this error message every time I try to run my program,

The error shows in the Subprogram, but I think it stems from the main program or the class "Car".

  <Error: The type Convertible must implement the inherited abstract method 
  Car.Rent(java.lang.String, int)>

This is my Subprogram, where the error is:

  public class Convertible extends Car {


 //=========== CONSTRUCTOR ===========//
 /* To instantiate a Convertible object
 * @param code        - The car code of this car
 * @param make        - The maker of this car
 * @param model       - The model name of this car
 * @param openTopTime - The time it takes to open the convertible top (in seconds) */

  private double openTopTime;


  public Convertible( int code, String make, String model, double openTopTime ) {
  super (id, make, model);
  this.openTopTime = openTopTime;
   }

  /* Get the time it takes for the car to open it's convertible top
  * @param renter - The renter's name */
   public double OpenTopTime() {
   return this.OpenTopTime;      
  }
}

And my main program:

  public class CRSMain {


  public static void main(String[] args) {
  CRS crs = new CRS();                         
  String carListFilename = "CarList.txt";     
  
  
  Displayer c = new Displayer ();
  c.Sedan ( cl );
  c.Coupe ( c2 );
  }
  }
   public class Displayer {
   // Write a method that will dynamically display

   public void Show( Car c ) {
   // Calling overriden method.

   Car c1 = new Sedan("1008","Honda","Civic","Good on gas");
  
  
     }
    }


    import java.util.Date;


   public abstract class Car {
   // Global Variables for the car types
   public static final int SEDAN       = 0;
   public static final int COUPE       = 1;
   public static final int CROSSOVER   = 2;
   public static final int CONVERTIBLE = 3;

   private int id;
   private String make;
   private String model;
   private int mileage;
   private boolean isRent;
   private String renter;
   private int allowableDist;
   private Date dueDate;

  //============== Constructor ===============
  /* Default constructor for initiating a Car object */
  public Car() {
  this.dueDate = new Date();
  }

 /* To instantiate a Car object
  * @param id          - The car Id of this car
  * @param make        - The maker of this car
  * @param model       - The model name of this car */
  public Car( int id, String make, String model) {
  this.id = id;
  this.make = make;
  this.model = model;
    }

     //============= Private Methods ===============
     /* May add your own private methods here */   


     //============= Public Methods ================   
  /* Get the Car ID
  * @return - The car code */
  public int GetId() {
   return this.id;    // Dummy return value. Needs to be modified.
 }

 /* Get the car maker
  * @return - The car maker */   
  public String GetMake() {
   return this.make;    // Dummy return value. Needs to be modified.
 }

 /* Get the car model
  * @return - The car model */   
 public String GetModel() {
   return this.model;    // Dummy return value. Needs to be modified.

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文