+ 1

Hi, how can i write system.out.println( color for v1and v3 is red) actually for more than two vehicles

public class Vehicle { private String color; Vehicle() { this.setColor("Red"); } Vehicle(String c) { this.setColor(c); } public void setColor(String c) { this.color = c; } public String getColor() { return color; Vehicle v1 = new Vehicle(); Vehicle v3= new Vehicle(); Vehicle v2 = new Vehicle("Green"); System.out.println(v2.getColor);

23rd Nov 2016, 3:51 PM
ehsan shahbazi
ehsan shahbazi - avatar
4 odpowiedzi
+ 1
i want the output for this code be: v1 and v3 are red and v2 is green with one system.out.println(????);
24th Nov 2016, 10:32 AM
ehsan shahbazi
ehsan shahbazi - avatar
+ 1
thank you
24th Nov 2016, 10:59 AM
ehsan shahbazi
ehsan shahbazi - avatar
0
Can you explain a little bit more what you want?
23rd Nov 2016, 10:51 PM
Lucas Heim
Lucas Heim - avatar
0
You can use "+" to connect several strings. System.out.println("V1 and V3 are " + v1.getColor() + " V2 is " + v2.getColor()); If you want a code that finds which one are equal, it will take a little bit more of work, but it's not hard.
24th Nov 2016, 10:50 AM
Lucas Heim
Lucas Heim - avatar