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
27 changes: 27 additions & 0 deletions Assignment-2/Problem-1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Calculate {
int firstOperand;
double secondOperand;
String convertedUppercaseText;

public void printCalculatedSum(int firstOperand, int secondOperand) {
int additionResult = firstOperand + secondOperand;
System.out.println("Result: " + additionResult);
}

public void printUpperCaseString(String inputText) {
convertedUppercaseText = inputText.toUpperCase();
System.out.println("Updated String: " + convertedUppercaseText);
}
}

public class Computation {
public static void main(String[] args) {
Calculate calculate = new Calculator();
calculate.firstOperand = 10;
calculate.secondOperand = 20.5;
calculate.convertedUppercaseText = "hello";

calculate.printCalculatedSum(calculate.firstOperand, 5);
calculate.printUpperCaseString("world");
}
}
97 changes: 97 additions & 0 deletions Assignment-2/Problem-2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Product {
private String name;
private double price;
private int quantity;

public setProductDetails(String name, double price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}

public String getName() {
return name;
}

public double getPrice() {
return price;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int newQuantity) {
this.quantity = newQuantity;
}
}

class InventoryManager {
private List<Product> inventory;

public InventoryManager() {
this.inventory = new ArrayList<>();
}

public void addProduct(Product product) {
inventory.add(product);
}

public List<Product> getInventory() {
return inventory;
}
}

public class Main {
public static void main(String[] args) {
InventoryManager inventoryManager = new InventoryManager();
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("\nInventory Management System");
System.out.println("1. Add Product");
System.out.println("2. Display Inventory");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");

int userChoice = scanner.nextInt();

switch (userChoice) {
case 1:
System.out.print("Enter product name: ");
String productName = scanner.next();
System.out.print("Enter product price: ");
double productPrice = scanner.nextDouble();
System.out.print("Enter product quantity: ");
int productQuantity = scanner.nextInt();

Product newProduct = new Product(productName, productPrice, productQuantity);
inventoryManager.addProduct(newProduct);

System.out.println("Product added successfully!");
break;

case 2:
System.out.println("\nCurrent Inventory:");
List<Product> products = inventoryManager.getInventory();
for (Product product : products) {
System.out.println("Name: " + product.getName() +
", Price: $" + product.getPrice() +
", Quantity: " + product.getQuantity());
}
break;

case 3:
System.out.println("Exiting program. Goodbye!");
System.exit(0);

default:
System.out.println("Invalid choice. Please enter a valid option.");
}
}
}
}
3 changes: 3 additions & 0 deletions Assignment-3/OCP/Device.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Device {
void displayDetails();
}
3 changes: 3 additions & 0 deletions Assignment-3/OCP/DeviceFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface DeviceFactory {
Device createDevice();
}
6 changes: 6 additions & 0 deletions Assignment-3/OCP/Laptop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Laptop implements Device {
@Override
public void displayDetails() {
System.out.println("Laptop: Model Y, RAM: 16GB, Storage: 512GB");
}
}
6 changes: 6 additions & 0 deletions Assignment-3/OCP/LaptopFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class LaptopFactory implements DeviceFactory {
@Override
public Device createDevice() {
return new Laptop();
}
}
12 changes: 12 additions & 0 deletions Assignment-3/OCP/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Main {
public static void main(String[] args) {
DeviceFactory smartphoneFactory = new SmartphoneFactory();
DeviceFactory laptopFactory = new LaptopFactory();

Device smartphone = smartphoneFactory.createDevice();
Device laptop = laptopFactory.createDevice();

smartphone.displayDetails();
laptop.displayDetails();
}
}
6 changes: 6 additions & 0 deletions Assignment-3/OCP/Smartphone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Smartphone implements Device {
@Override
public void displayDetails() {
System.out.println("Smartphone: Model X, RAM: 8GB, Storage: 128GB");
}
}
6 changes: 6 additions & 0 deletions Assignment-3/OCP/SmartphoneFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SmartphoneFactory implements DeviceFactory {
@Override
public Device createDevice() {
return new Smartphone();
}
}
5 changes: 5 additions & 0 deletions Assignment-3/SRP/problem-1/AreaCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class AreaCalculator {
public double calculateArea(Rectangle rectangle) {
return rectangle.getLength() * rectangle.getWidth();
}
}
12 changes: 12 additions & 0 deletions Assignment-3/SRP/problem-1/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Main {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(5.0, 3.0);
AreaCalculator calculator = new AreaCalculator();
double area = calculator.calculateArea(rectangle);
printArea(area);
}

public static void printArea(double area) {
System.out.println("Area: " + area);
}
}
17 changes: 17 additions & 0 deletions Assignment-3/SRP/problem-1/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Rectangle {
private double length;
private double width;

public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}

public double getLength() {
return length;
}

public double getWidth() {
return width;
}
}
12 changes: 12 additions & 0 deletions Assignment-3/SRP/problem-2/AreaFileCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.io.FileWriter;
import java.io.IOException;

public class AreaFileWriter {
public void writeAreaToFile(double area) {
try (FileWriter writer = new FileWriter("area.txt")) {
writer.write("Area: " + area);
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}
}
11 changes: 11 additions & 0 deletions Assignment-3/SRP/problem-2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Main {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(5.0, 3.0);
double area = rectangle.calculateArea();

AreaFileWriter fileWriter = new AreaFileWriter();
fileWriter.writeAreaToFile(area);

System.out.println("Calculated Area: " + area);
}
}
13 changes: 13 additions & 0 deletions Assignment-3/SRP/problem-2/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Rectangle {
private double length;
private double width;

public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}

public double calculateArea() {
return length * width;
}
}