Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Week 2 Assignment 1/Factorial_W2A1_3.class
Binary file not shown.
15 changes: 15 additions & 0 deletions Week 2 Assignment 1/Factorial_W2A1_3.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Binary file added Week 2 Assignment 1/Fibonacci_W2A1_1.class
Binary file not shown.
18 changes: 18 additions & 0 deletions Week 2 Assignment 1/Fibonacci_W2A1_1.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Binary file added Week 2 Assignment 1/Reverse_W2A1_4.class
Binary file not shown.
19 changes: 19 additions & 0 deletions Week 2 Assignment 1/Reverse_W2A1_4.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Binary file added Week 2 Assignment 1/SumOFArray_W2A1_2.class
Binary file not shown.
15 changes: 15 additions & 0 deletions Week 2 Assignment 1/SumOFArray_W2A1_2.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Binary file added Week 2 Assignment 2/PizzaShop_W2A2_1.class
Binary file not shown.
106 changes: 106 additions & 0 deletions Week 2 Assignment 2/PizzaShop_W2A2_1.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
54 changes: 54 additions & 0 deletions Week 2 Assignment 2/PizzaShop_W2A2_1_v2.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
44 changes: 44 additions & 0 deletions Week 2 Assignment 3/SavingsAccount_W2A2_2.java
Original file line number Diff line number Diff line change
@@ -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[]) {

}
}
Binary file added Week 3 Assignment 1/BankAccount.class
Binary file not shown.
Loading