简体   繁体   中英

Passing a class as a parameter

I've been assigned to write a small program using classes and constructors but seem to be stuck. Heres my code:

public static class ParkingMeter {

    int hours;
    int minutes;

    public ParkingMeter(int hours,int minutes){
        String time = Integer.toString(getMinutes(hours,minutes));


    }
     private int getMinutes(int hours, int minutes){
            int time = (hours * 60) + minutes;
         return time;
        }
}

public static class ParkedCar{

    String CompanyName;             // Company name
    String Model;                   // Car model
    String Color;                   // Car color
    String PlateNumber;             // License plate number
    String Minutes;                 // number of minutes parked 

    public ParkedCar(String companyName, String model, String color,String plate, String minutes){
        CompanyName = companyName;
        Model = model;
        Color = color;
        PlateNumber = plate;
        Minutes = minutes;
    }
 }
public static class PoliceOfficer{
   String OfficerName;
   String BadgeNumber;

   public PoliceOfficer(String name,String badge){
       OfficerName = name;
       BadgeNumber = badge;
   }
   public static void checkTheCar(ParkedCar, ParkingMeter){
       // do something

   }
}

I have to pass the classes into a method located inside the PoliceOfficer class but i get the error <identifier> expected . not sure what i'm doing wrong here. thanks.

You should give your variables a name.

public static void checkTheCar(ParkedCar pc, ParkingMeter pm){
       // do something

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM