├── README ├── .gitattributes ├── BankApp ├── src │ └── main │ │ └── java │ │ └── org │ │ └── example │ │ ├── Enum │ │ ├── Role.java │ │ └── TransactionType.java │ │ ├── Services │ │ └── TransactionService.java │ │ ├── Main.java │ │ ├── Entity │ │ ├── Transaction.java │ │ ├── AccountDetails.java │ │ └── User.java │ │ └── ServiceImpl │ │ └── transactionServiceImpl.java └── pom.xml ├── Fifo and priorityQueue optimization ├── src │ └── main │ │ └── java │ │ └── org │ │ └── example │ │ ├── Sales.java │ │ ├── productOrder │ │ └── ProducList.csv │ │ ├── Entities │ │ ├── Store.java │ │ ├── Customer.java │ │ ├── Main.java │ │ ├── ProductReader.java │ │ └── Product.java │ │ └── ServicesImpl │ │ ├── PriorQueue.java │ │ └── FIFOImpl.java ├── target │ └── classes │ │ └── org │ │ └── example │ │ ├── Sales.class │ │ ├── Entities │ │ ├── Main.class │ │ ├── Store.class │ │ ├── Product.class │ │ ├── Customer.class │ │ └── ProductReader.class │ │ └── ServicesImpl │ │ ├── FIFOImpl.class │ │ └── PriorQueue.class └── pom.xml ├── entities ├── service │ ├── PrincipalService.java │ └── Implementation │ │ └── PrincipalServiceImplementation.java ├── Principal.java ├── Main.java ├── Course.java ├── NonAcademicStaff.java ├── Teacher.java ├── Applicant.java ├── Staff.java └── Student.java ├── OperatorChallenge.java └── MethodChallenge.java /README: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Enum/Role.java: -------------------------------------------------------------------------------- 1 | package org.example.Enum; 2 | 3 | public enum Role { 4 | CUSTOMER, CASHIER 5 | } 6 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Enum/TransactionType.java: -------------------------------------------------------------------------------- 1 | package org.example.Enum; 2 | 3 | public enum TransactionType { 4 | WITHDRAW, DEPOSIT 5 | } 6 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Sales.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | public interface Sales { 4 | void attendToCustomer(); 5 | } 6 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Sales.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Sales.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Entities/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Entities/Main.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Entities/Store.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Entities/Store.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Entities/Product.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Entities/Product.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Entities/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Entities/Customer.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/ServicesImpl/FIFOImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/ServicesImpl/FIFOImpl.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/Entities/ProductReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/Entities/ProductReader.class -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/target/classes/org/example/ServicesImpl/PriorQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamuelOlawuyi/Class-1/HEAD/Fifo and priorityQueue optimization/target/classes/org/example/ServicesImpl/PriorQueue.class -------------------------------------------------------------------------------- /entities/service/PrincipalService.java: -------------------------------------------------------------------------------- 1 | package org.example.entities.service; 2 | 3 | import org.example.entities.Applicant; 4 | import org.example.entities.Principal; 5 | 6 | public interface PrincipalService { 7 | public String admitApplicant(Principal principal, Applicant applicant); 8 | } 9 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/productOrder/ProducList.csv: -------------------------------------------------------------------------------- 1 | Unit,Description,Unit Price ($),Amount ($) 2 | 150,White - Men's S/S Crew Tee - Small,3.5,525 3 | 200,White - Men's S/S Crew Tee - Medium,3.75,750 4 | 100,White - Men's S/S Crew Tee - Large,4,400 5 | 150,Charcoal - Men's S/S Crew Tee - Small,3.5,525 6 | 200,Charcoal - Men's S/S Crew Tee - Medium,3.75,750 7 | 100,Charcoal - Men's S/S Crew Tee - Large,4,400 8 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Services/TransactionService.java: -------------------------------------------------------------------------------- 1 | package org.example.Services; 2 | 3 | import org.example.Entity.Transaction; 4 | import org.example.Entity.User; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public interface TransactionService { 9 | 10 | Transaction depositFunds (User cashier, User customer, BigDecimal cashDeposit); 11 | BigDecimal withdrawFunds (User cashier, User customer, BigDecimal expectedCash); 12 | } 13 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Entities/Store.java: -------------------------------------------------------------------------------- 1 | package org.example.Entities; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class Store { 9 | public static List products = new ArrayList<>(); 10 | public static Map availableUnit = new HashMap<>(); 11 | public static List customersList = new ArrayList<>(); 12 | } 13 | -------------------------------------------------------------------------------- /entities/service/Implementation/PrincipalServiceImplementation.java: -------------------------------------------------------------------------------- 1 | package org.example.entities.service.Implementation; 2 | 3 | import org.example.entities.Applicant; 4 | import org.example.entities.Principal; 5 | import org.example.entities.service.PrincipalService; 6 | 7 | public class PrincipalServiceImplementation implements PrincipalService { 8 | 9 | @Override 10 | public String admitApplicant(Principal principal, Applicant applicant) { 11 | if(applicant.getAge() >= 15 ){ 12 | return "Hello" + applicant.getName() + "you're admitted"; 13 | } 14 | return "you are not admited"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BankApp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | BankApp 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 20 13 | 20 14 | UTF-8 15 | 16 | 17 | -------------------------------------------------------------------------------- /entities/Principal.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | public class Principal extends Staff { 4 | 5 | private int principalId; 6 | 7 | public Principal(String name, String qualification, double salary, int principalId) { 8 | super(name, qualification,salary); 9 | this.principalId = principalId; 10 | } 11 | 12 | public int getPrincipalId(){ 13 | return principalId; 14 | } 15 | 16 | public void setPrincipalId(int principalId) { 17 | this.principalId = principalId; 18 | } 19 | 20 | @Override 21 | public String toString(){ 22 | return "Principal{" + 23 | "principalId=" + principalId + 24 | "}"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | TaskWeekThreeNew 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 20 13 | 20 14 | UTF-8 15 | 16 | 17 | -------------------------------------------------------------------------------- /entities/Main.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | import org.example.entities.Applicant; 4 | 5 | import org.example.entities.service.Implementation.PrincipalServiceImplementation; 6 | 7 | // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, 8 | // then press Enter. You can now see whitespace characters in your code. 9 | public class Main { 10 | public static void main(String[] args) { 11 | Principal principal = new Principal("John","BSCEng",100000,234); 12 | Applicant applicant = new Applicant(" Samuel ",18,250); 13 | PrincipalServiceImplementation principalServiceImplementation = new PrincipalServiceImplementation(); 14 | String admit = principalServiceImplementation.admitApplicant(principal,applicant); 15 | 16 | System.out.println(admit); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /OperatorChallenge.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.w3c.dom.ls.LSOutput; 4 | 5 | public class OperatorChallenge { 6 | public static void main(String[] args) { 7 | 8 | double firstVar = 20.00d; 9 | double secondVar = 80.00d; 10 | double thirdVar = firstVar + secondVar; 11 | double fourthVar = thirdVar * 100.00d; 12 | System.out.println("My values total is: " + fourthVar); 13 | double fifthVar = (fourthVar % 40.00d); 14 | System.out.println("The remainder = " + fifthVar); 15 | double sixthVar = fifthVar; 16 | boolean sevenVal = (sixthVar == 0.00) ? true : false; 17 | 18 | System.out.println("is no remainder: " + sevenVal); 19 | 20 | if (!sevenVal) { 21 | System.out.println("got some remainder"); 22 | } 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /entities/Course.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | public class Course { 4 | private String courseTitle; 5 | private int unit; 6 | 7 | public Course(String courseTitle, int unit){ 8 | this.courseTitle = courseTitle; 9 | this.unit = unit; 10 | } 11 | 12 | public String getCourseTitle() { 13 | return courseTitle; 14 | } 15 | 16 | public void setCourseTitle(String courseTitle) { 17 | this.courseTitle = courseTitle; 18 | } 19 | 20 | public int getUnit() { 21 | return unit; 22 | } 23 | 24 | public void setUnit(int unit) { 25 | this.unit = unit; 26 | } 27 | @Override 28 | public String toString() { 29 | return "Course{" + 30 | "courseTitle=" + courseTitle + '\'' + 31 | ", unit=" + unit + 32 | 33 | "}"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /entities/NonAcademicStaff.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | public class NonAcademicStaff extends Staff { 4 | private String role; 5 | private int workingHours; 6 | 7 | public NonAcademicStaff(String name, String qualification, double salary, String role, int workingHours){ 8 | super(name, qualification, salary); 9 | this.role = role; 10 | this.workingHours = workingHours; 11 | } 12 | 13 | 14 | public String getRole() { 15 | return role; 16 | } 17 | 18 | public void setRole(String role) { 19 | this.role = role; 20 | } 21 | 22 | public int getWorkingHours() { 23 | return workingHours; 24 | } 25 | 26 | @Override 27 | public String toString(){ 28 | return "NonAcademicStaff{" + 29 | "role=" + role + 30 | ", workingHours=" + workingHours + 31 | "}"; 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /entities/Teacher.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | import org.example.entities.Course; 4 | import org.example.entities.Staff; 5 | 6 | public class Teacher extends Staff { 7 | private int teacherId; 8 | private Course course; 9 | 10 | public Teacher(String name, String qualification, double salary, int teacherId, Course course){ 11 | super(name, qualification, salary); 12 | this.teacherId = teacherId; 13 | this.course = course; 14 | } 15 | 16 | public int getTeacherId(){ 17 | return teacherId; 18 | } 19 | 20 | public void setTeacherId(int teacherId){ 21 | this.teacherId = teacherId; 22 | } 23 | 24 | public Course getCourse(){ 25 | return course; 26 | } 27 | 28 | public void setCourse(Course course){ 29 | this.course = course; 30 | } 31 | 32 | @Override 33 | public String toString(){ 34 | return "Teacher{" + 35 | "teacherId=" + teacherId + 36 | ", course=" + course + 37 | "}"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /entities/Applicant.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | public class Applicant { 4 | private String name; 5 | private int age; 6 | private int score; 7 | 8 | public Applicant(String name, int age, int score) { 9 | this.name = name; 10 | this.age = age; 11 | this.score = score; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public int getAge() { 23 | return age; 24 | } 25 | 26 | public void setAge(int age) { 27 | this.age = age; 28 | } 29 | 30 | public int getScore() { 31 | return score; 32 | } 33 | 34 | public void setScore(int score) { 35 | this.score = score; 36 | } 37 | @Override 38 | public String toString(){ 39 | return "Applicant{" + 40 | "name='" + name + '\'' + 41 | ", ages" + age + 42 | ", scores" + score + 43 | "}"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Main.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.example.Entity.User; 4 | import org.example.Enum.Role; 5 | import org.example.ServiceImpl.transactionServiceImpl; 6 | import java.math.BigDecimal; 7 | 8 | // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, 9 | // then press Enter. You can now see whitespace characters in your code. 10 | public class Main { 11 | public static void main(String[] args) { 12 | User accessBankCustomer = new User(Role.CUSTOMER); 13 | User accessBankCashier = new User(Role.CASHIER); 14 | transactionServiceImpl transactionService = new transactionServiceImpl(); 15 | 16 | //User accessBankCustomer = new User(Role.CUSTOMER); 17 | //User accessBankCashier = new User(Role.CASHIER); 18 | //transactionServiceImpl transactionService = new transactionServiceImpl(); 19 | transactionService.depositFunds(accessBankCashier, accessBankCustomer, new BigDecimal()); 20 | transactionService.withdrawFunds(accessBankCashier, accessBankCustomer, new BigDecimal()); 21 | 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Entity/Transaction.java: -------------------------------------------------------------------------------- 1 | package org.example.Entity; 2 | 3 | import org.example.Enum.TransactionType; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class Transaction { 8 | private BigDecimal amount; 9 | private TransactionType transactionType; 10 | private User customer; 11 | private User cashier; 12 | 13 | public BigDecimal getAmount() { 14 | return amount; 15 | } 16 | 17 | public void setAmount(BigDecimal amount) { 18 | this.amount = amount; 19 | } 20 | 21 | public TransactionType getTransactionType() { 22 | return transactionType; 23 | } 24 | 25 | public void setTransactionType(TransactionType transactionType) { 26 | this.transactionType = transactionType; 27 | } 28 | 29 | public User getCustomer() { 30 | return customer; 31 | } 32 | 33 | public void setCustomer(User customer) { 34 | this.customer = customer; 35 | } 36 | 37 | public User getCashier() { 38 | return cashier; 39 | } 40 | 41 | public void setCashier(User cashier) { 42 | this.cashier = cashier; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/ServiceImpl/transactionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.ServiceImpl; 2 | 3 | import org.example.Entity.Transaction; 4 | import org.example.Entity.User; 5 | import org.example.Services.TransactionService; 6 | 7 | import java.math.BigDecimal; 8 | 9 | public class transactionServiceImpl implements TransactionService { 10 | @Override 11 | public Transaction depositFunds(User cashier, User customer, BigDecimal cashDeposit) { 12 | //check customer if they are our customer 13 | // check if withdrawal is within limit 14 | //deposit to account 15 | //update account details 16 | //create transaction object 17 | //storing transaction object 18 | //return transaction object 19 | return null; 20 | } 21 | 22 | @Override 23 | public BigDecimal withdrawFunds(User cashier, User customer, BigDecimal expectedCash) { 24 | //check customer if they exist in our system 25 | //check withdrawal limit against expecteCash 26 | //withdraw funds from account details 27 | //update accountDetails balance 28 | //return funds 29 | // 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Entity/AccountDetails.java: -------------------------------------------------------------------------------- 1 | package org.example.Entity; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | public class AccountDetails { 7 | private Long accountNumber; 8 | private BigDecimal balance; 9 | private List transactionHistory; //aggregation 10 | private User customer; //composition 11 | 12 | public Long getAccountNumber() { 13 | return accountNumber; 14 | } 15 | 16 | public void setAccountNumber(Long accountNumber) { 17 | this.accountNumber = accountNumber; 18 | } 19 | 20 | public BigDecimal getBalance() { 21 | return balance; 22 | } 23 | 24 | public void setBalance(BigDecimal balance) { 25 | this.balance = balance; 26 | } 27 | 28 | public List getTransactionHistory() { 29 | return transactionHistory; 30 | } 31 | 32 | public void setTransactionHistory(List transactionHistory) { 33 | this.transactionHistory = transactionHistory; 34 | } 35 | 36 | public User getCustomer() { 37 | return customer; 38 | } 39 | 40 | public void setCustomer(User customer) { 41 | this.customer = customer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Entities/Customer.java: -------------------------------------------------------------------------------- 1 | package org.example.Entities; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Customer { 7 | private String name; 8 | private List cart = new ArrayList<>(); 9 | 10 | public Customer(String olu) { 11 | 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public List getCart() { 23 | return cart; 24 | } 25 | 26 | public void setCart(List cart) { 27 | this.cart = cart; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | // return "Customer{" + 33 | // "name='" + name + '\'' + 34 | // ", cart=" + cart + 35 | // '}'; 36 | 37 | return "Customer name is " + name + " with cart " + cart; 38 | } 39 | 40 | public void selectItem(Product storeProduct, int noOfItem){ 41 | storeProduct.setUnit(noOfItem); 42 | storeProduct.setAmount(noOfItem * storeProduct.getUnitPrice()); 43 | cart.add(storeProduct); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/ServicesImpl/PriorQueue.java: -------------------------------------------------------------------------------- 1 | package org.example.ServicesImpl; 2 | 3 | import org.example.Entities.Customer; 4 | import org.example.Entities.Product; 5 | import org.example.Sales; 6 | 7 | import java.util.Collections; 8 | import java.util.PriorityQueue; 9 | import java.util.Queue; 10 | 11 | import static org.example.Entities.Store.customersList; 12 | 13 | public class PriorQueue implements Sales { 14 | public static Queue productQueue = new PriorityQueue<>(Collections.reverseOrder()); 15 | @Override 16 | public void attendToCustomer() { 17 | for (Customer x : customersList) { 18 | for (Product p : x.getCart()){ 19 | productQueue.offer(p); 20 | } 21 | } 22 | while (productQueue.peek() != null){ 23 | System.out.println(productQueue.poll()); 24 | } 25 | } 26 | // Task 4: Using Lambda expression 27 | // @Override 28 | // public void attendToCustomer(){ 29 | // customersList.forEach(customer -> {customer.getCart() 30 | // .forEach(product -> {productQueue.offer(product);} ); 31 | // }); 32 | // productQueue.stream().forEach(System.out::println); 33 | // } 34 | } 35 | -------------------------------------------------------------------------------- /entities/Staff.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | public abstract class Staff { 4 | private String name; 5 | private String qualification; 6 | private double salary; 7 | 8 | 9 | public Staff(String name, String qualification, double salary){ 10 | this.name = name; 11 | this.qualification = qualification; 12 | this.salary = salary; 13 | 14 | } 15 | 16 | public Staff(){ 17 | 18 | } 19 | 20 | public String getName(){ 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public String getQualification(){ 29 | return qualification; 30 | } 31 | 32 | public void setQualification(String qualification) { 33 | this.qualification = qualification; 34 | } 35 | 36 | public double getSalary() { 37 | return salary; 38 | } 39 | 40 | public void setSalary(double salary) { 41 | this.salary = salary; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Staff{" + 47 | "name='" + name + '\'' + 48 | ", qualification='" + qualification + '\'' + 49 | ", salary=" + salary + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /BankApp/src/main/java/org/example/Entity/User.java: -------------------------------------------------------------------------------- 1 | package org.example.Entity; 2 | 3 | import org.example.Enum.Role; 4 | 5 | public class User { 6 | private String name; 7 | private String email; 8 | 9 | public User(Role role) { 10 | this.role = role; 11 | } 12 | 13 | private Role role; 14 | private String dob; 15 | private String location; 16 | 17 | private int age; 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getEmail() { 28 | return email; 29 | } 30 | 31 | public void setEmail(String email) { 32 | this.email = email; 33 | } 34 | 35 | public String getDob() { 36 | return dob; 37 | } 38 | 39 | public void setDob(String dob) { 40 | this.dob = dob; 41 | } 42 | 43 | public String getLocation() { 44 | return location; 45 | } 46 | 47 | public void setLocation(String location) { 48 | this.location = location; 49 | } 50 | 51 | public int getAge() { 52 | return age; 53 | } 54 | 55 | public void setAge(int age) { 56 | if (age < 18) { 57 | System.out.println("You are too young to join my bank"); 58 | } else { 59 | this.age = age; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Entities/Main.java: -------------------------------------------------------------------------------- 1 | package org.example.Entities; 2 | 3 | import org.example.ServicesImpl.FIFOImpl; 4 | import org.example.ServicesImpl.PriorQueue; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.example.Entities.Store.*; 9 | 10 | // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, 11 | // then press Enter. You can now see whitespace characters in your code. 12 | public class Main { 13 | public static void main(String[] args) throws IOException { 14 | new ProductReader(); 15 | System.out.println(products); 16 | Customer customer1 = new Customer("Olu"); 17 | customer1.selectItem(products.get(3), 3); 18 | customersList.add(customer1); 19 | 20 | Customer customer2 = new Customer("Tolu"); 21 | customer2.selectItem(products.get(2), 2); 22 | customersList.add(customer2); 23 | 24 | Customer customer3 = new Customer("Bolu"); 25 | customer3.selectItem(products.get(4), 7); 26 | customersList.add(customer3); 27 | 28 | FIFOImpl fifo = new FIFOImpl(); 29 | fifo.attendToCustomer(); 30 | System.out.println(availableUnit); 31 | 32 | PriorQueue priorQueue = new PriorQueue(); 33 | priorQueue.attendToCustomer(); 34 | System.out.println(availableUnit); 35 | } 36 | } -------------------------------------------------------------------------------- /entities/Student.java: -------------------------------------------------------------------------------- 1 | package org.example.entities; 2 | 3 | import org.example.entities.Course; 4 | 5 | public class Student { 6 | private String name; 7 | private String schoolFees; 8 | private Course course; 9 | 10 | static boolean FeePayment = false; 11 | public Student(String name, String schoolFees, Course course){ 12 | this.name = name; 13 | this.schoolFees = schoolFees; 14 | this.course = course; 15 | } 16 | 17 | public String getName(){ 18 | return name; 19 | } 20 | 21 | public void setName(String name){ 22 | this.name = name; 23 | } 24 | 25 | public String isSchoolFees(){ 26 | return schoolFees; 27 | } 28 | 29 | // public void setSchoolFees(boolean schoolFees) { 30 | // this.schoolFees = schoolFees; 31 | // } 32 | public void SchoolFeeConfirmationPaid(){ 33 | FeePayment = true; 34 | } 35 | 36 | public Course getCourse() { 37 | return course; 38 | } 39 | 40 | public void setCourse(Course course) { 41 | this.course = course; 42 | } 43 | @Override 44 | public String toString() { 45 | return "Student{" + 46 | "name=" + name + 47 | ", schoolFees=" + schoolFees + 48 | ", course=" + course + 49 | "}"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Entities/ProductReader.java: -------------------------------------------------------------------------------- 1 | package org.example.Entities; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | import static org.example.Entities.Store.availableUnit; 8 | import static org.example.Entities.Store.products; 9 | 10 | public class ProductReader { 11 | public ProductReader() throws IOException { 12 | String fileName = "C:\\Users\\olasa\\IdeaProjects\\TaskWeekThreeNew\\src\\main\\java\\org\\example\\productOrder\\ProducList.csv"; 13 | try(BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName))){ 14 | String line; 15 | while((line = bufferedReader.readLine()) !=null){ 16 | String commaAdder[] = line.split(","); 17 | if (commaAdder[0].contains("Unit"))continue; 18 | 19 | //System.out.println(Arrays.toString(commaAdder)); 20 | 21 | Product product = new Product(); 22 | product.setDescription(commaAdder[1]); 23 | product.setUnitPrice(Double.parseDouble(commaAdder[2])); 24 | product.setAmount(Double.parseDouble(commaAdder[3])); 25 | products.add(product); 26 | availableUnit.put(commaAdder[1], Integer.valueOf(commaAdder[0])); 27 | 28 | } 29 | } 30 | } 31 | 32 | public static void main(String[] args) throws IOException { 33 | System.out.println(new ProductReader()); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /MethodChallenge.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | public class MethodChallenge { 4 | public static void main(String[] args) { 5 | 6 | int highScorePosition = calculateHighScorePosition(1500); 7 | displayHighScoreposition("Tim", highScorePosition); 8 | 9 | highScorePosition = calculateHighScorePosition(1000); 10 | displayHighScoreposition("Bob", highScorePosition); 11 | 12 | highScorePosition = calculateHighScorePosition(500); 13 | displayHighScoreposition("percy", highScorePosition); 14 | 15 | highScorePosition = calculateHighScorePosition(100); 16 | displayHighScoreposition("james", highScorePosition); 17 | 18 | highScorePosition = calculateHighScorePosition(25); 19 | displayHighScoreposition("Timmy", highScorePosition); 20 | 21 | 22 | // String playerName = "Tim"; 23 | // String playerPosition = "Second"; 24 | // String message; 25 | // 26 | // System.out.println(playerName + " managed to get into position " + playerPosition + " on the high score list"); 27 | } 28 | public static void displayHighScoreposition(String playerName, int highScorePosition){ 29 | System.out.println(playerName + " managed to get into position " + 30 | highScorePosition + " on the high score list"); 31 | } 32 | 33 | public static int calculateHighScorePosition (int playerScore){ 34 | 35 | //int playerScore = 1000; 36 | int position = 4; 37 | 38 | if(playerScore >= 1000){ 39 | position = 1; 40 | } else if((playerScore >= 500)){ 41 | position = 2; 42 | }else if((playerScore >= 100)){ 43 | position = 3; 44 | } 45 | return position; 46 | } 47 | 48 | // return calculateHighScorePosition(700); 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/ServicesImpl/FIFOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.ServicesImpl; 2 | 3 | import org.example.Entities.Customer; 4 | import org.example.Entities.Product; 5 | import org.example.Entities.ProductReader; 6 | import org.example.Sales; 7 | 8 | import java.util.LinkedList; 9 | import java.util.Queue; 10 | //import org.example.Entities.Store 11 | 12 | import static org.example.Entities.Store.availableUnit; 13 | import static org.example.Entities.Store.customersList; 14 | 15 | public class FIFOImpl implements Sales { 16 | public static Queue fifoQueue = new LinkedList<>(); 17 | 18 | // @Override 19 | // public void attendToCustomer() { 20 | // for (Customer customer : customersList) { 21 | // for (Product i : customer.getCart()) { 22 | // int remainingUnit = availableUnit.get(i.getDescription()) - i.getUnit(); 23 | // availableUnit.replace(i.getDescription(), remainingUnit); 24 | // } 25 | // fifoQueue.offer(customer); 26 | // 27 | // } 28 | // while (fifoQueue.peek() != null) { 29 | // System.out.println(fifoQueue.poll()); 30 | // } 31 | // } 32 | 33 | // Tasks 4: Using Lambda expression 34 | @Override 35 | public void attendToCustomer() { 36 | customersList.forEach(customer -> { 37 | customer 38 | .getCart().forEach(product -> { 39 | int remainingUnit = availableUnit.get(product.getDescription()) - product.getUnit(); 40 | availableUnit.replace(product.getDescription(), remainingUnit); 41 | }); 42 | fifoQueue.offer(customer); 43 | }); 44 | fifoQueue.stream().forEach(System.out::println); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Fifo and priorityQueue optimization/src/main/java/org/example/Entities/Product.java: -------------------------------------------------------------------------------- 1 | package org.example.Entities; 2 | 3 | public class Product implements Comparable{ 4 | private int unit; 5 | private String description; 6 | private double unitPrice; 7 | private double amount; 8 | 9 | // public Product(int Unit, String description, double unitPrice, double amount){ 10 | // this.unit = unit; 11 | // this.description = description; 12 | // this.unitPrice = unitPrice; 13 | // this.amount = amount; 14 | // } 15 | 16 | public int getUnit() { 17 | return unit; 18 | } 19 | 20 | public void setUnit(int unit) { 21 | this.unit = unit; 22 | } 23 | 24 | public String getDescription() { 25 | return description; 26 | } 27 | 28 | public void setDescription(String description) { 29 | this.description = description; 30 | } 31 | 32 | public double getUnitPrice() { 33 | return unitPrice; 34 | } 35 | 36 | public void setUnitPrice(double unitPrice) { 37 | this.unitPrice = unitPrice; 38 | } 39 | 40 | public double getAmount() { 41 | return amount; 42 | } 43 | 44 | public void setAmount(double amount) { 45 | this.amount = amount; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | // return "Product{" + 51 | // "unit=" + unit + 52 | // ", description='" + description + '\'' + 53 | // ", unitPrice=" + unitPrice + 54 | // ", amount=" + amount + 55 | // '}'; 56 | return "Unit: " + unit + "\n description: " + description + "\n unitprice: " + unitPrice + " \n amount: " + amount + "\n\n"; 57 | } 58 | 59 | @Override 60 | public int compareTo(Product o) { 61 | return Integer.compare(this.unit,o.unit); 62 | } 63 | } 64 | --------------------------------------------------------------------------------