├── .gitignore ├── Lecture Handouts ├── Advanced_Programming_All_Lectures.pdf ├── Course_Introduction.pdf ├── Lecture_01.pdf ├── Lecture_02.pdf ├── Lecture_03.pdf ├── Lecture_04.pdf ├── Lecture_05.pdf ├── Lecture_06.pdf ├── Lecture_07.pdf ├── Lecture_08.pdf ├── Lecture_09.pdf └── Lecture_10.pdf ├── README.md ├── Section A └── CPW │ ├── Item.java │ ├── ItemDemo.java │ ├── StackDemo.java │ ├── User.java │ ├── UserManager.java │ ├── datastructure │ └── collections │ │ ├── DynamicStack.java │ │ ├── FixedStack.java │ │ └── Stack.java │ ├── dbc │ └── MySqlDBApp.java │ ├── gui │ ├── DesktopApp.java │ └── guidemo.java │ ├── multithreading │ ├── UsersThreadDemo.java │ └── UsersThreadRunDemo.java │ ├── nw │ ├── Client.java │ └── Server.java │ └── security │ ├── Role.java │ └── UserRole.java └── Section B ├── CPW ├── StackDemo.java ├── collections │ ├── Employee.java │ └── EmployeeDemo.java ├── datastructure │ └── collections │ │ ├── DynamicStack.java │ │ ├── FixedStack.java │ │ └── Stack.java ├── dbc │ └── DbApp.java ├── gui │ └── DesktopDemo.java ├── guidemo.java ├── multithreading │ ├── DirThreadDemo.java │ └── MyThreadDemo.java └── nw │ ├── Client.java │ └── Server.java └── CS_B6 └── Code └── readme.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /Lecture Handouts/Advanced_Programming_All_Lectures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Advanced_Programming_All_Lectures.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Course_Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Course_Introduction.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_01.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_02.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_03.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_04.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_05.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_05.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_06.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_07.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_07.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_08.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_08.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_09.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_09.pdf -------------------------------------------------------------------------------- /Lecture Handouts/Lecture_10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaseeb/SS18_AdvancedProgramming/e90a46dd561f2f263a7629341af960082b8b6546/Lecture Handouts/Lecture_10.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SS18_AdvancedProgramming -------------------------------------------------------------------------------- /Section A/CPW/Item.java: -------------------------------------------------------------------------------- 1 | package collections; 2 | public class Item{ 3 | private static int lastid =1; 4 | private int id; 5 | private String name; 6 | private int instock; 7 | private double price; 8 | public Item(){ 9 | id = lastid++; 10 | } 11 | public Item(String name, int instock, double price){ 12 | id = lastid++; 13 | this.name = name; 14 | this.instock = instock; 15 | this.price = price; 16 | } 17 | public int getId(){ 18 | return id; 19 | } 20 | public void setName(String name){ 21 | this.name = name; 22 | } 23 | public String getName(){ 24 | return name; 25 | } 26 | 27 | public void setStock(int newstock){ 28 | this.instock = newstock; 29 | } 30 | public int getStock(){ 31 | return instock; 32 | } 33 | public void setPrice(double newprice){ 34 | this.price = newprice; 35 | } 36 | public double getPrice(){ 37 | return price; 38 | } 39 | } -------------------------------------------------------------------------------- /Section A/CPW/ItemDemo.java: -------------------------------------------------------------------------------- 1 | import java.util.Map; 2 | import java.util.HashMap; 3 | import collections.Item; 4 | import java.util.Optional; 5 | import java.util.Scanner; 6 | public class ItemDemo{ 7 | public static void main(String args[]){ 8 | Map items = new HashMap(); 9 | for(int i = 1; i<4; i++ ){ 10 | Item item = new Item("Item "+i, i*2, 3.2*i); 11 | items.put(item.getId(),item); 12 | } 13 | Scanner scaner = new Scanner(System.in); 14 | int choice=1; 15 | System.out.println("Enter 1 for search by ID and 2 by Name"); 16 | choice = scaner.nextInt(); 17 | Item item=null; 18 | switch(choice){ 19 | case 1: 20 | System.out.println("Enter id to search"); 21 | int id = scaner.nextInt(); 22 | item = items.get(id); 23 | break; 24 | case 2: 25 | System.out.println("Enter name to search"); 26 | scaner.nextLine(); 27 | String name= scaner.nextLine(); 28 | Optional titem = items.values().stream().filter(i -> i.getName().equals(name)).findFirst(); 29 | item = titem.orElse(null); 30 | break; 31 | } 32 | if(item!=null){ 33 | System.out.println("Item found info: ID- "+item.getId() + " \t Name:"+item.getName()+ "\t Stock:"+item.getStock()+"\t Price:"+item.getPrice()); 34 | }else{ 35 | System.out.println("Item not found"); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Section A/CPW/StackDemo.java: -------------------------------------------------------------------------------- 1 | import datastructure.collections.*; 2 | public class StackDemo{ 3 | public static void main(String[] args){ 4 | Stack stk; 5 | FixedStack fstk = new FixedStack(5); 6 | stk = fstk; 7 | for(int i=0; i<7; i++){ 8 | stk.push(i+1); 9 | } 10 | for(int i=0; i<7;i++){ 11 | System.out.println("Value poped from Fixed Stack: "+stk.pop()); 12 | } 13 | DynamicStack dstk = new DynamicStack(5); 14 | stk = dstk; 15 | for(int i=0; i<7; i++){ 16 | stk.push(i+1); 17 | } 18 | for(int i=0; i<7;i++){ 19 | System.out.println("Value poped from Fixed Stack: "+stk.pop()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Section A/CPW/User.java: -------------------------------------------------------------------------------- 1 | package security; 2 | public class User{ 3 | private static int max=0; 4 | private int id; 5 | public String username; 6 | public String password; 7 | public User(String username, String password){ 8 | id = ++max; 9 | this.username = username; 10 | this.password = password; 11 | } 12 | public boolean equals(String username){ 13 | return this.username == username; 14 | } 15 | public boolean equals(User user){ 16 | return this.username == user.username; 17 | } 18 | public int getId(){ 19 | return id; 20 | } 21 | } -------------------------------------------------------------------------------- /Section A/CPW/UserManager.java: -------------------------------------------------------------------------------- 1 | package security; 2 | import java.util.Map; 3 | 4 | import java.util.Optional; 5 | import security.User; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.ArrayList; 10 | public class UserManager{ 11 | private static final Map users= new HashMap(); 12 | private static final Map roles = new HashMap(); 13 | private static final Map logedinuser = new HashMap(); 14 | private static final List usersroles = new ArrayList(); 15 | public UserManager(){ 16 | User user1=new User("ahmad","123456"); 17 | users.put(user1.getId(),user1); 18 | Role role1 = new Role("Admin"); 19 | roles.put(role1.getID(),role1); 20 | usersroles.add(new UserRole(user1,role1)); 21 | } 22 | public boolean register(String username, String password){ 23 | //boolean existslmbda = users.values().stream().anyMatch(u-> u.username == username); 24 | boolean exists = false; 25 | for(User user:users.values()){ 26 | if(user.equals(username)){ 27 | exists =true; 28 | break; 29 | } 30 | } 31 | if(exists){ 32 | return false; 33 | }else{ 34 | User user=new User(username,password); 35 | users.put(user.getId(),user); 36 | return true; 37 | } 38 | } 39 | public boolean login(String username, String password){ 40 | boolean loggedin = false; 41 | for(User user: logedinuser.values()){ 42 | if(user.equals(username)){ 43 | loggedin = true; 44 | break; 45 | } 46 | } 47 | if(!loggedin){ 48 | Optional user = users.values().stream().filter(u-> u.username==username && u.password == password).findFirst(); 49 | User usr = user.orElse(null); 50 | if(usr!=null){ 51 | logedinuser.put(usr.getId(),usr); 52 | loggedin = true; 53 | } 54 | } 55 | return loggedin; 56 | } 57 | } -------------------------------------------------------------------------------- /Section A/CPW/datastructure/collections/DynamicStack.java: -------------------------------------------------------------------------------- 1 | package datastructure.collections; 2 | public class DynamicStack extends Items implements Stack{ 3 | private int top=-1; 4 | public DynamicStack(int size){ 5 | super(size); 6 | } 7 | public void push(int item){ 8 | if(top == items.length-1){ 9 | int[] temp = new int[items.length+5]; 10 | for(int i=0; i employees = new HashMap(); 9 | 10 | for(int i=0; i<3; i++){ 11 | Employee emp = new Employee("emp "+(i+1),"position "+(i+1)); 12 | employees.put(emp.getId(), emp); 13 | } 14 | Scanner scan = new Scanner(System.in); 15 | int choice = 1; 16 | System.out.println("Enter 1 to search by id, Enter 2 to search by name"); 17 | choice = scan.nextInt(); 18 | switch(choice){ 19 | case 1: 20 | System.out.println("Enter id of the employee to search for "); 21 | Integer id = scan.nextInt(); 22 | Employee emp = employees.get(id); 23 | if(emp!=null){ 24 | System.out.println("Target employee info: Id "+emp.getId() + "\t Name "+emp.getName()+ "\t Position "+ emp.getPosition()); 25 | }else{ 26 | System.out.println("Employee not found"); 27 | } 28 | break; 29 | case 2: 30 | System.out.println("Enter name of the employee to search for "); 31 | scan.nextLine(); 32 | String name = scan.nextLine(); 33 | Optional employee = employees.values().stream().filter(e -> e.getName().equals(name)).findFirst(); 34 | emp = employee.orElse(null); 35 | if(emp!=null){ 36 | System.out.println("Target employee info: Id "+emp.getId() + "\t Name "+emp.getName()+ "\t Position "+ emp.getPosition()); 37 | }else{ 38 | System.out.println("Employee not found"); 39 | } 40 | break; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Section B/CPW/datastructure/collections/DynamicStack.java: -------------------------------------------------------------------------------- 1 | package datastructure.collections; 2 | public class DynamicStack implements Stack{ 3 | int[] items; 4 | int top =-1; 5 | public DynamicStack(int size){ 6 | items = new int[size]; 7 | } 8 | public void push(int item){ 9 | if(top == items.length-1){ 10 | int[] temp = new int[items.length+5]; 11 | for (int x=0; x