Write a Car class that has constant PI = 3.147, variable capacity, method numberOfRiders with a single parameter of integer type and return nothing and finally have private inner class called Engine. Write default, parameter and Copy constructor for both classes. The engine class has two inner variables fuleType and enginePower. Also write accessors and mutator method for both classes.
import javax.swing.JOptionPane;
class Car {
// constant PI = 3.147
private final float PI = 3.147f;
private int capacity;
private Engine engine;
public Car() {
engine=new Engine();
}
public Car(Car car) {
this.capacity = car.capacity;
engine=new Engine();
}
public void numberOfRiders(int capacity) {
this.capacity = capacity;
}
// private inner class called Engine.
private class Engine {
private String fuleType;
private float enginePower;
public Engine() {
}
public Engine(Engine engine) {
this.fuleType = engine.fuleType;
this.enginePower = engine.enginePower;
}
/**
* @return the fuleType
*/
public String getFuleType() {
return fuleType;
}
/**
* @param fuleType the fuleType to set
*/
public void setFuleType(String fuleType) {
this.fuleType = fuleType;
}
/**
* @return the enginePower
*/
public float getEnginePower() {
return enginePower;
}
/**
* @param enginePower the enginePower to set
*/
public void setEnginePower(float enginePower) {
this.enginePower = enginePower;
}
}
/**
* @return the capacity
*/
public int getCapacity() {
return capacity;
}
/**
* @param capacity the capacity to set
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
/**
* @return the engine
*/
public Engine getEngine() {
return engine;
}
/**
* @param engine the engine to set
*/
public void setEngine(Engine engine) {
this.engine = engine;
}
}
public class Q218799 {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Car car=new Car();
car.numberOfRiders(5);
}
}
Comments
Leave a comment