Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaIntro5.java
More file actions
Latest commit
40 lines (32 loc) · 1.25 KB
/
Copy pathJavaIntro5.java
File metadata and controls
40 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
publicclassJavaIntro5 {
publicstaticvoidmain(Stringargs[]) {
motorm1 = newmotor(0); //new is used to create an instance of the class called an object
motorm2 = newmotor(1);
System.out.println("m1 channel: " + m1.getChannel());
System.out.println("m2 channel: " + m2.getChannel());
m1.setSpeed(1);
m2.setSpeed(-1);
System.out.println("m1 speed: " + m1.getSpeed());
System.out.println("m2 speed: " + m2.getSpeed());
}
}
//Simple motor class
classmotor{
//classes can have fields that store data
intchannel; //which port is the motor connected too
doublespeed = 0; //how fast should the motor be going -1 to 1
motor(intc){ //This is the constructor, it doesn't have a return type or void
channel = c; //channel doesn't get a value set until the consttuctor is run
}
intgetChannel(){ //this is a "getter" method it returns a value
returnchannel;
}
doublegetSpeed(){
returnspeed;
}
voidsetSpeed(doubles){ //this is a "setter" method it sets a value
speed = s;
}
//a complete motor class would have methods that actually control the motor
//most of those methods are already created for us in FRC
}