Note:
I did two of them without ChatGPT fire emoji
Hack 1: (0.25)
Create a void method that takes an integer input and adds it to an ArrayList. Then, add a non-void method that is able to call a certain index from the ArrayList.
public static class IntegerArray {
// length of 10 set
public static int[] arrayList = new int[10];
public static int start = 0;
// all values set to 0 by default, index from starting position to find zeroes
public static void push(int num) {
for (int i = start; i < arrayList.length; i ++) {
// first auto-generated zero overwritten with num
if (arrayList[i] == 0) {
arrayList[i] = num;
// add to start to prevent overwritting old values
start = i;
break;
};
};
}
// bruh
public static int index(int i) {
return arrayList[i];
}
}
IntegerArray test = new IntegerArray();
// add 5 and 10, then print indexes 0 and 1
test.push(5);
test.push(10);
System.out.println(test.index(0));
System.out.println(test.index(1));
// this is some of the worst code ive written god i hate java
5
10
Hack 2: (0.25)
Create a simple guessing game with random numbers in math, except the random number is taken to a random exponent (also includes roots), and the person has to find out what the root and exponent is (with hints!). Use at least one static and one non-static method in your class.
// "Each team will give a 10 minute lesson and assign **30 minutes** of homework to introduce their unit."
Hack 3: (0.25)
Create a class of your choosing that has multiple parameters of different types (int, boolean, String, double) and put 5 data values in that list. Show that you can access the information by givng some samples.
// literally what is this question even asking
Hack 4: (0.25)
Using your preliminary knowlege of loops, use a for loop to iterate through a person’s first and last name, seperated by a space, and create methods to call a person’s first name and a person’s last name by iterating through the string.
public static class Name {
public String first(String name) {
int i = name.indexOf(" ");
return name.substring(0, i);
}
public String last(String name) {
int i = name.indexOf(" ");
return name.substring(i + 1);
}
}
Name test = new Name();
System.out.println(test.first("aiden huynh"));
System.out.println(test.last("aiden huynh"));
aiden
huynh