Skip to content

Commit af6a3cf

Browse files
authoredApr 28, 2022
Added files
1 parent 634a5a4 commit af6a3cf

27 files changed

+1459
-0
lines changed
 

Diff for: ‎ConsoleInput.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.Scanner;
2+
/**
3+
* Example of using the Scanner object to receive user input from the keyboard
4+
*
5+
* @author Ken Fogel
6+
*/
7+
public class ConsoleInput {
8+
9+
/**
10+
* This method is where the program begins doing useful work. You can name it anything
11+
* you want but by convention it should be a verb.
12+
*/
13+
public void perform() {
14+
Scanner sc = new Scanner(System.in);
15+
System.out.println("Enter an integer");
16+
int integerInput = sc.nextInt();
17+
System.out.println("The integer is " + integerInput);
18+
}
19+
20+
/**
21+
* Where the program begins
22+
*
23+
* @param args Command line arguments, not used in this program
24+
*/
25+
public static void main(String[] args) {
26+
var ConsoleInput = new ConsoleInput();
27+
ConsoleInput.perform();
28+
}
29+
}
30+
31+
/***********************************************************************
32+
* This work is licensed under the Creative Commons Attribution 4.0 *
33+
* International License. To view a copy of this license, *
34+
* visit http://creativecommons.org/licenses/by/4.0/ *
35+
* or send a letter to *
36+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
37+
***********************************************************************/

Diff for: ‎ConsolePrinting.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Example of using System.out.println
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class ConsolePrinting01 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
System.out.println("The moose is a majestic animal.");
14+
}
15+
16+
/**
17+
* Where the program begins
18+
*
19+
* @param args Command line arguments, not used in this program
20+
*/
21+
public static void main(String[] args) {
22+
ConsolePrinting01 consolePrinting01 = new ConsolePrinting01();
23+
consolePrinting01.perform();
24+
}
25+
}
26+
27+
/***********************************************************************
28+
* This work is licensed under the Creative Commons Attribution 4.0 *
29+
* International License. To view a copy of this license, *
30+
* visit http://creativecommons.org/licenses/by/4.0/ *
31+
* or send a letter to *
32+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
33+
***********************************************************************/
34+
35+

Diff for: ‎ConsolePrinting01.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Example of printing to the console
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class ConsolePrinting01 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
System.out.print("The moose is a majestic animal.");
14+
}
15+
16+
/**
17+
* Where the program begins
18+
*
19+
* @param args Command line arguments, not used in this program
20+
*/
21+
public static void main(String[] args) {
22+
var consolePrinting01 = new ConsolePrinting01();
23+
consolePrinting01.perform();
24+
}
25+
}
26+
27+
/***********************************************************************
28+
* This work is licensed under the Creative Commons Attribution 4.0 *
29+
* International License. To view a copy of this license, *
30+
* visit http://creativecommons.org/licenses/by/4.0/ *
31+
* or send a letter to *
32+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
33+
***********************************************************************/
34+

Diff for: ‎ConsolePrinting02.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Example of using concatenation to combine a string and a primitive variable
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class ConsolePrinting02 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
int moosePopulation = 1000000;
14+
System.out.println("There are as many as " + moosePopulation + " in Canada.");
15+
}
16+
17+
/**
18+
* Where the program begins
19+
*
20+
* @param args Command line arguments, not used in this program
21+
*/
22+
public static void main(String[] args) {
23+
var consolePrinting02 = new ConsolePrinting02();
24+
consolePrinting02.perform();
25+
}
26+
}
27+
28+
/***********************************************************************
29+
* This work is licensed under the Creative Commons Attribution 4.0 *
30+
* International License. To view a copy of this license, *
31+
* visit http://creativecommons.org/licenses/by/4.0/ *
32+
* or send a letter to *
33+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
34+
***********************************************************************/
35+

Diff for: ‎DecisionLoopTest.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Example of if/else logic
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class DecisionLoopTest {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
14+
int x = 4;
15+
int y = 6;
16+
if (x==y) {
17+
System.out.println(x + " and " + y + " are the equal");
18+
} else {
19+
System.out.println(x + " and " + y + " are not equal");
20+
}
21+
}
22+
23+
/**
24+
* Where the program begins
25+
*
26+
* @param args Command line arguments, not used in this program
27+
*/
28+
public static void main(String[] args) {
29+
var decisionLoopTest = new DecisionLoopTest();
30+
decisionLoopTest.perform();
31+
}
32+
}
33+
34+
/***********************************************************************
35+
* This work is licensed under the Creative Commons Attribution 4.0 *
36+
* International License. To view a copy of this license, *
37+
* visit http://creativecommons.org/licenses/by/4.0/ *
38+
* or send a letter to *
39+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
40+
***********************************************************************/
41+

