Intro to Programming Examples
niemasd
940 views
2.2 Beyond ints
Video Game Example Initial Attempt
1
2
3
4
5
6
7
8
class VideoGame {
String mainTitle = "Final Fantasy XV";
String mainPrice = "$49.99";
String dlcTitle = "Episode Ardyn";
String dlcPrice = "$4.99";
String totalPrice = mainPrice + dlcPrice;
}
Video Game Example Second Attempt
1
2
3
4
5
6
7
8
class VideoGame {
String mainTitle = "Final Fantasy XV";
double mainPrice = 49.99;
String dlcTitle = "Episode Ardyn";
double dlcPrice = 4.99;
double totalPrice = mainPrice + dlcPrice;
}
Number Precision
1
2
3
4
5
6
7
class Numbers {
int num1 = 1 + 2;
int num2 = 3;
double num3 = 1.1 + 2.2;
double num4 = 3.3;
}
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.