This is the task:
You are asked to represent the real-world entity Car in an object orient program. For the purpose of this exercise, only assume that an object of type Car can be created out of three different parts, engine, wheel, and window. To represent these components you need to create a separate class to represent each one. The specifications for each of the required classes are given below:and these are my classes:
Class Engine: This class should describe an engine in terms of its Cylinder Capacity (CC), number of cylinders, number of valves, and horse power. The class needs to define two constructors, a default one that accepts no arguments but initializes class members to reasonable values while the second one, a copy constructor, that accepts value for the four attributes and assign them to the class data members. The class should also define four methods, start(), stop(),getHorsePower(), and setHorsePower(). The start() and stop() methods will just display, on the screen, appropriate messages when called. The setHorsePower() will receive an integer value for the horse power and assign it to the appropriate data member while the getHorsePower() will receive no argument but will return the current value of the horse power.
Class Wheel: This class should describe the wheels in a Car in terms of how many wheels a car has, the size of the wheel, and proper inflation pressure. The class needs to define a non-default constructor that accepts values for the three attributes and assign them to corresponding class data members. The class should also define two methods, getPressure() and setPressure(). The setPressure() will receive an integer value for the proper psi value and assign it to appropriate data member while the getPressure() will receive no argument but will return the current value of the tire pressure.
Class Window: This class should describe the Windows in a car in terms of how many windows a car has and the width and the height of a window (assuming all windows have the same dimension) The class needs to define a non-default constructor that accepts values for the three attributes and assign them to corresponding class data members. The class should also define three methods, rollUp(), rollDown(), and ComputerWindowArea(). Both the rollUp() and rollDown() method will just display appropriate messages on the screen when called. The ComputerWindowArea() will compute the area of a window (assuming it is a rectangle) and returning the area value to the caller.
Class Car: This class should represent a car, a real-word entity. Each car must have an engine, a wheel, and a window objects. To construct an object of type Car, you need to invoke a constructor that accepts objects of types Engine, Wheel, and Window respectively then copy these objects to the appropriate class members. The class should also define three methods, displayWheelPressure(), displayWindowArea(), and displayValveNumber(). The task of each of these methods is to display, on the screen, the value described by the method name.
Class TestCar: This is a driver class which will have the main() method. The class will create two objects of type Car. The first one has an Engine with the following specifications (CC = 2400, Cylinder # = 4, # of valves = 16, and hp = 166). This car object should have 4 wheels, of size 175, and proper pressure of 31. Also it has 2 windows, each is 45X50 in size. For the second Car object, your program should assign appropriate value for the engine specifications, This car object should have 4 wheels, of size 215, and proper pressure of 35. Also it has a 4 windows, each is 50X60 in size. After creating the two objects the program should display (using appropriate messages) for every object: the wheel pressure, the area of the window, the number of valves, and the horse power of the engine of that object.
Note: Every class must be in a separate file but all of them under the same directory.
Expand|Select|Wrap|Line Numbers
- public class Engine{
- // Declare the varibles
- double cylinderCapacity,horsePower;
- int numberOfCylinders,numberOfValves;
- Engine obj1= new Engine();
- // Default constructor accepts no arguments
- Engine(){
- cylinderCapacity=200.00;
- horsePower=500.00;
- numberOfCylinders=6;
- numberOfValves=12;
- }
- // A copy constructor accepts value for the four attributes and assign them to the class data members
- Engine(double a, double b, int c, int d){
- cylinderCapacity=a;
- horsePower=b;
- numberOfCylinders=c;
- numberOfValves=d;
- }
- // Methods will just display, on the screen, appropriate messages when called
- void start(){
- System.out.println("The start method was called");
- }
- void stop(){
- System.out.println("The stop method was called");
- }
- // This method receives an integer value for the horse power and assign it to the appropriate data member
- void setHorsePower(int horsePower){
- int power;
- power=horsePower;
- }
- // This method receives no argument but will return the current value of the horse power.
- double getHosrePower(){
- return horsePower;
- }
- int getValveNumber(){
- return numberOfValves;
- }
- }
Expand|Select|Wrap|Line Numbers
- public class Wheel{
- // Declare the variables
- Wheel obj2 = new Wheel();
- int numberOfWheels;
- double sizeOfWheels,inflationPressure;
- // Non-default constructor that accepts values for the three attributes and assign them to corresponding class data members
- Wheel(int a,double b,double c){
- numberOfWheels=a;
- sizeOfWheels=b;
- inflationPressure=c;
- }
- // This method receives an integer value for the proper psi value and assign it to appropriate data member
- void setPressure(int inflationPressure){
- int pressure;
- pressure=inflationPressure;
- }
- // This method receives no argument but will return the current value of the tire pressure
- double getPressure(){
- return inflationPressure;
- }
- }
Expand|Select|Wrap|Line Numbers
- public class Window{
- // Declare the variables
- int numberOfWindows;
- double height,width;
- Window obj3= new Window();
- // Non-default constructor that accepts values for the three attributes and assign them to corresponding class data members
- Window(){
- numberOfWindows=4;
- height=3.7;
- width=1.2;
- }
- // These methods will just display appropriate messages on the screen when called.
- void rollUp(){
- System.out.println(" Window was rooled up");
- }
- void rollDown(){
- System.out.println(" Window was rolled down");
- }
- // This method computes the area of a window and returning the area value to the caller.
- double computerWindowArea(double height,double width){
- double length_1,length_2,area;
- length_1=height;
- length_2=width;
- area=length_1 * length_2;
- return area;
- }
- }
Expand|Select|Wrap|Line Numbers
- public class Car{
- Engine point1=new Engine();
- Wheel point2= new Wheel();
- Window point3= new Window();
- Car(Engine obj1,Wheel obj2,Window obj3){
- point1=obj1;
- point2=obj2;
- point3=obj3;
- }
- double displayWheelPressure(){
- System.out.println(" The pressure is " + point2.getPressure());
- }
- double displayWindowArea(){
- System.out.println(" The area of the window is " + point3.computerWindowArea(4,4));
- }
- double displayValveNumber(){
- System.out.println(" The valve number is " + point1.getValveNumber());
- }
- }
Expand|Select|Wrap|Line Numbers
- public class TestCar{
- public static void main(String[] args) {
- // Create two objects of type car
- Car firstCar = new Car();
- Car secondCar= new Car();
- }
- }
can any one give my a hent.