Krcoding 2021-10-24 22:51 采纳率: 0%
浏览 85

问题求解(代码怎么写)

定义一个名为收费Charge的接口,其中声明一个名为收取费用fee的方法,该方法无参、无返回值。再定义一个名为调节温度的ControlTemperature接口,其中声明一个名为controlTemperature的方法,该方法无参、无返回值。定义一个名为公共汽车Bus的类,该类实现收费接口,在其收取费用的方法中输出提示字符串“Bus:$2.25 single ride”。定义一个名为出租车Taxi的类,该类同时实现收费和调节温度接口,在其收取费用的方法中输出提示字符串“Taxi:Drop charge:$2.60, Distance charge: $2.70 per mile, Time charge: $0.50 per minute”,在其controlTemperature方法中输出提示字符串“There is an air conditioning unit right above seats”。定义一个名为电影院Cinema的类,该类同时实现收费和调节温度接口,在其收取费用的方法中输出提示字符串“Cinema:$7-$8 on movies before noon, $13-$14 before 3pm, and $14-$15 for regular adult admission after 3pm”,在其controlTemperature方法中输出提示字符串“There is a Central Air Conditioner in the room”。定义一个用于测试的主类,在主方法中利用已定义的三个类分别创建对象,并调用每个对象中实现接口的所有方法。

  • 写回答

2条回答 默认 最新

  • 关注
    
    public interface Charge{
      void fee();
    }
    public interface ControlTemperature{
      void controlTemperature();
    
    }
    public class Bus implements Charge{
      public void fee(){
          System.out.println("Bus:$2.25 single ride");
      }
    }
    
    public class Taxi  implements Charge,ControlTemperature{
      public void fee(){
          System.out.println("Taxi:Drop charge:$2.60, Distance charge: $2.70 per mile, Time charge: $0.50 per minute");
      }
      public void controlTemperature(){
        System.out.println("There is an air conditioning unit right above seats");
      }
    
    }
    
    public class Cinema implements Charge,ControlTemperature{
      public void fee(){
          System.out.println("Cinema:$7-$8 on movies before noon, $13-$14 before 3pm, and $14-$15 for regular adult admission after 3pm");
      }
      public void controlTemperature(){
        System.out.println("There is a Central Air Conditioner in the room");
      }
    
    }
    
    //测试
    public class Test{
      public static void main(String[] args){
          new Bus().fee();
          Taxi  taxi = new Taxi();
           taxi.fee();
          taxi.controlTemperature();
          Cinema cinema= new Cinema ();
           cinema.fee();
          cinema.controlTemperature();
    
    
      }
    
    }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 10月24日