Skip to content

Commit ae5c298

Browse files
committed
first commit
0 parents  commit ae5c298

14 files changed

Lines changed: 1263 additions & 0 deletions

src/Car.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
public class Car {
2+
String make = "Chevrolet";
3+
String model;
4+
int year = 2020;
5+
String color = "Blue";
6+
double price = 50000.00;
7+
8+
String name;
9+
10+
// constructors, can have multiple if different parameters
11+
Car() {
12+
}
13+
14+
Car(String name) {
15+
this.name = name;
16+
}
17+
18+
Car(String make, String model) {
19+
this.make = make;
20+
this.model = model;
21+
}
22+
23+
// copy constructor
24+
Car(Car x) {
25+
this.copy(x);
26+
}
27+
28+
void drive() {
29+
System.out.println("You drive the car");
30+
}
31+
void brake() {
32+
System.out.println("You brake the car");
33+
}
34+
35+
// overriding toString built-in method
36+
public String toString() {
37+
return make + "\n" + model + "\n" + color + "\n" + year;
38+
}
39+
40+
// getters
41+
public String getMake() {
42+
return make;
43+
}
44+
public String getModel() {
45+
return model;
46+
}
47+
48+
// setters
49+
public void setMake(String make) {
50+
this.make = make;
51+
}
52+
public void setModel(String model) {
53+
this.model = model;
54+
}
55+
56+
// copy method
57+
public void copy(Car x) {
58+
this.setMake(x.getMake());
59+
this.setModel(x.getModel());
60+
}
61+
}

src/DiceRoller.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Random;
2+
3+
public class DiceRoller {
4+
5+
// GLOBAL
6+
Random random;
7+
int number;
8+
9+
DiceRoller() {
10+
random = new Random();
11+
// LOCAL -> need to pass parameters to method
12+
// Random random = new Random();
13+
// int number = 0;
14+
// roll(random, number);
15+
roll();
16+
}
17+
18+
// void roll(Random random, int number) {
19+
void roll() {
20+
number = random.nextInt(6)+1;
21+
System.out.println(number);
22+
}
23+
}

src/Human.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Human {
2+
3+
String name;
4+
int age;
5+
double weight;
6+
7+
// constructors must have same name than Class
8+
Human(String name, int age, double weight) {
9+
this.name = name;
10+
this.age = age;
11+
this.weight = weight;
12+
}
13+
14+
void eat() {
15+
System.out.println(this.name + " is eating");
16+
}
17+
void drink() {
18+
System.out.println(this.name + " is drinking");
19+
}
20+
21+
}

0 commit comments

Comments
 (0)