Hugging Face
Models
Datasets
Spaces
Buckets
new
Docs
Enterprise
Pricing
Log In
Sign Up
Spaces:
KaiquanMah
/
TurkuBasicOOPinJava
like
0
Running
App
Files
Files
Community
main
TurkuBasicOOPinJava
/
Week 3: Objects, files and exceptions
71.8 kB
Ctrl+K
Ctrl+K
1 contributor
History:
38 commits
KaiquanMah
System.out.println("<menu item i>");
37afcbe
verified
10 months ago
10. Array from list
Safe
2.2 kB
Create 10. Array from list
10 months ago
11a Hashmap
Safe
3.07 kB
HashMap<String, Integer>; put get containsKey keySet(=k ONLY)
10 months ago
11b. Combine names and grades
Safe
2.21 kB
HashMap<String, Integer> map = new HashMap<>();
10 months ago
12. Coldest city
Safe
2.68 kB
for (String city : cityNTemps.keySet())
10 months ago
13a. Using existing libraries
Safe
537 Bytes
Random.nextInt(upToButNotIncl)
10 months ago
13b. Draw lottery numbers
Safe
2.74 kB
r.nextInt(39)
10 months ago
14a Class StringBuilder
Safe
1.96 kB
StringBuilder str = new StringBuilder("<urStr>");
10 months ago
14b Starsquare
Safe
1.61 kB
Create 14b Starsquare
10 months ago
15a Math-library
Safe
558 Bytes
Math.PI; Math.pow
10 months ago
15b. Math-class methods
Safe
378 Bytes
abs exp log floor max signum negateExact
10 months ago
16a Files and exceptions
Safe
876 Bytes
Create 16a Files and exceptions
10 months ago
16b. Players from FILE
Safe
2.07 kB
Scanner reader = new Scanner(new File("fileName.txt")); list.add(reader.nextLine());
10 months ago
17a Handling file contents
Safe
2.27 kB
String row = reader.nextLine(); String[] chunks = row.split(","); Integer.valueOf(chunk);
10 months ago
17b. Read numbers from a file
Safe
2.36 kB
Create 17b. Read numbers from a file
10 months ago
18a 3 Types Exceptions, TRY-CATCH, throws FileNotFoundException
Safe
3.58 kB
Create 18a 3 Types Exceptions, TRY-CATCH, throws FileNotFoundException
10 months ago
18b. Add numbers to list 2
Safe
2.05 kB
Create 18b. Add numbers to list 2
10 months ago
19. Phone book 1: Adding a number
Safe
2.17 kB
public static void addNumber(HashMap<String,String> numbers)
10 months ago
1a Objects and references
Safe
3.46 kB
obj1.equals(obj2)
10 months ago
1b. Calculator
Safe
2.14 kB
Create 1b. Calculator
10 months ago
2. Names to list - equals
Safe
2.05 kB
equals
10 months ago
20. Phone book 2: Searching for a number
Safe
1.77 kB
containsKey get
10 months ago
21. Phone book 3: Listing numbers - Extract HASHMAP KEYS, then SORT
Safe
2.59 kB
String[] arrKeys = numbers.keySet().toArray(new String[0]); Arrays.sort(arrKeys);
10 months ago
22. Phone book 4: Menu
Safe
3.33 kB
System.out.println("<menu item i>");
10 months ago
3a. Objects as parameters and return values
Safe
679 Bytes
someMethod(ArrayList<Integer> list)
10 months ago
3b. Add sum to list - RECREATE LIST
Safe
2.15 kB
ArrayList<Integer> lista = new ArrayList<>(); for (int l : pa) lista.add(l);
10 months ago
4. Remove negative numbers - get, remove
Safe
2.49 kB
get, remove
10 months ago
5a. Method side effects
Safe
1.11 kB
eg change order
10 months ago
5b. Second smallest without side effects
Safe
2.2 kB
Collections.min/max, THEN go through list to find secondSmallest
10 months ago
6B. Create a list
Safe
2.04 kB
Create 6B. Create a list
10 months ago
6a. Objects as return values
Safe
1.8 kB
ArrayList<String> list = new ArrayList<>();
10 months ago
7. Convert to a number list
Safe
3.06 kB
"" + someInt; Integer.parseInt(str)
10 months ago
8. Combine lists
Safe
2.99 kB
newList.addAll(list1); Collections.sort(newList)
10 months ago
9a. Data structure - ARRAY
Safe
3.36 kB
String[] names = new String[16]; arr.length; list.size(); str.length();
10 months ago
9b. Sum of array elements
Safe
1.28 kB
Create 9b. Sum of array elements
10 months ago