Answer to Question #218799 in Java | JSP | JSF for Hamza

Question #218799

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.  


1
Expert's answer
2021-07-19T10:14:45-0400
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);
		
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS