2017.12.16 - Pojazd - PojazdCzterokołowySilnikowy - laboratorium Gdynia

 

2017.12.16 - laboratorium Gdynia

Pojazd - PojazdCzterokołowySilnikowy

PojazdCzterokołowySpalinowy extends PojazdCzterokołowySilnikowy

PojazdCzterokołowyElektryczny extends PojazdCzterokołowySilnikowy

UWAGA KOD SIĘ NIE KOMPILUJE:

public class PojazdyProgram {

	public static void main( String[] args ) {	
		PojazdCzterokołowySilnikowy pojazd1 = new PojazdCzterokołowySpalinowy();
		PojazdCzterokołowySilnikowy pojazd2 = new PojazdCzterokołowyElektryczny();

		pojazd1.startEngine();
		pojazd1.accelerate( 100 );

		System.out.println( "Current vehicle speed: " + pojazd1.getCurrentVelocity() );

		pojazd1.decelerate( 0 );

		System.out.println( "Current vehicle speed: " + pojazd1.getCurrentVelocity() );

		pojazd2.startEngine();
		pojazd2.accelerate( 100 );

		System.out.println( "Current vehicle speed: " + pojazd2.getCurrentVelocity() );

		pojazd2.decelerate( 0 );

		System.out.println( "Current vehicle speed: " + pojazd2.getCurrentVelocity() );

	}

}


abstract class PojazdCzterokołowySilnikowy {

	final int WHEEL_COUNT = 4;

	String name;
	int enginePower;
	private int currentVelocity;

	void startEngine() {
		System.out.println( "Engine started" );
	}

	/**
	 * [accelerate description]
	 * @param targetVelocity [description]
	 */
	abstract public void accelerate( int targetVelocity );
	//  {
	// 	System.out.println( "Vehicle accelerates" );
	// 	setCurrentVelocity( targetVelocity );
	// }	

	public void decelerate( int targetVelocity ) {
		System.out.println( "Vehicle decelerates" );
		setCurrentVelocity( targetVelocity );
	}

	private void setCurrentVelocity( int velocity ) {
		for( int v = getCurrentVelocity(); v <= velocity; v++ ) { //...mija czas
			currentVelocity = v;
			System.out.println( "Current velocity: " + v );
		}
	}

	public int getCurrentVelocity() {
		return currentVelocity;
	}
}



class PojazdCzterokołowySpalinowy extends PojazdCzterokołowySilnikowy {
	
//	TypPaliwa typPaliwa;	//atrybut 
	float pojemnośćBaku;

	void zatankujPaliwo() {

	}
}

class PojazdCzterokołowyElektryczny extends PojazdCzterokołowySilnikowy {
	float pojemnośćAkumulatorów;

	void naładujAkumulatory() {

	}
}