Skip to content

Commit 3f001be

Browse files
authored
fix: remove elon
1 parent 235a13e commit 3f001be

File tree

17 files changed

+781
-781
lines changed

17 files changed

+781
-781
lines changed

config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
"status": "active"
111111
},
112112
{
113-
"slug": "elons-toy-car",
114-
"name": "Elon's Toy Car",
113+
"slug": "jedliks-toy-car",
114+
"name": "Jedlik's Toy Car",
115115
"uuid": "2ae791e9-eb7a-4344-841d-0c4797e5106c",
116116
"concepts": [
117117
"classes"
-42.4 KB
Binary file not shown.
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# Hints
2-
3-
## General
4-
5-
## 1. Buy a brand-new remote controlled car
6-
7-
- [This page shows how to create a new instance of a class][creating-objects].
8-
9-
## 2. Display the distance driven
10-
11-
- Keep track of the distance driven in a [field][fields].
12-
- Consider what visibility to use for the field (does it need to be used outside the class?).
13-
14-
## 3. Display the battery percentage
15-
16-
- Keep track of the distance driven in a [field][fields].
17-
- Initialize the field to a specific value corresponding to the initial battery charge.
18-
- Consider what visibility to use for the field (does it need to be used outside the class?).
19-
20-
## 4. Update the number of meters driven when driving
21-
22-
- Update the field representing the distance driven.
23-
24-
## 5. Update the battery percentage when driving
25-
26-
- Update the field representing the battery percentage driven.
27-
28-
## 6. Prevent driving when the battery is drained
29-
30-
- Add a conditional to only update the distance and battery if the battery is not already drained.
31-
- Add a conditional to display the empty battery message if the battery is drained.
32-
33-
[creating-objects]: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html
34-
[fields]: https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
1+
# Hints
2+
3+
## General
4+
5+
## 1. Buy a brand-new remote controlled car
6+
7+
- [This page shows how to create a new instance of a class][creating-objects].
8+
9+
## 2. Display the distance driven
10+
11+
- Keep track of the distance driven in a [field][fields].
12+
- Consider what visibility to use for the field (does it need to be used outside the class?).
13+
14+
## 3. Display the battery percentage
15+
16+
- Keep track of the distance driven in a [field][fields].
17+
- Initialize the field to a specific value corresponding to the initial battery charge.
18+
- Consider what visibility to use for the field (does it need to be used outside the class?).
19+
20+
## 4. Update the number of meters driven when driving
21+
22+
- Update the field representing the distance driven.
23+
24+
## 5. Update the battery percentage when driving
25+
26+
- Update the field representing the battery percentage driven.
27+
28+
## 6. Prevent driving when the battery is drained
29+
30+
- Add a conditional to only update the distance and battery if the battery is not already drained.
31+
- Add a conditional to display the empty battery message if the battery is drained.
32+
33+
[creating-objects]: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html
34+
[fields]: https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
# Instructions
2-
3-
In this exercise you'll be playing around with a remote controlled car, which you've finally saved enough money for to buy.
4-
5-
Cars start with full (100%) batteries. Each time you drive the car using the remote control, it covers 20 meters and drains one percent of the battery.
6-
7-
The remote controlled car has a fancy LED display that shows two bits of information:
8-
9-
- The total distance it has driven, displayed as: `"Driven <METERS> meters"`.
10-
- The remaining battery charge, displayed as: `"Battery at <PERCENTAGE>%"`.
11-
12-
If the battery is at 0%, you can't drive the car anymore and the battery display will show `"Battery empty"`.
13-
14-
You have six tasks, each of which will work with remote controlled car instances.
15-
16-
## 1. Buy a brand-new remote controlled car
17-
18-
Implement the (_static_) `ElonsToyCar.buy()` method to return a brand-new remote controlled car instance:
19-
20-
```java
21-
ElonsToyCar car = ElonsToyCar.buy();
22-
```
23-
24-
## 2. Display the distance driven
25-
26-
Implement the `ElonsToyCar.distanceDisplay()` method to return the distance as displayed on the LED display:
27-
28-
```java
29-
ElonsToyCar car = ElonsToyCar.buy();
30-
car.distanceDisplay();
31-
// => "Driven 0 meters"
32-
```
33-
34-
## 3. Display the battery percentage
35-
36-
Implement the `ElonsToyCar.batteryDisplay()` method to return the battery percentage as displayed on the LED display:
37-
38-
```java
39-
ElonsToyCar car = ElonsToyCar.buy();
40-
car.batteryDisplay();
41-
// => "Battery at 100%"
42-
```
43-
44-
## 4. Update the number of meters driven when driving
45-
46-
Implement the `ElonsToyCar.drive()` method that updates the number of meters driven:
47-
48-
```java
49-
ElonsToyCar car = ElonsToyCar.buy();
50-
car.drive();
51-
car.drive();
52-
car.distanceDisplay();
53-
// => "Driven 40 meters"
54-
```
55-
56-
## 5. Update the battery percentage when driving
57-
58-
Update the `ElonsToyCar.drive()` method to update the battery percentage:
59-
60-
```java
61-
ElonsToyCar car = ElonsToyCar.buy();
62-
car.drive();
63-
car.drive();
64-
car.batteryDisplay();
65-
// => "Battery at 98%"
66-
```
67-
68-
## 6. Prevent driving when the battery is drained
69-
70-
Update the `ElonsToyCar.drive()` method to not increase the distance driven nor decrease the battery percentage when the battery is drained (at 0%):
71-
72-
```java
73-
ElonsToyCar car = ElonsToyCar.buy();
74-
75-
// Drain the battery
76-
// ...
77-
78-
car.distanceDisplay();
79-
// => "Driven 2000 meters"
80-
81-
car.batteryDisplay();
82-
// => "Battery empty"
83-
```
1+
# Instructions
2+
3+
In this exercise you'll be playing around with a remote controlled car, which you've finally saved enough money for to buy.
4+
5+
Cars start with full (100%) batteries. Each time you drive the car using the remote control, it covers 20 meters and drains one percent of the battery.
6+
7+
The remote controlled car has a fancy LED display that shows two bits of information:
8+
9+
- The total distance it has driven, displayed as: `"Driven <METERS> meters"`.
10+
- The remaining battery charge, displayed as: `"Battery at <PERCENTAGE>%"`.
11+
12+
If the battery is at 0%, you can't drive the car anymore and the battery display will show `"Battery empty"`.
13+
14+
You have six tasks, each of which will work with remote controlled car instances.
15+
16+
## 1. Buy a brand-new remote controlled car
17+
18+
Implement the (_static_) `JedliksToyCar.buy()` method to return a brand-new remote controlled car instance:
19+
20+
```java
21+
JedliksToyCar car = JedliksToyCar.buy();
22+
```
23+
24+
## 2. Display the distance driven
25+
26+
Implement the `JedliksToyCar.distanceDisplay()` method to return the distance as displayed on the LED display:
27+
28+
```java
29+
JedliksToyCar car = JedliksToyCar.buy();
30+
car.distanceDisplay();
31+
// => "Driven 0 meters"
32+
```
33+
34+
## 3. Display the battery percentage
35+
36+
Implement the `JedliksToyCar.batteryDisplay()` method to return the battery percentage as displayed on the LED display:
37+
38+
```java
39+
JedliksToyCar car = JedliksToyCar.buy();
40+
car.batteryDisplay();
41+
// => "Battery at 100%"
42+
```
43+
44+
## 4. Update the number of meters driven when driving
45+
46+
Implement the `JedliksToyCar.drive()` method that updates the number of meters driven:
47+
48+
```java
49+
JedliksToyCar car = JedliksToyCar.buy();
50+
car.drive();
51+
car.drive();
52+
car.distanceDisplay();
53+
// => "Driven 40 meters"
54+
```
55+
56+
## 5. Update the battery percentage when driving
57+
58+
Update the `JedliksToyCar.drive()` method to update the battery percentage:
59+
60+
```java
61+
JedliksToyCar car = JedliksToyCar.buy();
62+
car.drive();
63+
car.drive();
64+
car.batteryDisplay();
65+
// => "Battery at 98%"
66+
```
67+
68+
## 6. Prevent driving when the battery is drained
69+
70+
Update the `JedliksToyCar.drive()` method to not increase the distance driven nor decrease the battery percentage when the battery is drained (at 0%):
71+
72+
```java
73+
JedliksToyCar car = JedliksToyCar.buy();
74+
75+
// Drain the battery
76+
// ...
77+
78+
car.distanceDisplay();
79+
// => "Driven 2000 meters"
80+
81+
car.batteryDisplay();
82+
// => "Battery empty"
83+
```
Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
1-
# Introduction
2-
3-
## Classes
4-
5-
The primary object-oriented construct in Java is the _class_, which is a combination of data (_fields_) and behavior (_methods_).
6-
The fields and methods of a class are known as its _members_.
7-
8-
Access to members can be controlled through access modifiers, the two most common ones being:
9-
10-
- `public`: the member can be accessed by any code (no restrictions).
11-
- `private`: the member can only be accessed by code in the same class.
12-
13-
You can think of a class as a template for creating instances of that class.
14-
To create an instance of a class (also known as an _object_), the `new` keyword is used:
15-
16-
```java
17-
class Car {
18-
}
19-
20-
// Create two car instances
21-
Car myCar = new Car();
22-
Car yourCar = new Car();
23-
```
24-
25-
Fields have a type and a name (defined in camelCase) and can be defined anywhere in a class (by convention cased in PascalCase):
26-
27-
```java
28-
class Car {
29-
// Accessible by anyone
30-
public int weight;
31-
32-
// Only accessible by code in this class
33-
private String color;
34-
}
35-
```
36-
37-
One can optionally assign an initial value to a field.
38-
If a field does _not_ specify an initial value, it will be set to its type's default value.
39-
An instance's field values can be accessed and updated using dot notation.
40-
41-
```java
42-
class Car {
43-
// Will be set to specified value
44-
public int weight = 2500;
45-
46-
// Will be set to default value (0)
47-
public int year;
48-
}
49-
50-
Car newCar = new Car();
51-
newCar.weight; // => 2500
52-
newCar.year; // => 0
53-
54-
// Update value of the field
55-
newCar.year = 2018;
56-
```
57-
58-
Private fields are usually updated as a side effect of calling a method.
59-
Such methods usually don't return any value, in which case the return type should be `void`:
60-
61-
```java
62-
class CarImporter {
63-
private int carsImported;
64-
65-
public void importCars(int numberOfCars)
66-
{
67-
// Update private field from public method
68-
carsImported = carsImported + numberOfCars;
69-
}
70-
}
71-
```
1+
# Introduction
2+
3+
## Classes
4+
5+
The primary object-oriented construct in Java is the _class_, which is a combination of data (_fields_) and behavior (_methods_).
6+
The fields and methods of a class are known as its _members_.
7+
8+
Access to members can be controlled through access modifiers, the two most common ones being:
9+
10+
- `public`: the member can be accessed by any code (no restrictions).
11+
- `private`: the member can only be accessed by code in the same class.
12+
13+
You can think of a class as a template for creating instances of that class.
14+
To create an instance of a class (also known as an _object_), the `new` keyword is used:
15+
16+
```java
17+
class Car {
18+
}
19+
20+
// Create two car instances
21+
Car myCar = new Car();
22+
Car yourCar = new Car();
23+
```
24+
25+
Fields have a type and a name (defined in camelCase) and can be defined anywhere in a class (by convention cased in PascalCase):
26+
27+
```java
28+
class Car {
29+
// Accessible by anyone
30+
public int weight;
31+
32+
// Only accessible by code in this class
33+
private String color;
34+
}
35+
```
36+
37+
One can optionally assign an initial value to a field.
38+
If a field does _not_ specify an initial value, it will be set to its type's default value.
39+
An instance's field values can be accessed and updated using dot notation.
40+
41+
```java
42+
class Car {
43+
// Will be set to specified value
44+
public int weight = 2500;
45+
46+
// Will be set to default value (0)
47+
public int year;
48+
}
49+
50+
Car newCar = new Car();
51+
newCar.weight; // => 2500
52+
newCar.year; // => 0
53+
54+
// Update value of the field
55+
newCar.year = 2018;
56+
```
57+
58+
Private fields are usually updated as a side effect of calling a method.
59+
Such methods usually don't return any value, in which case the return type should be `void`:
60+
61+
```java
62+
class CarImporter {
63+
private int carsImported;
64+
65+
public void importCars(int numberOfCars)
66+
{
67+
// Update private field from public method
68+
carsImported = carsImported + numberOfCars;
69+
}
70+
}
71+
```
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Introduction
2-
3-
%{concept:classes}
1+
# Introduction
2+
3+
%{concept:classes}

0 commit comments

Comments
 (0)