Diff for: ‎DecisionLoopTest01.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Example of boolean expressions
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class DecisionLoopTest01 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
14+
// Comparison operators
15+
int x = 4;
16+
int y = 6;
17+
System.out.println(x + " == " + y + ": " + (x == y));
18+
System.out.println(x + " > " + y + ": " + (x > y));
19+
System.out.println(x + " < " + y + ": " + (x < y));
20+
System.out.println(x + " >= " + y + ": " + (x >= y));
21+
System.out.println(x + " <= " + y + ": " + (x <= y));
22+
23+
// Logical Operators
24+
int z = 5;
25+
System.out.println("(" + z + " > " + x + " && " + z + " < " + y +"): " + (z > x && z < y));
26+
z = 8;
27+
System.out.println("(" + z + " < " + x + " || " + z + " > " + y +"): " + (z < x || z > y));
28+
}
29+
30+
/**
31+
* Where the program begins
32+
*
33+
* @param args Command line arguments, not used in this program
34+
*/
35+
public static void main(String[] args) {
36+
var decisionLoopTest01 = new DecisionLoopTest01();
37+
decisionLoopTest01.perform();
38+
}
39+
}
40+
41+
/***********************************************************************
42+
* This work is licensed under the Creative Commons Attribution 4.0 *
43+
* International License. To view a copy of this license, *
44+
* visit http://creativecommons.org/licenses/by/4.0/ *
45+
* or send a letter to *
46+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
47+
***********************************************************************/
48+

Diff for: ‎DecisionLoopTest02.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Example of a decision with if
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class DecisionLoopTest02 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
14+
int x = 8;
15+
int y = 6;
16+
if (x == y) {
17+
System.out.println(x + " and " + y + " are equal");
18+
}
19+
20+
System.out.println("After the if statement's block of code");
21+
}
22+
23+
/**
24+
* Where the program begins
25+
*
26+
* @param args Command line arguments, not used in this program
27+
*/
28+
public static void main(String[] args) {
29+
var decisionLoopTest02 = new DecisionLoopTest02();
30+
decisionLoopTest02.perform();
31+
}
32+
}
33+
34+
/***********************************************************************
35+
* This work is licensed under the Creative Commons Attribution 4.0 *
36+
* International License. To view a copy of this license, *
37+
* visit http://creativecommons.org/licenses/by/4.0/ *
38+
* or send a letter to *
39+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
40+
***********************************************************************/
41+

Diff for: ‎DecisionLoopTest03.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Example of a decision with if/else
3+
*
4+
* @author Ken Fogel
5+
*/
6+
public class DecisionLoopTest03 {
7+
8+
/**
9+
* This method is where the program begins doing useful work. You can name it anything
10+
* you want but by convention it should be a verb.
11+
*/
12+
public void perform() {
13+
14+
int x = 4;
15+
int y = 6;
16+
if (x==y) {
17+
System.out.println(x + " and " + y + " are the equal");
18+
} else {
19+
System.out.println(x + " and " + y + " are not equal");
20+
}
21+
System.out.println("After the if");
22+
}
23+
24+
/**
25+
* Where the program begins
26+
*
27+
* @param args Command line arguments, not used in this program
28+
*/
29+
public static void main(String[] args) {
30+
var decisionLoopTest03 = new DecisionLoopTest03();
31+
decisionLoopTest03.perform();
32+
}
33+
}
34+
35+
/***********************************************************************
36+
* This work is licensed under the Creative Commons Attribution 4.0 *
37+
* International License. To view a copy of this license, *
38+
* visit http://creativecommons.org/licenses/by/4.0/ *
39+
* or send a letter to *
40+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
41+
***********************************************************************/
42+

Diff for: ‎EnerGuide.java

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Declare primitive variables and strings to represent the EnerGuide data and assign
3+
* the values. Display the variables after the assignment.
4+
*
5+
* @author Ken Fogel
6+
*/
7+
public class Energuide {
8+
9+
/**
10+
* This method is where the program begins doing useful work. You can name it anything
11+
* you want but by convention it should be a verb.
12+
*/
13+
public void perform() {
14+
double averageAnnualOperatingCost = 70.0;
15+
double lowAverageCost = 10.0;
16+
double highAverageCost = 100.0;
17+
double utilityRate = 0.1;
18+
int hoursOfViewing = 5;
19+
int screenSize = 42;
20+
String screenResolution = "HDTV: 720p";
21+
String brand = "Nom";
22+
String displayType = "Plasma";
23+
String modelName = "XxXxxXx";
24+
int annualEnergyConsumption = 500;
25+
boolean energyStar = true;
26+
27+
System.out.println("Average Annual Operating Cost: " + averageAnnualOperatingCost);
28+
System.out.println("Low Average Cost: " + lowAverageCost);
29+
System.out.println("High Average Cost: " + highAverageCost);
30+
System.out.println("Utility Rate: " + utilityRate);
31+
System.out.println("Hours Of Viewing: " + hoursOfViewing);
32+
System.out.println("Screen Size: " + screenSize);
33+
System.out.println("Screen Resolution: " + screenResolution);
34+
System.out.println("Brand: " + brand);
35+
System.out.println("Display Type: " + displayType);
36+
System.out.println("Model Name: " + modelName);
37+
System.out.println("Annual Energy Consumption: " + annualEnergyConsumption);
38+
System.out.println("EnergyStar: " + energyStar);
39+
}
40+
41+
/**
42+
* Where the program begins
43+
*
44+
* @param args Command line arguments, not used in this program
45+
*/
46+
public static void main(String[] args) {
47+
var energuide = new Energuide();
48+
energuide.perform();
49+
}
50+
}
51+
52+
/***********************************************************************
53+
* This work is licensed under the Creative Commons Attribution 4.0 *
54+
* International License. To view a copy of this license, *
55+
* visit http://creativecommons.org/licenses/by/4.0/ *
56+
* or send a letter to *
57+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. *
58+
***********************************************************************/

0 commit comments

Comments
 (0)
Please sign in to comment.