0

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.

Ronald
  • 77
  • 10
  • 1
    Passing a class and passing a reference to an instance of a class are not the same thing. If you're not familiar with the differences, here's a decent [summary of them](http://javarevisited.blogspot.com/2012/12/difference-between-class-and-object-in-oops-java.html). – D.B. Jun 26 '16 at 01:03

1 Answers1

4

You should give your variables a name.

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

}
intboolstring
  • 6,891
  • 5
  • 30
  • 44
  • 1
    You should also follow the Java naming conventions. Local and non-constant member variables should begin with a lower-case letter and be in camel case. Also, you don't pass classes as parameters. You pass pointers to objects, or you pass primitives, but never classes. – Lew Bloch Jun 26 '16 at 01:00
  • @LewBloch did you mean to tell that to OP? – intboolstring Jun 26 '16 at 01:01
  • @LewBloch you may also want to take a look at [this](http://stackoverflow.com/questions/2629357/does-java-have-pointers) thread. – intboolstring Jun 26 '16 at 01:03
  • @LewBloch you certainly can pass classes as parameters. It probably is not the intent here, but it can be done. When I say classes I mean the `Class` object, which I suppose if you're a purist might not be the same thing you were talking about. – D.B. Jun 26 '16 at 01:04
  • Classes are completely not the same as `Class` instances. Is "purist" a bad thing? If things are different, it's a mistake to say they aren't. You cannot pass classes as parameters to a method in Java. That is a fact. You may use the term wrong, but that is something you should fix, @D.B. It is also a fact that you can pass `Class` references to methods, but as we apparently agree, that is not the same thing at all. Not even impurely. Class, objects, and references are not at all the same thing. Using terms incorrectly causes misunderstanding and one should not do it. – Lew Bloch Jul 14 '16 at 22:49