Last active
January 5, 2024 10:30
-
-
Save isaacssemugenyi/951b88f3649b3441f21d88c6fee7b443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package builder; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Car { | |
private String make; | |
private String name; | |
private String color; | |
private int model; | |
private List<String> countriesPresent = new ArrayList<>(); | |
public void setMake(String make) { | |
this.make = make; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public void setColor(String color) { | |
this.color = color; | |
} | |
public void setModel(int model) { | |
this.model = model; | |
} | |
public void setCountriesPresent(List<String> countriesPresent) { | |
this.countriesPresent = countriesPresent; | |
} | |
@Override | |
public String toString() { | |
return String.format( | |
"{ make = %s, name = %s, color = %s, model = %s , countriesPresent = %s }", | |
make, | |
name, | |
color, | |
model, | |
countriesPresent | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package builder; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args){ | |
Car car1 = new Car(); | |
car1.setMake("Tesla"); | |
car1.setName("Model X"); | |
car1.setModel(2020); | |
car1.setColor("Blue"); | |
car1.setCountriesPresent(List.of("USA", "Germany", "China")); | |
System.out.println(car1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment