Some Rectifications you can do
Comparing type == "MyVi" , you should not compare String's with == operator because it will compare for object i.e hashcode comparison.
You should use type.equals("MyVi");
You should not use local variables to calculate the car payment as they need to be initialized so you should pass them to the payment method or use them as an instance variable.
public int payment(int Carpayment,int hour,String type){
//int Carpayment;
//int hour;
//String type;
if (type == "MyVi")
Carpayment = 10 * hour;
else
if (type == "Iswara")
Carpayment = 15 * hour;
else
if (type == "Waja")
Carpayment = 20 * hour;
else
if (type == "Vios")
Carpayment = 25 * hour;
else
if (type == "Civic")
Carpayment = 30 * hour;
return Carpayment;
}
3.You can do something like this
Class Car {
int Carpayment;
int hour;
String type;
Car(int hour,String type) {
this.hour = hour;
this.type = type;
}
public int payment(){
if (type == "MyVi")
Carpayment = 10 * hour;
else
if (type == "Iswara")
Carpayment = 15 * hour;
else
if (type == "Waja")
Carpayment = 20 * hour;
else
if (type == "Vios")
Carpayment = 25 * hour;
else
if (type == "Civic")
Carpayment = 30 * hour;
return Carpayment;
}
}
Car civic_1 = new Car(4,"Civic");
System.out.println(civic_1.payment());//Prints the Car payment to be done