Write a class called Dealer that has two fields of type Vehi
Solution
1 Ans:-
//Created a Dealer Class
public class Dealer {
//Vehicle and Customer objects
public Vehicle myVehicle;
public Customer myCustomer;
//Constructor for creating Dealer object by using a Customer object
public Dealer(Customer myCustomer){
this.myCustomer = myCustomer;
}
//Constructor for creating Dealer object by using Customer and Vehicle objects.
public Dealer(Customer myCustomer, Vehicle myVehicle){
this.myCustomer = myCustomer;
this.myVehicle = myVehicle;
}
//Accessor Method to get vehicle
public Vehicle getVehicle(){
return this.myVehicle;
}
//Accessor Method to get Customer
public Customer getCustomer(){
return this.myCustomer;
}
//set vehicle to a new vehicle
public void setVehicle(Vehicle myVehicle){
this.myVehicle = myVehicle;
}
}
//Vehicle Class
class Vehicle{
public String make;
public String model;
public String VIN;
}
//Customer Class
class Customer{
public Name myNmae;
public String accountNumber;
//Accessor Method
public Name getName(){
return this.myName;
}
}
//Name Class
class Name{
public String last_name;
public String first_name;
//Accessor Method to get Last_name
public String getLastName(){
return this.last_name;
}
}
2) Given d is a reference to a Dealer Object.We have to write the java statement which will get the last_name of an individual customer
d.getCustomer().getName().getLastName();
see the ANs :- 1 above for the Customer class and Name Class Definitions. Dealer class contains getCustomer method . Customer Class contains the getName() method and the Name class contains the getLastName() method for retrieving the last name of the customer of the Dealer d object.

