Skip to content

Commit 2f98b21

Browse files
committed
feat: adds Formula1Car methods
1 parent 7df9237 commit 2f98b21

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/evanphilakhong/Formula1Car.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
@Getter
77
@Setter
88
public class Formula1Car {
9+
private Track track;
910
private Team team;
1011
private String[] sponsors;
1112
private String driverName;
1213
private int driverNum;
14+
private int position;
1315
private TyreCompound currTyre;
14-
private boolean isDrs;
16+
private boolean drs;
1517

1618
//Constructors
1719
public Formula1Car() {
@@ -20,24 +22,45 @@ public Formula1Car() {
2022
this.driverName = "";
2123
this.driverNum = 0;
2224
this.currTyre = null;
23-
this.isDrs = false;
25+
this.drs = false;
2426
}
2527

26-
public Formula1Car(Team team, String[] sponsors, String driverName, int driverNum, TyreCompound currTyre) {
28+
public Formula1Car(Team team, String[] sponsors, String driverName, int driverNum, int position, TyreCompound currTyre) {
2729
this.team = team;
2830
this.sponsors = sponsors;
2931
this.driverName = driverName;
3032
this.driverNum = driverNum;
33+
this.position = position;
3134
this.currTyre = currTyre;
32-
this.isDrs = false;
35+
this.drs = false;
3336
}
3437

3538
// methods
3639
public void printSponsors() {
37-
for (String sponsor : sponsors) {
38-
System.out.println(sponsor);
40+
if (sponsors.length == 0) {
41+
System.out.println("There are no Sponsors");
42+
} else {
43+
System.out.println("Here's a list of our Sponsors:");
44+
for (String sponsor : sponsors) {
45+
System.out.println(sponsor);
46+
}
3947
}
4048
}
49+
50+
public boolean isDrsAvailible() {
51+
if (track.isDrsZone()) {
52+
this.drs = true;
53+
return true;
54+
}
55+
return false;
56+
}
57+
58+
public boolean rainStrategy() {
59+
if (track.isRaining()) {
60+
currTyre.setCurrTyre(TyreCompound.WET);
61+
}
62+
}
63+
4164
public static void main(String[] args) {
4265
Formula1Car formula1Car = new Formula1Car();
4366
Team team = Team.MCLAREN;

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/evanphilakhong/Track.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class Track {
1010
private String trackLocation;
1111
private int numLaps;
1212
private int trackLengthInKm;
13-
private boolean isDrsZone;
14-
private boolean isRaining;
13+
private boolean drsZone;
14+
private boolean raining;
1515

1616
public static void main(String[] args) {
1717

0 commit comments

Comments
 (0)