mercredi 6 juillet 2016

Accessing contents of a class through parameter in java?

i need to access the contents of a class in this case: ParkingMeter through the parameters of another method in another class: public static void checkTheCar(ParkedCar pc, ParkingMeter pm) but not sure how to do that. the method checkTheCar has to retrieve a integer from ParkingMeter and check if its in the right range. any advice is appreciated.

public static class ParkingMeter {

    int time;

    public ParkingMeter(int hours,int minutes){
         time = (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 pc, ParkingMeter pm){
       // do something

   }

   }

Aucun commentaire:

Enregistrer un commentaire