Answer to Question #59129 in Java | JSP | JSF for Peter

Question #59129
The UML for an Instantiable class called Vehicle is shown below: Write an application program that uses an array to create three Vehicle objects with appropriate data. Add code to display the contents of the array. Vehicle -regNo:String -carMake:String +Vehicle() +Vehicle(String, String) +setRegNo(String):void +setCarMake(String):void +getRegNo():String +getCarMake():String +toString():String
1
Expert's answer
2016-04-13T15:09:04-0400
public class Main {
public static void main(String[] args) {
Vehicle array[] = new Vehicle[3];
array[0] = new Vehicle("BD51SMR", "Audio");
array[1] = new Vehicle("BD51SMR", "Ford");
array[2] = new Vehicle("UKPL8TE", "Mercedes");
for(int i = 0; i < array.length; i++){
System.out.println(array[i]);
}
}
}




public class Vehicle {
private String regNo;
private String carMake;

public Vehicle(){

}

public Vehicle(String regNo, String carMake){
this.regNo = regNo;
this.carMake = carMake;
}

public void setRegNo(String regNo){
this.regNo = regNo;
}

public void setCarMake(String carMake){
this.carMake = carMake;
}

public String getRegNo(){
return regNo;
}

public String getCarMake(){
return carMake;
}

public String toString(){
return regNo + " " + carMake;
}
}

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 first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS