JAVA PROGAMMING Implement a Java Application that implements a MAN driving a CAR
ID: 3575681 • Letter: J
Question
JAVA PROGAMMING
Implement a Java Application that implements a MAN driving a CAR.
To solve this project you have to :
1. Create a CAR class with :Attributes : [MAKE THEM PRIVATE!!!!]
engineOn : Boolean
fuelTank : float
speed : float
acceleration : float
deceleration : float
owner : string
Methods: you have to provide the corresponding methods to change the attributes’ value [MAKE THEM PUBLIC].
Implement the corresponding constructor!!!!
2. Create a MAN class with :Attributes :
name: string
surname : string
address : string
myCar : CAR
Methods : you have to provide the corresponding methods to change the attributes’ value [MAKE THEM PUBLIC].
implement the corresponding constructor!!!!!
3. Create a class GARAGE that is executing the following operations:
Creates car object
Creates man object that owns the car
Let’s man object driving the car….that means he can :
Switch the engine ON and OFF
He can refuel the car
He can make the car accelerating
He can make the car slowing down
He can stop the car
Explanation / Answer
import java.util.*;
class Car
{
private boolean engineOn;
private float fuelTank;
private float speed;
private float acceleration;
private float deceleration;
private String owner;
Car(boolean e, float f, float s, float a, float d, String n)
{
engineOn=e;
fuelTank=f;
speed=s;
acceleration=a;
deceleration=d;
owner=n;
}
public void setEngineOn(boolean b)
{
engineOn=b;
}
public void setFuelTank(float f)
{
fuelTank=f;
}
public void setSpeed(float a)
{
speed=a;
}
public void setAcceleration(float a)
{
acceleration=a;
}
public void setDeceleration(float d)
{
deceleration=d;
}
public void setOwner(String n)
{
owner=n;
}
public String toString()
{
return "Car Details... Engine On: "+engineOn+" Fuel Tank: "+fuelTank+" Speed: "+speed+" Acceleration: "+acceleration+" Decceleration: "+deceleration;
}
}
class Man
{
private String name, surname, address;
private Car myCar;
Man(String n, String s, String a, Car c)
{
name=n;
surname=s;
address=a;
myCar=c;
}
public void setName(String s)
{
name=s;
}
public void setSurName(String s)
{
surname=s;
}
public void setAddress(String s)
{
address=s;
}
public void setCar(Car c)
{
myCar=c;
}
public String toString()
{
return name+" "+surname+" "+address+" "+myCar.toString();
}
}
public class Garage
{
public static void main(String s[])
{
String name="Asif Iqbal";
Car c= new Car(false,40,0,0,0,name);
c.setEngineOn(true);
c.setSpeed(40);
c.setAcceleration(10);
Man m= new Man(name,"Khan", "California",c);
System.out.println(m);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.