Created
June 3, 2019 09:51
-
-
Save dnivra26/cff23fcedcb9100c01edaf48dfcd6b04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dnivra26; | |
class Auto { | |
public int getFrontTyreAir() { | |
return frontTyreAir; | |
} | |
public int getBackLeftTyreAir() { | |
return backLeftTyreAir; | |
} | |
public int getBackRightTyreAir() { | |
return backRightTyreAir; | |
} | |
public Auto(int frontTyreAir, int backLeftTyreAir, int backRightTyreAir) { | |
this.frontTyreAir = frontTyreAir; | |
this.backLeftTyreAir = backLeftTyreAir; | |
this.backRightTyreAir = backRightTyreAir; | |
} | |
private int frontTyreAir, backLeftTyreAir, backRightTyreAir; | |
} | |
class Bike { | |
public int getFrontTyreAir() { | |
return frontTyreAir; | |
} | |
public int getBackTyreAir() { | |
return backTyreAir; | |
} | |
public Bike(int frontTyreAir, int backTyreAir) { | |
this.frontTyreAir = frontTyreAir; | |
this.backTyreAir = backTyreAir; | |
} | |
private int frontTyreAir, backTyreAir; | |
} | |
public class AirChecker { | |
public int findAirLeft(Object vehicle) { | |
if (vehicle.getClass() == Auto.class) { | |
return ((Auto) vehicle).getBackLeftTyreAir() + ((Auto) vehicle).getBackRightTyreAir() + ((Auto) vehicle).getFrontTyreAir(); | |
} else { | |
return ((Bike) vehicle).getBackTyreAir() + ((Bike) vehicle).getFrontTyreAir(); | |
} | |
} | |
public static void main(String[] args) { | |
AirChecker airChecker = new AirChecker(); | |
Auto auto = new Auto(1, 2, 3); | |
Bike bike = new Bike(1, 2); | |
System.out.println(airChecker.findAirLeft(auto)); | |
System.out.println(airChecker.findAirLeft(bike)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment