public class Variables
1: /**
2: * Variables.java -- creating and manipulating variables
3: *
4: * @author Mark Young (A00000000)
5: * @version 1.1, 2014-09-09
6: */
7: public class Variables {
9: public static void main(String[] args) {
10: // create variables
11: int empNum;
12: int numberOfPods, peasPerPod, totalPeas;
13: int totalEnrolment = 22;
14: int numberOfBaskets, eggsPerBasket, totalEggs;
16: // initialize variables
17: numberOfBaskets = 10;
18: eggsPerBasket = 6;
19: totalEggs = numberOfBaskets * eggsPerBasket;
21: // print using variables
22: System.out.println(
23: "\nnumberOfBaskets = 10;" +
24: "\neggsPerBasket = 6;" +
25: "\neggsPerBasket = numberOfBaskets * eggsPerBasket;" +
26: "\n\tnumberOfBaskets == " + numberOfBaskets +
27: "\n\teggsPerBasket == " + eggsPerBasket +
28: "\n\ttotalEggs == " + totalEggs
29: );
31: // revise variable
32: eggsPerBasket = eggsPerBasket - 2;
34: // show how only that revision occurs
35: System.out.println(
36: "\neggsPerBasket = eggsPerBasket - 2;" +
37: "\n\tnumberOfBaskets == " + numberOfBaskets +
38: "\n\teggsPerBasket == " + eggsPerBasket +
39: "\n\ttotalEggs == " + totalEggs +
40: "\n(Note: totalEggs has NOT changed!)"
41: );
43: // create more variables
44: int midtermScore = 78;
45: double midtermWeighted = midtermScore * 0.20;
46: char letterGrade = 'B';
47: boolean failedMidterm = (midtermScore < 50);
49: // report on those variables
50: System.out.println(
51: "\nint midtermScore = 78;" +
52: "\ndouble midtermWeighted = midtermScore * 0.20;" +
53: "\nchar letterGrade = 'B';" +
54: "\nboolean failedMidterm = (midtermScore < 50);" +
55: "\n\tmidtermScore == " + midtermScore +
56: "\n\tmidtermWeighted == " + midtermWeighted +
57: "\n\tfailedMidterm == " + failedMidterm +
58: "\n(Note: midtermWeighted might not be EXACTLY 15.6." +
59: "\n That's because of \"rounding error\".)"
60: );
61: System.out.println();
62: }
64: }