package org.example; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Properties; public class Main { // Class public static void main(String[] args) { // MAIN Object MyBasics myB = new MyBasics(); // myB local prop myB.myIfElse(); // for loop String[] localNames = myB.contactNames(); // ["Bob Smith", "Mary Jones", "Joe Doe"] //Print for (String name : localNames) { // for ( x in: ys ) // x local var of the loop {} // ys dataset //// 1. local static variable Class localNames //// 2. Object passed myB.contactNames() System.out.println(name); } // end for loop // Execute a class object SumCalculator sumCalculator = new SumCalculator(); int number = 7; // 28 int result = sumCalculator.sum(number); System.out.println("Result: " + result); // 28 // Override Methods Persons persons = new Persons(); Student student = new Student(); // only student members Teacher teacher = new Teacher(); // call method persons.typeofPerson(); student.typeofPerson(); teacher.typeofPerson(); // Polymorphism Persons persons1 = new Student(); // Persons 7 > Student 2 new 1 or end up with 9 members persons1.typeofPerson(); // student // execute Interface Contact contact = new EmailContact("philipm@onlc.com"); contact.displayContactInfo(); // interface // Collections Chapter 4 String[] orders = new String[2]; // specific length // Assign Values to that Array orders[0] = "Order 1234"; orders[1] = "Order 3456"; System.out.println(orders[0]); ArrayList orders1 = new ArrayList<>(); // variable length // elements // [] orders1.add("Bob"); // ["Bob"] orders1.add("Joe"); // ["Bob","Joe"] System.out.println(orders1.get(0)); System.out.println("---------"); orders1.add("Mary"); // ["Bob","Joe","Mary"] // enhansed for each loop for (String x: orders1) { System.out.println(x); } System.out.println("Now Remove Joe"); // 1 orders1.remove(1); // enhansed for each loop for (String x: orders1) { System.out.println(x); } // Dictionary TreeMap HashMap // HashMap Map groceryCart = new HashMap<>(); groceryCart.put("Apples",5); groceryCart.put("Bananas", 2); // 2 groceryCart.put("Apples", 3); // 2 replace qty 3 System.out.println(groceryCart); groceryCart.remove("Apples"); System.out.println("---------"); System.out.println(groceryCart); groceryCart.put("Apples", 9); groceryCart.put("Oranges", 5); // enhansed for each loop for (Map.Entry x: groceryCart.entrySet()) { String itemName = x.getKey(); int itemQuantity = x.getValue(); System.out.println("Item: " + itemName + " Quantity: " + itemQuantity); } //for // Properties Class Chapter 8 Properties properties = new Properties(); try { String filePath = "C:\\Users\\Student\\IdeaProjects\\JavaCustom2\\src\\main\\resources\\config.properties"; FileInputStream fileInputStream = new FileInputStream(filePath); properties.load(fileInputStream); fileInputStream.close(); // Get a property value String username = properties.getProperty("username"); System.out.println(("Username: " + username)); // not set // Set a username // !config.properties properties.setProperty("username", "philm"); // Get a property value String username1 = properties.getProperty("username"); System.out.println(("Username: " + username1)); // philm // Write properties back to the config file FileOutputStream fileOutputStream = new FileOutputStream(filePath); properties.store(fileOutputStream, null); } // try catch (Exception e) { e.printStackTrace(); } // catch } // main } // Main