-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
135 lines (113 loc) · 3.03 KB
/
Part1.java
File metadata and controls
135 lines (113 loc) · 3.03 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;
public class Part1 {
public static void main(String args[]) {
// #4
HashMap<Integer, String> leagueStudents = new HashMap<Integer, String>();
leagueStudents.put(1, "Rowan");
leagueStudents.put(0, "Alex");
leagueStudents.put(5, "Jeremiah");
leagueStudents.put(2, "Noah");
// #6
ArrayList<String> toppings = new ArrayList<String>();
toppings.add("bacon");
toppings.add("bell peppers");
toppings.add("Canadian bacon");
/*
* toppings.add("cheese"); toppings.add("Turkey bacon");
* toppings.add("pepperoni"); toppings.add("Antarctic bacon");
*/
// #7: Recursion is when a function calls itself.
// #9: The following code will output 1, then 2, then 3.
int[] nums = { 1, 2, 3, 4, 5, 6 };
for (int i = 0; i <= 2; i++) {
System.out.println(nums[i]);
}
// #10
Stack<String> locations = new Stack<String>();
locations.add("San Marcos");
locations.add("Margonsfield, California");
locations.add("Oceanside");
// #12
/*
* Robot[] robots = new Robot[]; for (Robot r : robots) { for (int i = 0; i < 3;
* i++) { r.move(50); r.turn(60); } }
*/
// #14
double[] cream = new double[] {0.0, 1.1, 2.2, 3.3};
// #15
// - Bubble Sort
// - Heap Sort
// - Quick Sort
// - Merge Sort
// - Insertion Sort I HAD TO LOOK THIS UP
// - Selection Sort I HAD TO LOOK THIS UP
// #16: An example of a subclass is:
// public class Cheetah extends Animal {
// Cheetah is the subclass and Animal is the superclass.
// #18
/**
* Searching Algorithm | Data Prerequisites
* Linear Algorithm | none
* Binary Algorithm | must be sorted
* Interpolation | must be sorted, evenly spaced HAD TO LOOK THIS UP
* Exponential | must be sorted HAD TO LOOK THIS UP
*/
// #19
int[] nums2 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i < nums2.length; i+=2) {
if (i < nums2.length-1) {
int x = nums2[i+1];
nums2[i+1] = nums2[i];
nums2[i] = x;
}
}
for (int i = 0; i < nums2.length; i++) {
System.out.println(nums2[i]);
}
/**
* #20
* DIFFERENCES BETWEEN ABSTRACT CLASSES AND INTERFACES:
* Interfaces only have abstract methods. LOOKED THIS ONE UP
* Instead of being extended must be implemented.
* SIMILARITIES IN ABSTRACT CLASSES AND INTERFACES:
* Both can hold abstract methods.
* Both cannot have instances.
*/
}
// #13
public static int[] sortInts(int[] nums) {
boolean unsorted = true;
while (unsorted) {
for (int i = 0; i < nums.length; i++) {
if (i > 0) {
if (nums[i] < nums[i - 1]) {
int x = nums[i - 1];
nums[i - 1] = nums[i];
nums[i] = x;
}
}
}
unsorted = false;
for (int i = 0; i < nums.length; i++) {
if (i > 0) {
if (nums[i] < nums[i - 1]) {
unsorted = true;
break;
}
}
}
}
return nums;
}
// #5
public static boolean contains(char[] list, char c) {
for (char c1 : list) {
if (c1 == c) {
return true;
}
}
return false;
}
}