diff --git a/Week 2 Assignment 1/Factorial_W2A1_3.class b/Week 2 Assignment 1/Factorial_W2A1_3.class new file mode 100644 index 0000000..d3ba8bf Binary files /dev/null and b/Week 2 Assignment 1/Factorial_W2A1_3.class differ diff --git a/Week 2 Assignment 1/Factorial_W2A1_3.java b/Week 2 Assignment 1/Factorial_W2A1_3.java new file mode 100644 index 0000000..51a4a39 --- /dev/null +++ b/Week 2 Assignment 1/Factorial_W2A1_3.java @@ -0,0 +1,15 @@ +public class Factorial_W2A1_3 { + static int product = 1; + public static void main(String args[]) { + int num = 4; + System.out.println(recursion(num)); + } + + static int recursion(int num) { + if(num > 0) { + product = product * num; + recursion(num - 1); + } + return product; + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/Fibonacci_W2A1_1.class b/Week 2 Assignment 1/Fibonacci_W2A1_1.class new file mode 100644 index 0000000..321640c Binary files /dev/null and b/Week 2 Assignment 1/Fibonacci_W2A1_1.class differ diff --git a/Week 2 Assignment 1/Fibonacci_W2A1_1.java b/Week 2 Assignment 1/Fibonacci_W2A1_1.java new file mode 100644 index 0000000..9e7b898 --- /dev/null +++ b/Week 2 Assignment 1/Fibonacci_W2A1_1.java @@ -0,0 +1,18 @@ +public class Fibonacci_W2A1_1 { + static int temp1 = 0, temp2 = 1, temp3 = 0; + public static void main(String arg[]) { + int num = 9; + System.out.print(temp1 + " " + temp2 + " "); + recursion(num); + } + + static void recursion(int num) { + if(num > 0) { + temp3 = temp1 + temp2; + temp1 = temp2; + temp2 = temp3; + System.out.print(temp3 + " "); + recursion(num - 1); + } + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/Reverse_W2A1_4.class b/Week 2 Assignment 1/Reverse_W2A1_4.class new file mode 100644 index 0000000..8212dc7 Binary files /dev/null and b/Week 2 Assignment 1/Reverse_W2A1_4.class differ diff --git a/Week 2 Assignment 1/Reverse_W2A1_4.java b/Week 2 Assignment 1/Reverse_W2A1_4.java new file mode 100644 index 0000000..74167d9 --- /dev/null +++ b/Week 2 Assignment 1/Reverse_W2A1_4.java @@ -0,0 +1,19 @@ +import java.util.Arrays; + +public class Reverse_W2A1_4 { + static int[] arr = {3,4,6,7,9}; + static int[] reversedArray = new int[arr.length]; + static int counter = 0; + public static void main(String args[]) { + System.out.println(recursion(arr.length)); + } + + static String recursion(int arrLength) { + if(arrLength > 0) { + reversedArray[counter] = arr[(arr.length - 1) - counter]; + counter++; + recursion(arrLength - 1); + } + return Arrays.toString(reversedArray); + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/SumOFArray_W2A1_2.class b/Week 2 Assignment 1/SumOFArray_W2A1_2.class new file mode 100644 index 0000000..4628b3c Binary files /dev/null and b/Week 2 Assignment 1/SumOFArray_W2A1_2.class differ diff --git a/Week 2 Assignment 1/SumOFArray_W2A1_2.java b/Week 2 Assignment 1/SumOFArray_W2A1_2.java new file mode 100644 index 0000000..15ce919 --- /dev/null +++ b/Week 2 Assignment 1/SumOFArray_W2A1_2.java @@ -0,0 +1,15 @@ +public class SumOFArray_W2A1_2 { + static int sum = 0, i = 0; + static int[] arr = {3,4,2,7,9}; + public static void main(String args[]) { + System.out.println(recursion(arr.length)); + } + static int recursion(int arrLength) { + if(arrLength > 0) { + sum += arr[i]; + i++; + recursion(arrLength - 1); + } + return sum; + } +} \ No newline at end of file diff --git a/Week 2 Assignment 2/PizzaShop_W2A2_1.class b/Week 2 Assignment 2/PizzaShop_W2A2_1.class new file mode 100644 index 0000000..7a65ecb Binary files /dev/null and b/Week 2 Assignment 2/PizzaShop_W2A2_1.class differ diff --git a/Week 2 Assignment 2/PizzaShop_W2A2_1.java b/Week 2 Assignment 2/PizzaShop_W2A2_1.java new file mode 100644 index 0000000..d08f246 --- /dev/null +++ b/Week 2 Assignment 2/PizzaShop_W2A2_1.java @@ -0,0 +1,106 @@ +import java.util.Scanner; + +public class PizzaShop_W2A2_1 { + private String[] crust = {"Thin Crust", "Cheese Burst", "Classic Pan"}; + private int crustOption; + private int[] crustPrice = {100, 200, 300}; + + private String[] toppings = {"Corn", "Chicken", "Paneer", "Pineapple", "Pepperoni"}; + private int toppingsOption; + private int[] toppingsPrice = {100, 200, 300, 400, 500}; + + private String[] sides = {"Coke", "Fries", "Wedges", "Nachos"}; + private int sidesOption; + private int[] sidesPrice = {100, 200, 300, 400}; + + private int[] offerTypes = {20, 50}; + private int offerOption = 0; + + private double price; + private double discount; + //crusttype, toppings, sides, offers, price + + public void getPrice() { + price = crustPrice[crustOption] + toppingsPrice[toppingsOption] + sidesPrice[sidesOption]; + if(offerOption > 0) { + discount = offerTypes[offerOption - 1] / 100.00; + discount = price * discount; + price = price - discount; + } + System.out.println("Total: Rs " + price); + } + + public void setOffer(int option) { + offerOption = option; + } + + public void getOffer() { + for(int i = 0; i < offerTypes.length; i++) { + System.out.print((i + 1) + " " + offerTypes[i] + "% Off\n"); + } + } + + public void setSides(int option) { + sidesOption = option - 1; + } + + public void getSides() { + for(int i = 0; i < sides.length; i++) { + System.out.print((i + 1) + " " + sides[i] + " Rs " + sidesPrice[i] + "\n"); + } + } + + public void setToppings(int option) { + toppingsOption = option - 1; + } + + public void getToppings() { + for(int i = 0; i < toppings.length; i++) { + System.out.print((i + 1) + " " + toppings[i] + " Rs " + toppingsPrice[i] + "\n"); + } + } + + public void setCrust(int option) { + crustOption = option - 1; + } + + public void getCrust() { + for(int i = 0; i < crust.length; i++) { + System.out.print((i + 1) + " " + crust[i] + " Rs " + crustPrice[i] + "\n"); + } + } + + public static void main(String args[]) { + Scanner scans = new Scanner(System.in); + PizzaShop_W2A2_1 pizzaShop = new PizzaShop_W2A2_1(); + int option; + String offerGiven; + System.out.println("Select from below"); + + System.out.println("Crust:"); + pizzaShop.getCrust(); + option = scans.nextInt(); + pizzaShop.setCrust(option); + + System.out.println("Toppings: "); + pizzaShop.getToppings(); + option = scans.nextInt(); + pizzaShop.setToppings(option); + + System.out.println("Sides: "); + pizzaShop.getSides(); + option = scans.nextInt(); + pizzaShop.setSides(option); + + System.out.println("Any discounts to be applied?\ny/n"); + offerGiven = scans.next(); + if(offerGiven.equals("y")) { + System.out.println("Offers: "); + pizzaShop.getOffer(); + option = scans.nextInt(); + pizzaShop.setOffer(option); + } + pizzaShop.getPrice(); + scans.close(); + } +} \ No newline at end of file diff --git a/Week 2 Assignment 2/PizzaShop_W2A2_1_v2.java b/Week 2 Assignment 2/PizzaShop_W2A2_1_v2.java new file mode 100644 index 0000000..fdfb913 --- /dev/null +++ b/Week 2 Assignment 2/PizzaShop_W2A2_1_v2.java @@ -0,0 +1,54 @@ +public class PizzaShop_W2A2_1_v2 { + private String crustType; + private String toppingType; + private String sidesType; + private int offers; + private boolean offerApplied = false; + private double price; + private double discount; + + private int crustTypeAmount; + //crusttype, toppings, sides, offers, price + PizzaShop_W2A2_1_v2(String crust, String topping, String sides) { + crustType = crust; + toppingType = topping; + sidesType = sides; + } + + PizzaShop_W2A2_1_v2(String crust, String topping, String sides, int offer) { + crustType = crust; + toppingType = topping; + sidesType = sides; + offers = offer; + offerApplied = true; + } + + // private int getCrustPrice() { + // switch(crustType) { + // case "thinCrust": + // crustTypeAmount = 100; + // break; + // case "cheeseBurst": + // crustTypeAmount = 200; + // break; + // case "classicPan": + // crustTypeAmount = 300; + // break; + // } + // } + + public double calculateTotalPrice() { + //logic to calculate price here + return price; + } + public static void main(String arg[]) { + //(crustType, toppingType, sidesType) + PizzaShop_W2A2_1_v2 pizzaWithoutOffer = new PizzaShop_W2A2_1_v2("Thin Crust", "Corn", "Fries"); + System.out.println("Total price: " + pizzaWithoutOffer.calculateTotalPrice()); + + //20% off applied + //(crustType, toppingType, sidesType, offerDiscount) + PizzaShop_W2A2_1_v2 pizzaWithOfferApplied = new PizzaShop_W2A2_1_v2("Thin Crust", "Cheese Burst", "Classic Pan", 20); + System.out.println("Total price: " + pizzaWithOfferApplied.calculateTotalPrice()); + } +} \ No newline at end of file diff --git a/Week 2 Assignment 3/SavingsAccount_W2A2_2.java b/Week 2 Assignment 3/SavingsAccount_W2A2_2.java new file mode 100644 index 0000000..516aed6 --- /dev/null +++ b/Week 2 Assignment 3/SavingsAccount_W2A2_2.java @@ -0,0 +1,44 @@ +public class SavingsAccount_W2A2_2 { + private double balance; + private String customerName; + private int customerAge; + private String nomineeName; + private long panNumber; + private boolean withdraw = false; + private boolean deposit = false; + + public SavingsAccount_W2A2_2(String custName, int custAge, long panNo) { + customerName = custName; + customerAge = custAge; + panNumber = panNo; + } + + public void updateNomineeDetails(String name) { + nomineeName = name; + } + + public double getBalance() { + return balance; + } + + public void withdraw(String withdrawUsing) { + if(withdrawUsing.equals("withdrawSlip") || withdrawUsing.equals("atm")) { + withdraw = true; + } + if(withdraw) { + //withdraw money code here + } + } + + public void deposit(String depositUsing) { + if(depositUsing.equals("challan") || depositUsing.equals("atm")) { + deposit = true; + } + if(deposit) { + //deposit money code here + } + } + public static void main(String args[]) { + + } +} \ No newline at end of file diff --git a/Week 3 Assignment 1/BankAccount.class b/Week 3 Assignment 1/BankAccount.class new file mode 100644 index 0000000..993ea6b Binary files /dev/null and b/Week 3 Assignment 1/BankAccount.class differ diff --git a/Week 3 Assignment 1/BankAccountClient_W3A1_2.java b/Week 3 Assignment 1/BankAccountClient_W3A1_2.java new file mode 100644 index 0000000..64c78ad --- /dev/null +++ b/Week 3 Assignment 1/BankAccountClient_W3A1_2.java @@ -0,0 +1,209 @@ +// a. A BankAccount will contain the account holders name, account number, +// the account creation date (string as of now), branch name and balance and Address + +// b. A BankAccount can be either SavingsAccount or CurrentAccount or Salaried Account (a special type of savings account) +// c. Current account holders do not have withdrawal limit on their account balance whereas Savings account holders +// can only withdraw 25000 per day. +// d. CurrentAccount holders should have a minimum account balance of Rs 25000. Regular savings account holders should +// maintain 10000 rupees whereas Salaried account holders can maintain 0 balance. +// e. There should be a provision to update Nominee details but they cannot update account number and name. +// f. The address should contain FlatNo, Street, City, State and pin code. +import java.util.Arrays; + +abstract class BankAccount { + private String acHolderName; + private int acNumber; + private String acCreationDate; + public String branchName; + private static double balance; + public String[] address; + + public BankAccount(String acHolderName, int acNumber, String acCreationDate, String branchName, double bal, String[] address) { + this.acHolderName = acHolderName; + this.acNumber = acNumber; + this.acCreationDate = acCreationDate; + this.branchName = branchName; + balance = bal; + this.address = address; + } + + public double getBalance() { + return balance; + } + + public void setBalance(double bal) { + balance = bal; + } + + abstract void updateNomineeDetails(String branchName, String[] address); + + public String getAcHolderName() { + return acHolderName; + } + public int getAcNumber() { + return acNumber; + } + public String getAcCreationDate() { + return acCreationDate; + } + public String getBranchName() { + return branchName; + } + public String getAddress() { + return Arrays.toString(address); + } + abstract void getAccDetails(); +} + +interface accountRules { + void withdrawFunc(double amount); + boolean minAcBalanceMaintained(); +} + +class SavingsAccount extends BankAccount implements accountRules { + + public static double withdrawLimit = 25_000; // per day + private static double minAcBalAmount = 10_000; + + public SavingsAccount(String acHolderName, int acNumber, String acCreationDate, String branchName, double balance, + String[] address) { + super(acHolderName, acNumber, acCreationDate, branchName, balance, address); + } + + @Override + public void withdrawFunc(double amount) { + if(amount < withdrawLimit && getBalance() > minAcBalAmount) { + setBalance(getBalance() - amount); + } + } + + @Override + public boolean minAcBalanceMaintained() { + if(getBalance() < minAcBalAmount) { + return false; + } + else return true; + } + + @Override + void updateNomineeDetails(String branchName, String[] address) { + this.branchName = branchName; + this.address = address; + } + + public void getAccDetails() { + System.out.println( + "\nAccount holder name: " + getAcHolderName() + + "\nAccount number: " + getAcNumber() + + "\nAccount creation date: " + getAcCreationDate() + + "\nBranch name: " + getBranchName() + + "\nAddress: " + getAddress() + ); + } +} + +class CurrentAccount extends BankAccount implements accountRules { + + private static double minAcBalAmount = 25_000; + + public CurrentAccount(String acHolderName, int acNumber, String acCreationDate, String branchName, double bal, + String[] address) { + super(acHolderName, acNumber, acCreationDate, branchName, bal, address); + } + + @Override + public void withdrawFunc(double amount) { + if(getBalance() > minAcBalAmount) { + setBalance(getBalance() - amount); + } + } + + @Override + public boolean minAcBalanceMaintained() { + if(getBalance() < minAcBalAmount) { + return false; + } + else return true; + } + + @Override + void updateNomineeDetails(String branchName, String[] address) { + this.branchName = branchName; + this.address = address; + } + + @Override + public void getAccDetails() { + System.out.println( + "\nAccount holder name: " + getAcHolderName() + + "\nAccount number: " + getAcNumber() + + "\nAccount creation date: " + getAcCreationDate() + + "\nBranch name: " + getBranchName() + + "\nAddress: " + getAddress() + ); + } +} + +class SalariedAccount extends SavingsAccount implements accountRules { + + private static double minAcBalAmount = 0; + + public SalariedAccount(String acHolderName, int acNumber, String acCreationDate, String branchName, double balance, + String[] address) { + super(acHolderName, acNumber, acCreationDate, branchName, balance, address); + // TODO Auto-generated constructor stub + } + + @Override + public void withdrawFunc(double amount) { + if(getBalance() > minAcBalAmount) { + setBalance(getBalance() - amount); + } + } + + @Override + public boolean minAcBalanceMaintained() { + if(getBalance() < minAcBalAmount) { + return false; + } + else return true; + } + + @Override + void updateNomineeDetails(String branchName, String[] address) { + this.branchName = branchName; + this.address = address; + } + + @Override + public void getAccDetails() { + System.out.println( + "\nAccount holder name: " + getAcHolderName() + + "\nAccount number: " + getAcNumber() + + "\nAccount creation date: " + getAcCreationDate() + + "\nBranch name: " + getBranchName() + + "\nAddress: " + getAddress() + ); + } +} + +public class BankAccountClient_W3A1_2 { + public static void main(String args[]) { + String[] address1 = {"Flat No 56", "Street 71", "City31", "State18", "577902"}; + //adding a new savings account + SavingsAccount acc1 = new SavingsAccount("anon1", 12, "today", "bdvt", 13000, address1); + acc1.withdrawFunc(2000); //withdrawing money as per the withdrawal and minimum balance rules + //System.out.println(acc1.getBalance()); + //System.out.println(acc1.minAcBalanceMaintained()); + acc1.getAccDetails(); + SavingsAccount acc2 = new SavingsAccount("anon2", 12, "today", "bdvt", 13000, address1); + //acc2.getAccDetails(); + String[] address2 = {"Flat No 3", "Street 7", "City1", "State10", "577291"}; + acc1.updateNomineeDetails("smg", address2); + acc1.getAccDetails(); + + String[] address3 = {"dummydata"}; + CurrentAccount currentAccount1 = new CurrentAccount("anon3", 56171, "18jun19", "bnglr", 70000, address3); + currentAccount1.getAccDetails(); + } +} \ No newline at end of file diff --git a/Week 3 Assignment 1/ContractEmployee.class b/Week 3 Assignment 1/ContractEmployee.class new file mode 100644 index 0000000..a7ee906 Binary files /dev/null and b/Week 3 Assignment 1/ContractEmployee.class differ diff --git a/Week 3 Assignment 1/CurrentAccount.class b/Week 3 Assignment 1/CurrentAccount.class new file mode 100644 index 0000000..9a85a6b Binary files /dev/null and b/Week 3 Assignment 1/CurrentAccount.class differ diff --git a/Week 3 Assignment 1/Employee.class b/Week 3 Assignment 1/Employee.class new file mode 100644 index 0000000..42cfe08 Binary files /dev/null and b/Week 3 Assignment 1/Employee.class differ diff --git a/Week 3 Assignment 1/EmployeeClient.class b/Week 3 Assignment 1/EmployeeClient.class new file mode 100644 index 0000000..378b0cf Binary files /dev/null and b/Week 3 Assignment 1/EmployeeClient.class differ diff --git a/Week 3 Assignment 1/EmployeeClient_W3A1_1.java b/Week 3 Assignment 1/EmployeeClient_W3A1_1.java new file mode 100644 index 0000000..ec3f2b4 --- /dev/null +++ b/Week 3 Assignment 1/EmployeeClient_W3A1_1.java @@ -0,0 +1,115 @@ +import java.util.Arrays; + +abstract class Employee { + public int id; + public String name; + public int age; + public String projectName; + public boolean applyLeave = false; + public String[] skills; + + Employee(int id, String name, int age, String projectName, String[] skills) { + this.id = id; + this.name = name; + this.age = age; + this.projectName = projectName; + this.skills = skills; + } + public abstract boolean canApplyLeave(int duration); + public abstract void getEmployeeDetails(); +} + +class RegularEmployee extends Employee { + private static int leaveBalance = 20; //days + private static double fixedSalary; + private static double bonus; + + RegularEmployee(int id, String name, int age, String projectName, String[] skills, double fixedSalary, double bonus) { + super(id, name, age, projectName, skills); + this.fixedSalary = fixedSalary; + this.bonus = bonus; + } + + @Override + public boolean canApplyLeave(int duration) { + if(leaveBalance > duration) { + applyLeave = true; + leaveBalance -= duration; + } + return applyLeave; + } + + public int getLeaveBalance() { + return leaveBalance; + } + + public void getEmployeeDetails() { + System.out.println( + "Employee ID: " + id + + "\nEmployee Name: " + name + + "\nEmployee age: " + age + + "\nProject name: " + projectName + + "\nSkills: " + Arrays.toString(skills) + + "\nBonus: " + bonus + + "\nLeave Balance: " + leaveBalance + ); + } +} + +class ContractEmployee extends Employee { + private static int contractDuration = 60; //days + private static double payPerHour; + + ContractEmployee(int id, String name, int age, String projectName, String[] skills, double payPerHour) { + super(id, name, age, projectName, skills); + this.payPerHour = payPerHour; + } + + @Override + public boolean canApplyLeave(int duration) { + if(contractDuration > duration) { + applyLeave = true; + contractDuration += duration; + } + return applyLeave; + } + + public int getRemainingContractDuration() { + return contractDuration; + } + + @Override + public void getEmployeeDetails() { + System.out.println( + "Employee ID: " + id + + "\nEmployee Name: " + name + + "\nEmployee age: " + age + + "\nProject name: " + projectName + + "\nSkills: " + Arrays.toString(skills) + + "\nPay per hour: " + payPerHour + + "\nRemaining contract period days: " + contractDuration + " days" + ); + } +} + +public class EmployeeClient_W3A1_1 { + public static void main(String args[]) { + String emp1Skills[] = {"Java", "Spring", "JS", "Shell scripting"}; + RegularEmployee regEmp1 = new RegularEmployee(12, "anon1", 34, "prism", emp1Skills, 340000, 20000); + System.out.println(regEmp1.canApplyLeave(12)); + System.out.println(regEmp1.getLeaveBalance()); + regEmp1.getEmployeeDetails(); + if(regEmp1.canApplyLeave(5)) { + System.out.println("New leave balance: " + regEmp1.getLeaveBalance()); + } + + System.out.println(); + + String contractEmp1Skills[] = {"Pen testing", "Network Security", "Data analysis"}; + ContractEmployee contractEmp1 = new ContractEmployee(29, "anon2", 29, "ufo", contractEmp1Skills, 10); + if(contractEmp1.canApplyLeave(13)) { + System.out.println("Your new contract period: " + contractEmp1.getRemainingContractDuration() + " days"); + } + contractEmp1.getEmployeeDetails(); + } +} \ No newline at end of file diff --git a/Week 3 Assignment 1/MainClass.class b/Week 3 Assignment 1/MainClass.class new file mode 100644 index 0000000..7754277 Binary files /dev/null and b/Week 3 Assignment 1/MainClass.class differ diff --git a/Week 3 Assignment 1/RegularEmployee.class b/Week 3 Assignment 1/RegularEmployee.class new file mode 100644 index 0000000..4165ab9 Binary files /dev/null and b/Week 3 Assignment 1/RegularEmployee.class differ diff --git a/Week 3 Assignment 1/SalariedAccount.class b/Week 3 Assignment 1/SalariedAccount.class new file mode 100644 index 0000000..8033ef8 Binary files /dev/null and b/Week 3 Assignment 1/SalariedAccount.class differ diff --git a/Week 3 Assignment 1/SavingsAccount.class b/Week 3 Assignment 1/SavingsAccount.class new file mode 100644 index 0000000..3274ad4 Binary files /dev/null and b/Week 3 Assignment 1/SavingsAccount.class differ diff --git a/Week 3 Assignment 1/accountRules.class b/Week 3 Assignment 1/accountRules.class new file mode 100644 index 0000000..b4c57b2 Binary files /dev/null and b/Week 3 Assignment 1/accountRules.class differ